GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Check current python executable version by yokomotod · Pull Request #4520 · python-poetry/poetry

Conversation

@yokomotod

@yokomotod yokomotod commented Sep 18, 2021

Copy link
Copy Markdown
Contributor

Hi.

As #3426 said, current poetry only checks the python constraint in pyproject.toml when creating a virtualenv.

This PR added a python version check for created virtualenv as well, at each command execution.

Demo

(Supporse python 3.8 and 3.9 are installed)

First, poetry install with pyproject.tom which requires python3.8:

[tool.poetry]
name = "ptry"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]

[tool.poetry.dependencies]
python = "~3.8"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

It creates virtualenv with python 3.8.x executable.

$ poetry run python -V
Python 3.8.10

Then change pyproject.tom to python = "^3.9".

With this PR, now poetry install aborts with error message:


  InvalidCurrentPythonVersionError

  Current Python version (3.8.10) is not allowed by the project (^3.9).
  Please change python executable via the "env use" command.

  at ~/.poetry/lib/poetry/utils/env.py:651 in create_venv
       647│             current_python = Version.parse(
       648│                 ".".join(str(c) for c in env.version_info[:3])
       649│             )
       650│             if not self._poetry.package.python_constraint.allows(current_python):
    →  651│                 raise InvalidCurrentPythonVersionError(
       652│                     self._poetry.package.python_versions, current_python
       653│                 )
       654│             return env
       655│ 

As above message suggests, by running poetry env use python3.9 , poetry install will work again.

I expect this PR covers all commands which should check python version, like uninstall, run, shell etc.

Pull Request Check List

Resolves: #3426

  • Added tests for changed code.
  • [ ] Updated documentation for changed code.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

edmorley and dccsillag reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@edmorley

edmorley commented Feb 2, 2022

Copy link
Copy Markdown
Contributor

I was about to open a new issue for this. Do you know if you'll have a chance to fix the tests on this PR? :-)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@radoering radoering mentioned this pull request Feb 3, 2022
Poetry removes numpy for some versions of python and pandas #5102
Open
3 tasks done
@finswimmer

finswimmer commented Feb 6, 2022

Copy link
Copy Markdown
Member

Hey @yokomotod,

could you please rebase your PR to resolve the conflict?

Thanks a lot for your contribution 👍

fin swimmer

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@yokomotod
yokomotod force-pushed the check-current-python-version branch from 7682929 to adc88ef Compare February 7, 2022 17:59
@yokomotod
Check current python version
8b60bf2
@yokomotod
yokomotod force-pushed the check-current-python-version branch from adc88ef to 8b60bf2 Compare February 7, 2022 18:39
@yokomotod

yokomotod commented Feb 7, 2022

Copy link
Copy Markdown
Contributor Author

@finswimmer @edmorley done!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@finswimmer
finswimmer requested a review from a team February 24, 2022 10:38
radoering
radoering requested changes Feb 24, 2022
View reviewed changes

@radoering radoering left a comment

Copy link
Copy Markdown
Member

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.

Just a minor nitpick. Otherwise looks good.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/poetry/utils/env.py Outdated
)
if not self._poetry.package.python_constraint.allows(current_python):
raise InvalidCurrentPythonVersionError(
self._poetry.package.python_versions, current_python

@radoering radoering Feb 24, 2022

Copy link
Copy Markdown
Member

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.

current_python is of type Version, but the type hint in InvalidCurrentPythonVersionError says it should be a string. Thus, either the type hint has to be changed or current_python should be cast to string explicity str(current_python). I tend toward the latter.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@yokomotod yokomotod Feb 25, 2022

Copy link
Copy Markdown
Contributor Author

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.

that's true.

Suggested change
self._poetry.package.python_versions, current_python
self._poetry.package.python_versions, str(current_python)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@yokomotod
fix current_python type
06c390a
radoering
radoering approved these changes Feb 25, 2022
View reviewed changes
@yokomotod

yokomotod commented Mar 4, 2022

Copy link
Copy Markdown
Contributor Author

@radoering Thank you for the review. Can we merge then?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@radoering

radoering commented Mar 4, 2022

Copy link
Copy Markdown
Member

The tests have to be triggered and succeed first. Unfortunately, I have neither the permissions to trigger the tests nor to merge.

@finswimmer ?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

finswimmer
finswimmer approved these changes Mar 4, 2022
View reviewed changes

@finswimmer finswimmer left a comment

Copy link
Copy Markdown
Member

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 a lot 👍 🏅

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@finswimmer
finswimmer merged commit 0b8ef3a into python-poetry:master Mar 4, 2022
@abn abn mentioned this pull request Mar 4, 2022
PEP610: handle optional vcs_info.requested_version #5274
Merged
@finswimmer finswimmer mentioned this pull request Mar 6, 2022
Release 1.2.0b1 #5280
Merged
@finswimmer finswimmer mentioned this pull request May 4, 2022
Poetry doesn't raise error if using wrong python version #5540
Closed
3 tasks done
@github-actions

github-actions Bot commented Feb 29, 2024

Copy link
Copy Markdown

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Feb 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

@finswimmer finswimmer finswimmer approved these changes
@radoering radoering radoering approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Invalid python version not detected

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@yokomotod @edmorley @finswimmer @radoering
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.