-
-
Notifications
You must be signed in to change notification settings - Fork 611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --python-executable
option for pip-sync
#1333
Add --python-executable
option for pip-sync
#1333
Conversation
This comment has been minimized.
This comment has been minimized.
@atugushev could you please comment if this PR makes sense and maintainers agree to add such an option |
…ecutable # Conflicts: # tests/test_utils.py
for more information, see https://pre-commit.ci
…python-executable
for more information, see https://pre-commit.ci
…M/pip-tools into feature/python-executable
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, it looks good. One thing to consider: could we improve --python-executable
to pass binary name somehow? For example: pip-sync --python-executable=python3
.
Great idea, I can try using Looks like it works well for aliases and full paths, so we can always use it for resolving: In [1]: import shutil
In [2]: import sys
In [3]: shutil.which('python')
Out[3]: 'D:\\Envs\\test\\python.EXE'
In [4]: shutil.which(sys.executable)
Out[4]: 'd:\\envs\\test\\python.exe' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've caught a trace when a given python executable is not found:
$ pip-sync -a --python-executable=python3.9
Traceback (most recent call last):
File "/Users/albert/Projects/pip-tools/.venv/bin/pip-sync", line 11, in <module>
load_entry_point('pip-tools', 'console_scripts', 'pip-sync')()
File "/Users/albert/Projects/pip-tools/.venv/lib/python3.8/site-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/Users/albert/Projects/pip-tools/.venv/lib/python3.8/site-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/Users/albert/Projects/pip-tools/.venv/lib/python3.8/site-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/albert/Projects/pip-tools/.venv/lib/python3.8/site-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/Users/albert/Projects/pip-tools/piptools/scripts/sync.py", line 126, in cli
_validate_python_executable(python_executable)
File "/Users/albert/Projects/pip-tools/piptools/scripts/sync.py", line 200, in _validate_python_executable
log.error(msg, python_executable, pip_version, required_pip_specification)
File "/Users/albert/Projects/pip-tools/piptools/logging.py", line 40, in error
self.log(message, *args, **kwargs)
File "/Users/albert/Projects/pip-tools/piptools/logging.py", line 24, in log
click.secho(prefix + message, *args, **kwargs)
TypeError: secho() got multiple values for argument 'err'
…M/pip-tools into feature/python-executable
My bad, did not re-run tests locally (on a side note I reverted logging message passing, was confused by the recommendation to delegate message formatting to the logging system (#1333 (comment)). Seems like pip-tools uses a custom logging wrapper that has incompatible method contracts. |
Thanks @MaratFM! Let's address that in a following up PR. |
tests/test_cli_sync.py
Outdated
|
||
@mock.patch("piptools.scripts.sync.get_pip_version_for_python_executable") | ||
@mock.patch("piptools.scripts.sync.get_sys_path_for_python_executable") | ||
@mock.patch("piptools.scripts.sync.get_installed_distributions") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are too much of monkeypatches. Ideally, there should be only @mock.patch("piptools.sync.run")
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refactored
Co-authored-by: Albert Tugushev <[email protected]>
@atugushev seems like with "# pragma: no branch" it stills shows partial coverage, so I reverted back to "# pragma: no cover" |
Co-authored-by: Albert Tugushev <[email protected]>
@atugushev sorry for changing tests back and forth, I could not run tests for all these platforms locally and have to wait when someone will trigger the GitHub actions pipeline |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @MaratFM for your patience. Awesome work! 👍🏻
--python-executable
option for pip-sync
Problem: build pipelines and infrastructure at big companies often targets multiple independent python projects. Currently, in order to use pip-sync, pip-tools have to be installed in every environment. When pip-compile does not have such restriction.
Solution: add the ability to pass custom python executable. When the option provided, list of installed packages will be collected from the target environment and all install/uninstall commands will be executed inside that environment.
This PR implements a proof concept for collecting early feedback on the idea and implementation. If concept and task will be accepted, sufficient test coverage will be added and PR re-submitted.
Thank you!
Added "--python-executable" option for pip-sync command. It allows targeting environments other than current:
Contributor checklist