-
-
Notifications
You must be signed in to change notification settings - Fork 645
exp: pypi- allow users to pass any versions #3482
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
base: main
Are you sure you want to change the base?
Conversation
Summary of ChangesHello @aignas, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request introduces experimental changes to the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces changes to allow any valid PEP440 version string for Python, normalizing them across the system. The core change is to consistently use version.parse() for normalization. My review identified a recurring high-severity issue where the code does not check if version.parse() returns None before accessing its attributes, which can lead to crashes with invalid version strings. I have provided comments and suggestions in multiple files to add the necessary checks by enabling strict parsing, which will make the implementation more robust.
| # the `FeatureFlagInfo`? | ||
| # | ||
| # ensure that the values here are normalized | ||
| value = version.parse(value).string |
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.
version.parse() with the default strict=False can return None for invalid versions, which would cause a crash when accessing .string. Using strict=True will ensure it fails with a descriptive error message for invalid versions, which is safer and provides better user feedback.
| value = version.parse(value).string | |
| value = version.parse(value, strict = True).string |
| ver = version.parse(input) | ||
| value = _flag_value(ctx.attr._python_version_flag) | ||
| if value: | ||
| ver = version.parse(value) |
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.
For robustness, it's better to parse with strict=True. Although the version string should already be normalized at this point, this provides defense-in-depth and ensures a clear failure instead of a potential crash if an invalid version string is somehow passed here.
| ver = version.parse(value) | |
| ver = version.parse(value, strict = True) |
|
|
||
| def _major_minor_version(version_str): | ||
| def _normalize_version(version_str): | ||
| ver = version.parse(version_str) |
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.
| python_name = "python_{}_host".format( | ||
| pip_attr.python_version.replace(".", "_"), | ||
| # normalize the version when getting the available interpreter | ||
| version.parse(pip_attr.python_version).string.replace(".", "_"), |
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.
version.parse() with the default strict=False can return None for invalid versions, causing a crash on .string access. Using strict=True will cause it to fail with a descriptive error message for invalid versions, which is safer.
version.parse(pip_attr.python_version, strict = True).string.replace(".", "_"),
| minor, _, _ = version.partition(".") | ||
|
|
||
| return major + sep + minor | ||
| parsed = v.parse(version) |
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.
v.parse() with the default strict=False can return None for invalid versions, causing a crash on .string access on the next line. Using strict=True will cause it to fail with a descriptive error message for invalid versions, which is safer.
| parsed = v.parse(version) | |
| parsed = v.parse(version, strict = True) |
| "3.15.2": "3152", | ||
| }.items(): | ||
| # All of the versions should be normalized | ||
| normalized_python_version = _version.parse(python_version).string |
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 call is unsafe as _version.parse() can return None. Using strict=True will make the test fail clearly if an invalid version string is ever added to the test cases, which is a good practice for test robustness.
| normalized_python_version = _version.parse(python_version).string | |
| normalized_python_version = _version.parse(python_version, strict = True).string |
This is a quick draft POC to outline how I imagine any versions in
pip.parsebeing handled.TODO:
users can specify anything, so we should normalize, but where do we stop?
Fixes #3479.