Skip to content

Commit 858473d

Browse files
authored
Merge pull request #20 from openlawlibrary/sbojanic/add-constraints-path-param
feat: add support for --constraints-path flag
2 parents 13717a5 + 1695e6f commit 858473d

21 files changed

+100
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ and this project adheres to a _modified_ form of _[Semantic Versioning][semver]_
1212

1313
### Changed
1414

15+
- Add support for --constraints-path flag ([#20])
16+
17+
[#20]: https://github.com/openlawlibrary/upgrade-python-package/pull/20
18+
1519
### Fixed
1620

1721
### Removed

upgrade/scripts/upgrade_python_package.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ def upgrade_and_run(
3434
cloudsmith_url=None,
3535
update_all=False,
3636
slack_webhook_url=None,
37+
constraints_path = None,
3738
*args,
3839
):
3940
"""
@@ -59,6 +60,7 @@ def upgrade_and_run(
5960
cloudsmith_url,
6061
update_all,
6162
slack_webhook_url,
63+
constraints_path,
6264
)
6365
else:
6466
logging.info('Trying to upgrade "%s" package.', package_name)
@@ -67,6 +69,7 @@ def upgrade_and_run(
6769
cloudsmith_url,
6870
update_all,
6971
slack_webhook_url,
72+
constraints_path,
7073
*args,
7174
)
7275
if not skip_post_install and (was_updated or force):
@@ -201,6 +204,7 @@ def install_wheel(
201204
version_cmd=None,
202205
update_all=False,
203206
slack_webhook_url=None,
207+
constraints_path=None,
204208
*args,
205209
):
206210
"""
@@ -265,7 +269,7 @@ def install_wheel(
265269
resp += pip("check")
266270
except:
267271
# try to install with constraints
268-
constraints_file_path = get_constraints_file_path(package_name)
272+
constraints_file_path = constraints_path or get_constraints_file_path(package_name)
269273
try:
270274
resp += install_with_constraints(
271275
to_install,
@@ -310,6 +314,7 @@ def upgrade_from_local_wheel(
310314
wheels_path=None,
311315
update_all=False,
312316
version=None,
317+
constraints_path=None,
313318
):
314319
resp = ""
315320
package_name, _ = split_package_name_and_extra(package_install_cmd)
@@ -321,6 +326,7 @@ def upgrade_from_local_wheel(
321326
wheels_path=wheels_path,
322327
update_all=update_all,
323328
version_cmd=version,
329+
constraints_path=constraints_path,
324330
)
325331
except Exception as e:
326332
response_err = str(e)
@@ -337,6 +343,7 @@ def attempt_to_install_version(
337343
cloudsmith_url=None,
338344
update_all=False,
339345
slack_webhook_url=None,
346+
constraints_path=None,
340347
):
341348
"""
342349
attempt to install a specific version of the given package
@@ -355,6 +362,7 @@ def attempt_to_install_version(
355362
version,
356363
update_all,
357364
slack_webhook_url,
365+
constraints_path,
358366
*args,
359367
)
360368
except Exception as e:
@@ -369,6 +377,7 @@ def attempt_upgrade(
369377
cloudsmith_url=None,
370378
update_all=False,
371379
slack_webhook_url=None,
380+
constraints_path=None,
372381
*args,
373382
):
374383
"""
@@ -390,6 +399,7 @@ def attempt_upgrade(
390399
None,
391400
update_all,
392401
slack_webhook_url,
402+
constraints_path,
393403
*args,
394404
)
395405
was_upgraded = "Requirement already up-to-date" not in resp
@@ -563,6 +573,11 @@ def try_running_module(wheel, *args, **kwargs):
563573
default=None,
564574
help="Slack webhook url string for sending slack notifications on failed upgrade",
565575
)
576+
parser.add_argument(
577+
"--constraints-path",
578+
action="store",
579+
help="Path to constraints.txt file"
580+
)
566581

567582

568583
def upgrade_python_package(
@@ -579,6 +594,7 @@ def upgrade_python_package(
579594
format_output=False,
580595
update_all=False,
581596
slack_webhook_url=None,
597+
constraints_path=None,
582598
*vars,
583599
):
584600
success = False
@@ -605,6 +621,7 @@ def upgrade_python_package(
605621
cloudsmith_url=cloudsmith_url,
606622
update_all=update_all,
607623
version=version,
624+
constraints_path=constraints_path,
608625
*vars,
609626
)
610627
elif should_run_initial_post_install:
@@ -618,6 +635,7 @@ def upgrade_python_package(
618635
cloudsmith_url,
619636
update_all,
620637
slack_webhook_url,
638+
constraints_path,
621639
*vars,
622640
)
623641
except Exception as e:
@@ -648,6 +666,7 @@ def main():
648666
format_output = parsed_args.format_output
649667
update_all = parsed_args.update_all
650668
slack_webhook_url = parsed_args.slack_webhook_url
669+
constraints_path = parsed_args.constraints_path
651670
upgrade_python_package(
652671
package,
653672
wheels_path,
@@ -662,9 +681,11 @@ def main():
662681
format_output,
663682
update_all,
664683
slack_webhook_url,
684+
constraints_path,
665685
*parsed_args.vars,
666686
)
667687

668688

669689
if __name__ == "__main__":
670-
main()
690+
691+
main()

upgrade/scripts/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def run(*command, **kwargs):
8787
options.update(kwargs)
8888
completed = subprocess.run(command, **options)
8989
except subprocess.CalledProcessError as err:
90-
logging.warning('Error occurred while running command "%s"', *command)
90+
logging.warning('Error occurred while running command "%s"', " ".join(command))
9191
if err.stdout:
9292
print(err.stdout)
9393
logging.warning(err.stdout)

upgrade/tests/conftest.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
original_executable = sys.executable
1212

1313
VENV_PATH = Path(__file__).parent / "venv"
14-
REPOSITORY_WHEELS_PATH = Path(__file__).parent / "repository"
14+
DATA_PATH = Path(__file__).parent / "data"
15+
WHEELS_DIR = DATA_PATH / "wheels_dir"
1516

1617

1718
@pytest.fixture
1819
def wheels_dir():
19-
return REPOSITORY_WHEELS_PATH
20+
return WHEELS_DIR
2021

2122

2223
def pytest_configure(config):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
oll-test-top-level==2.0.2
2+
oll-dependency1==2.0.0
3+
oll-dependency2==2.0.0
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)