[FIX] common: improve python requirements parsing and caching#153
Merged
Conversation
brinkflew
approved these changes
Apr 28, 2026
- Fix git requirements parsing when the package name is specified (pkg @ git+url). - Improve RE_PACKAGE regex to support complex version strings (e.g. .post1, rc1). - Add a warning for unnamed git requirements in requirements.txt. - Cache the parsed installed packages to avoid redundant logs and processing. Assisted-by: gemini-3-flash <noreply@google.com>
9844bf3 to
4b24d64
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
package_name @ git+url@version,odevwould incorrectly extract the version from the package name instead of the URL, leading to constant re-installations because it thought the version was incorrect (e.g.,1.0.0 != master).RE_PACKAGEregex was too restrictive, only allowing digits and dots. It failed to parse versions like5.4.2.post1, causing it to ignore the environment markers (conditions) that follow. This led to incorrect version mismatches (e.g., trying to apply a Python < 3.11 requirement on Python 3.12).installed_packages()was called for every requirements file check, causing redundant parsing and logging of "Invalid version format" for git-based packages at the DEBUG level.Proposed Changes
__package_spec: Now correctly identifies the source of the version string in git-based requirements.RE_PACKAGE: Expanded the allowed characters in version strings to support PEP 440 suffixes (post,rc,dev, etc.).installed_packages()is now cached (TTL 60s), significantly reducing log noise and processing time when multiple requirements files are checked.git+requirement is not named, encouraging the use of thepkg @ git+urlformat.Examples
Fixed Git Requirement Parsing
Before, this would trigger an install every time:
Log before:
Incorrect git python package version 'odoo_upgrade' ('ae2fe6...' != '1.0.0')Log after: (Package correctly identified as up-to-date).
Fixed Complex Versions (
.post1)Before: Regex stopped at
5.4.2, ignored the condition, and saw a conflict with the installed version on Python 3.12.After: Version
5.4.2.post1is fully captured, and the condition is correctly evaluated.Verification
TestPythonEnvtests pass.Assisted-by: gemini-3-flash noreply@google.com