-
Notifications
You must be signed in to change notification settings - Fork 2.4k
env use: fail if python version is not supported by the project #10685
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
env use: fail if python version is not supported by the project #10685
Conversation
Reviewer's GuideEnsures Sequence diagram for env_use failing on unsupported_python_versionsequenceDiagram
actor Developer
participant EnvUseCommand
participant EnvManager
participant PoetryConfig
participant PoetryPackage
Developer->>EnvUseCommand: env use python_spec
EnvUseCommand->>EnvManager: create_venv(python_spec)
EnvManager->>EnvManager: determine specific_python_requested
EnvManager->>PoetryConfig: get(virtualenvs.create)
EnvManager->>PoetryConfig: get(virtualenvs.prompt)
EnvManager->>PoetryPackage: read python_versions
alt python_spec not_compatible_with PoetryPackage.python_versions
EnvManager->>EnvManager: detect_no_compatible_python
EnvManager-->>EnvUseCommand: raise NoCompatiblePythonVersionFoundError
EnvUseCommand-->>Developer: display error unsupported Python version
else python_spec compatible
EnvManager->>EnvManager: proceed_with_venv_creation
EnvManager-->>EnvUseCommand: return created_virtualenv
EnvUseCommand-->>Developer: show success message
end
Class diagram for EnvManager_create_venv Python_version_handlingclassDiagram
class EnvManager {
+create_venv(python, io)
-use_in_project_venv() bool
-_poetry Poetry
}
class Poetry {
+config Config
+package Package
}
class Config {
+get(key) any
}
class Package {
+python_versions str
}
class NoCompatiblePythonVersionFoundError {
}
EnvManager --> Poetry : uses
Poetry --> Config : has
Poetry --> Package : has
EnvManager ..> NoCompatiblePythonVersionFoundError : raises
note for EnvManager "In create_venv:
- specific_python_requested is true when python is not None
- If specific_python_requested and requested version is incompatible
with Package.python_versions, EnvManager now always raises
NoCompatiblePythonVersionFoundError, regardless of
Config[virtualenvs.use-poetry-python]"
File-Level Changes
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey - I've left some high level feedback:
- Consider adding a short inline comment near the
if specific_python_requested:check increate_venv()to explain whyuse-poetry-pythonis intentionally ignored when an explicit Python is requested, to prevent future re-introduction of the previous behavior. - In the new tests that assert an empty cache (
assert not list(venv_cache.iterdir())), you could factor this into a small helper or use a more explicit check (e.g.assert not any(venv_cache.iterdir())) to make the intent clearer and avoid repeating the pattern.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider adding a short inline comment near the `if specific_python_requested:` check in `create_venv()` to explain why `use-poetry-python` is intentionally ignored when an explicit Python is requested, to prevent future re-introduction of the previous behavior.
- In the new tests that assert an empty cache (`assert not list(venv_cache.iterdir())`), you could factor this into a small helper or use a more explicit check (e.g. `assert not any(venv_cache.iterdir())`) to make the intent clearer and avoid repeating the pattern.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
9001c58 to
9bc4196
Compare
Pull Request Check List
Resolves: https://github.com/orgs/python-poetry/discussions/10523
use-poetry-pythonshould only be relevant if no specific python version has been requested.This bug originates from #4852 when the condition was not as clear as it is now:
Summary by Sourcery
Ensure
env useand virtualenv creation fail cleanly when a specifically requested Python version is not compatible with the project, regardless of theuse-poetry-pythonsetting.Bug Fixes:
virtualenvs.use-poetry-pythonconfiguration.Tests:
env usedoes not create or activate environments for unsupported Python versions and that executable-based venv creation skips compatibility lookups for both values ofuse-poetry-python.Chores: