-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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 (experimental) option to use current active python to create venv ("pyenv way") #4852
Add (experimental) option to use current active python to create venv ("pyenv way") #4852
Conversation
9d9ac45
to
848af21
Compare
5ef87d9
to
434fecb
Compare
executable = decode( | ||
subprocess.check_output( | ||
list_to_shell_command( | ||
["python", "-c", '"import sys; print(sys.executable)"'] |
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.
This is not necessarily universal.
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.
You mean python
? In theory yes.
But if you have e.g. python2
and python3
in your shell but no python
it is impossible to decide what python the user expects.
The main use case for the implementation here is for users who switch there python
to different versions (e.g. with pyenv). I'm not aware of other tools, but I guess they all will provide a python
. As a fallback if no python
is found and the option is activated, the default behavior will be used.
The only generic solution for all edge cases I can imagine right now, is to let the user set a "default python executable" that should be used. But in this case I have some security concerns. Running a user provided command listed in a config, doesn't sound good.
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.
This is not just about python2
vs python3
. There also are other issues like for .exe
extensions on windows etc depending on where poetry
is running. Additionally, quite a lot of tools rely on environment magic to wrangle which python
version to use etc., this can also be impacted by how the subprocess shell is spawned (eg: is it a login shell?, how does the tool configure the "current" python?, are profile scripts required? is the PATH
discoery set correctly? etc.). There are too many variables here. Not sure if this is a show stopper, but we should really consider if this makes things more obscure.
An additional point might be that we should fall back gracefully to compatible version detection than crashing as the option is "prefer" and not "use".
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.
An additional point might be that we should fall back gracefully to compatible version detection than crashing as the option is "prefer" and not "use".
This is already the case :)
6903560
to
5c65efd
Compare
QA @ 5c65efd
However, if I have a Normal shell
Project directory (w/
|
io.write_line( | |
f"<warning>The currently activated Python version {python_patch} " | |
f"is not supported by the project ({self._poetry.package.python_versions}).\n" | |
"Trying to find and use a compatible version.</warning> " | |
) |
1.1 backport?
Is this something that can be backported to 1.1 potentially?
The reason why is while 1.2 entails a significant release but this, if on 1.1, makes the experience much more convenient.
Thanks a lot for your feedback @tony. I'm not familiar with
For now it's unclear if we will will merge this at all or if we try to make a plugin out of it. If we will merge it, I don't think we will backport it to 1.1. There you can have this functionality if you use the |
You're welcome and let me know if another QA would be helpful (assuming / if there's any revisions from here)
Also following this and interested to see where it goes. |
@tony: I've found some time to test
|
@finswimmer I made a mistake, I didn't test your PR with And upon further examination, I'm detecting my asdf's project-based python correctly on 1.1.12 installed on A shot in the dark: Do we have any high-level, integration-level tests for Enlisting more assistance since there are @shawon-crosen @crflynn @Kurt-von-Laven As you are part of a related issue at asdf-community/asdf-poetry#10 this relates to you, would you like to QA finswimmer's 1.2 branch and see if it fails to detect your python version? Without and with |
Good news: Assume
With this PR, the minor version works correctly |
… to EnvManager.create_venv()
5c65efd
to
bfe848c
Compare
Sounds good @tony 👍
We don't have something like this yet. We would like to have some kind of end-to-end-test for several usecases, in different environments and with different settings. But I'm afraid this is nothing what can be done easily, because the possible combinations are endless ... For now I'm happy to see, that the implementation seems to work for I would like to hear something from people, that have use cases with |
I borrowed @finswimmer's shell commands and have a simple Docker test here using |
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.
This change is relatively minor, marked experimental, and arguably is less surprising behavior for the end user. I think we're good to go ahead and merge this, and tweak it if needed in the future.
Personally, I think that we should check the current python3
instead of python
given that Python 2 is well and truly dead now, but we can correct that later if it's an issue.
@neersighted, I don't have a lot of expertise on the topic, but that makes sense to me. This may already be what you are suggesting, but to clarify I would think it wise to also continue to check |
We only support Python 3 (Python 2 has been out of support for years now) and a python3 should always be present (both a PEP and distro packaging guidelines call for this) when Python is installed. Therefore I see no need to check both as the python binary is either Python 2 (unsupported), Python 3 (good), or does not exist. Some distros provide python as a symlink to python3, and others require a package like Debian's python-is-python3 or FreeBSD's lang/python. That being said, asdf and pyenv will both work with this change, and I can see this version as being more in line with the principle of least surprise. We can always change it if needed. |
Thank you for the explanation! That was very educational. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
The "pyenv-way" for switching/creating venvs as described in the docs doesn't work anymore when using the
install-poetry.py
script.This Draft-PR is a proof-of-concept to see if it's possible to detect the current running python in the shell, set by pyenv and bring back that functionality and make it also available when installing poetry viapipx
.It will probably never be included in poetry like this, as we don't want to rely on third-party tools if not necessary. But this could be a starting point to find out how to integrate it via a plugin.(Maybe it can be implemented, because I've found a generic way. So it's up to @sdispater if such a solution will be included.)This PR adds in opt-in option
virtualenvs.prefer-active-python
. If set totrue
poetry will try to use the current runningpython
of the shell for creating the venv.Would be happy if some people could test their usecase with this MR.
Install with
pipx
:Install with
install-poetry.py
script:Closes: #4199