Skip to content

[FIX] common: improve python requirements parsing and caching#153

Merged
sea-odoo merged 1 commit into
betafrom
fix-pip-requirements-parsing
Apr 28, 2026
Merged

[FIX] common: improve python requirements parsing and caching#153
sea-odoo merged 1 commit into
betafrom
fix-pip-requirements-parsing

Conversation

@sea-odoo
Copy link
Copy Markdown
Contributor

Problem

  1. Git Parsing Bug: When a git requirement is specified with the recommended format package_name @ git+url@version, odev would 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).
  2. Version String Limitation: The RE_PACKAGE regex was too restrictive, only allowing digits and dots. It failed to parse versions like 5.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).
  3. Redundant Logging: 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.
  4. Best Practice Enforcement: Unnamed git requirements (just the URL) make it hard for tools to correlate installed packages.

Proposed Changes

  • Fixed __package_spec: Now correctly identifies the source of the version string in git-based requirements.
  • Improved RE_PACKAGE: Expanded the allowed characters in version strings to support PEP 440 suffixes (post, rc, dev, etc.).
  • Added Caching: The parsed result of installed_packages() is now cached (TTL 60s), significantly reducing log noise and processing time when multiple requirements files are checked.
  • Added Warning: A warning is now displayed if a git+ requirement is not named, encouraging the use of the pkg @ git+url format.

Examples

Fixed Git Requirement Parsing

Before, this would trigger an install every time:

odoo_upgrade @ git+https://github.com/odoo/upgrade-util@master

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)

cbor2==5.4.2.post1 ; python_version < '3.11'

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.post1 is fully captured, and the condition is correctly evaluated.


Verification

  • Tested with a reproduction script covering all problematic cases.
  • Existing TestPythonEnv tests pass.
  • Verified that logs are much cleaner in DEBUG mode thanks to caching.

Assisted-by: gemini-3-flash noreply@google.com

@sea-odoo sea-odoo requested a review from brinkflew April 27, 2026 18:49
@sea-odoo sea-odoo changed the base branch from main to beta April 27, 2026 18:49
- 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>
@sea-odoo sea-odoo force-pushed the fix-pip-requirements-parsing branch from 9844bf3 to 4b24d64 Compare April 28, 2026 12:42
@sea-odoo sea-odoo merged commit 474ef67 into beta Apr 28, 2026
5 of 6 checks passed
@sea-odoo sea-odoo deleted the fix-pip-requirements-parsing branch April 28, 2026 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants