-
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
Use compatible Python executable installed by Pyenv #4164
Conversation
Test output here: $ python2 -V
Python 2.7.17
$ python3 -V
Python 3.6.9
$ pyenv versions
* system (set by /home/ggicci/.pyenv/version)
3.7.10
3.8.10
3.9.4
$ cd ~/workspace/src/ggicci.me/poetry-pyenv-test
$ grep "python =" pyproject.toml
python = "~3.7"
$ poetry@local -vvv install
Loading configuration file /home/ggicci/.config/pypoetry/config.toml
The currently activated Python version 3.6.9 is not supported by the project (~3.7).
Trying to find and use a compatible version.
Pyenv loaded: /home/ggicci/.pyenv/bin/pyenv
Trying python3
Trying python3.7
Trying /home/ggicci/.pyenv/versions/3.7.10/bin/python3.7
Using /home/ggicci/.pyenv/versions/3.7.10/bin/python3.7 (3.7.10)
Creating virtualenv poetry-pyenv-test-gx4qtdVT-py3.7 in /home/ggicci/.cache/pypoetry/virtualenvs
Using virtualenv: /home/ggicci/.cache/pypoetry/virtualenvs/poetry-pyenv-test-gx4qtdVT-py3.7
Installing dependencies from lock file
Finding the necessary packages for the current system |
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
poetry/utils/env.py
Outdated
): | ||
if "." not in python_to_try: | ||
if parse_constraint(f"^{python_to_try}.0").allows_any(supported_python): | ||
candidates.append("python" + python_to_try) |
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.
candidates.append("python" + python_to_try) | |
candidates.append(f"python{python_to_try}") |
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.
Suggestion to improve loop performance: assign the append function to a variable before starting the for loop to avoid dots inside the loop:
Example:
append = candidates.append
So inside the for loop you just use the append(...) directly.
For more information, I found this list with some examples (see item 3):
https://newrelic.com/blog/best-practices/python-performance-tips
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 for this good suggestion. I never noticed this tip of performance improvement before.
poetry/utils/pyenv.py
Outdated
return self._command is not None | ||
|
||
def load(self) -> None: | ||
if self._command is not None: |
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.
Why don't you do it like this?
Example:
def load(self) -> None:
if self._command is None:
self._command = self._locate_command()
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 prefer putting "fast fail" branches of statements in the head of a method and leaving "main logic" at the last. Maybe the pros of this methodolgy is not obivious here.
@ggicci why did you close this PR? |
This pr brought too many changes and should break down into small pieces. @NickKaramoff |
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. |
Pull Request Check List
Resolves: #4079 #4101
A new config item
virtualenvs.use-pyenv
with default valuetrue
has been instroduced.Features
Integrate
pyenv
withpoetry
's discovery logicIf no compatible versions were found in the system,
poetry
will keep looking for compatible Python interpreters installed bypyenv
.Fixes
virtualenv
.