Skip to content

feat: add extra_commands support to presets with odoo_version markers#9

Merged
trisdoan merged 5 commits intotrobz:mainfrom
nilshamerlinck:vatnumber
Feb 9, 2026
Merged

feat: add extra_commands support to presets with odoo_version markers#9
trisdoan merged 5 commits intotrobz:mainfrom
nilshamerlinck:vatnumber

Conversation

@nilshamerlinck
Copy link
Copy Markdown
Contributor

@nilshamerlinck nilshamerlinck commented Feb 6, 2026

We have to handle a particular packaging case for old odoo.

  • vatnumber is needed for odoo <= 13.0, see here
  • vatnumber package needs 2to3 to build which has been removed from recent setuptools
  • in the past we had pinned "setuptools<58" as a workaround:
  • then on oca ci, the workaround was moved to a dedicated container for legacy odoo: see here

This PR is an attempt at handling it properly in odoo-venv:

Summary

  • Add extra_commands field to presets.toml to run additional commands at specific stages during venv creation
  • Commands can be conditional based on odoo_version markers (e.g., odoo_version <= '13.0')
  • Support for environment variables in commands (e.g., UV_NO_BUILD_ISOLATION=1)
  • Verbose output shows condition and environment for each executed command

Details

The new extra_commands feature allows running arbitrary commands at three stages:

  • after_venv - after virtual environment creation
  • after_requirements - after installing all requirements
  • after_odoo_install - after installing Odoo in editable mode

Each command can have:

  • command: list of command arguments
  • when: marker expression (supports odoo_version and standard packaging markers)
  • stage: one of the three stages above
  • env: optional dict of environment variables

Concretely for vatnumber

[[common.extra_commands]]
command = ["uv", "pip", "install", "setuptools<58.0"]
when = "odoo_version <= '13.0'"
stage = "after_requirements"

[[common.extra_commands]]
command = ["uv", "pip", "install", "vatnumber==1.2"]
when = "odoo_version <= '13.0'"
stage = "after_requirements"
env = { UV_NO_BUILD_ISOLATION = "1" }

[[common.extra_commands]]
command = ["uv", "pip", "install", "setuptools<58.0"]
when = "odoo_version <= '13.0'"
stage = "after_requirements"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the solution. Just a small correction about the stage.

Suggested change
stage = "after_requirements"
stage = "after_venv"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for your review @hailangvn

I updated the PR to keep the change at after_requirements stage:

  • vatnumber was missing from ignore_from_odoo_requirements, fixed
  • I prefer to handle this case as an explicit exception happening after normal requirements are installed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please have a second look? Also added a commit for the README.md

[[common.extra_commands]]
command = ["uv", "pip", "install", "vatnumber==1.2"]
when = "odoo_version <= '13.0'"
stage = "after_requirements"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
stage = "after_requirements"
stage = "after_venv"

command = ["uv", "pip", "install", "setuptools<58.0"]
when = "odoo_version <= '13.0'"
stage = "after_requirements"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Install wheel to prepare for vatnumber installation
[[common.extra_commands]]
command = ["uv", "pip", "install", "wheel"]
when = "odoo_version <= '13.0'"
stage = "after_venv"

Add ability to run extra commands at specific stages during venv creation
based on odoo_version marker conditions.

Features:
- New 'extra_commands' field in presets.toml with 'when', 'stage', and 'env' keys
- Custom odoo_version marker evaluation (<=13.0, >=14.0, etc.)
- Support for environment variables in commands
- Verbose output showing condition and environment for each command
- Three execution stages: after_venv, after_requirements, after_odoo_install

Example usage:
  [[common.extra_commands]]
  command = ["uv", "pip", "install", "setuptools<58.0", "wheel"]
  when = "odoo_version <= '13.0'"
  stage = "after_requirements"

  [[common.extra_commands]]
  command = ["uv", "pip", "install", "vatnumber==1.2"]
  when = "odoo_version <= '13.0'"
  stage = "after_requirements"
  env = { UV_NO_BUILD_ISOLATION = "1" }

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@nilshamerlinck nilshamerlinck marked this pull request as ready for review February 6, 2026 09:30
- Add VALID_STAGES constant to validate command execution stages
- Extract validation logic to _validate_cmd_spec() helper (reduces
complexity)
- Extract error handling to _handle_cmd_error() helper
- Extract logging to _print_cmd_info() helper
- Wrap command execution in try/catch for detailed error context
- Update presets.toml with marker syntax examples and limitations
@trisdoan
Copy link
Copy Markdown
Collaborator

trisdoan commented Feb 9, 2026

Hi anh @nilshamerlinck , great idea!

just added some validation and docstring about the change, ok for you?

@nilshamerlinck
Copy link
Copy Markdown
Contributor Author

thanks @trisdoan, ok for me

PS: now that we are trying odoo-venv with older codebases, we will probably face other "odd cases" like that...

@trisdoan trisdoan merged commit ff59cfe into trobz:main Feb 9, 2026
1 check passed
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.

3 participants