primitives¶
Private Methods
Private methods, if any (those starting with _), are documented
for completeness but do not offer any stability guarantees.
They may change or be removed at any time without notice.
Shared primitives for Polytropos.
_convert_readme_to_rst(root, readme_filename, src_dir, content_type, module_name)
¶
Convert README to RST format using pandoc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
Project root directory |
required |
readme_filename
|
str
|
Name of the readme file |
required |
src_dir
|
str | None
|
Source directory relative to root |
required |
content_type
|
str
|
Content type of the readme file |
required |
module_name
|
str
|
Module name for image path rewriting |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
RST converted content or None if readme is in src directory |
Source code in src/polytropos/primitives.py
_dir_parts(path)
¶
Split a project-relative directory into its path components.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Project-relative directory |
required |
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
Tuple of the path components, empty for the project root |
Source code in src/polytropos/primitives.py
_dirs_overlap(first, second)
¶
Check whether two directories overlap.
Two directories overlap when one of them contains the other, so they share at least one file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
first
|
str
|
Project-relative directory |
required |
second
|
str
|
Project-relative directory |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when the directories overlap |
Source code in src/polytropos/primitives.py
_join_src_dir(path, src_dir)
¶
Prefix a path with the source directory of the project.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Project-relative path |
required |
src_dir
|
str | None
|
Source directory of the project (e.g., "src"), if configured |
required |
Returns:
| Type | Description |
|---|---|
str
|
Path relative to the project root |
Source code in src/polytropos/primitives.py
_render_src_dirs(entry, src_dir)
¶
Get the project-relative directories that hold the render sources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry
|
dict[str, Any]
|
File map entry |
required |
src_dir
|
str | None
|
Source directory of the project (e.g., "src"), if configured |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of directories relative to the project root |
Source code in src/polytropos/primitives.py
build_full_version(module_version, odoo_release)
¶
Build the full version string for the module.
Combines the Odoo release (A.B) with the module version (X.Y.Z) to form A.B.X.Y.Z (5+ components, required by manifestoo-core).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
module_version
|
str
|
Module version (e.g., "1.0.0", "1.2.3") |
required |
odoo_release
|
str
|
Odoo release (e.g., "17.0") |
required |
Returns:
| Type | Description |
|---|---|
str
|
Full version (e.g., "17.0.1.0.0", "18.0.1.2.3") |
Raises:
| Type | Description |
|---|---|
ValueError
|
If module version has fewer than 3 components |
Source code in src/polytropos/primitives.py
check_dynamic_version(pyproject_data)
¶
Check that version is declared as dynamic if present.
Without dynamic=['version'], tools like uv cannot properly resolve dependencies that depend on the Odoo release (e.g., odoo-addon-foo==18.0.*).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pyproject_data
|
dict[str, Any]
|
Parsed pyproject.toml |
required |
Source code in src/polytropos/primitives.py
check_release_compatibility(odoo_release, pyproject_data)
¶
Check if Odoo release is compatible with project.dependencies constraints.
Combines all odoo dependency entries (e.g. ["odoo>=18", "odoo<19"])
into a single specifier set before validation so that split constraints are
handled identically to a single "odoo>=18,<19" entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
odoo_release
|
str
|
Odoo release version (e.g., "17.0") |
required |
pyproject_data
|
dict[str, Any]
|
Parsed pyproject.toml |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If release is incompatible with constraints |
Source code in src/polytropos/primitives.py
deep_merge(base, override)
¶
Deep merge two dictionaries.
- If value is a dict, recurse
- If value is a list, extend base list with override list
- Otherwise, override the value
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base
|
dict[str, Any]
|
Base dictionary |
required |
override
|
dict[str, Any]
|
Override dictionary |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Merged dictionary |
Source code in src/polytropos/primitives.py
get_exclusion_patterns(root)
¶
Get file patterns to exclude from builds.
Combines default patterns with .gitignore if present.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
Project root directory |
required |
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of glob patterns to exclude |
Source code in src/polytropos/primitives.py
get_odoo_release(config_settings=None, pyproject_data=None)
¶
Get the Odoo release to use for building.
Resolution order: 1. config_settings["odoo_release"] 2. ODOO_RELEASE environment variable 3. odoo.release.series (if odoo installed) 4. tool.polytropos.default_odoo_release (if pyproject_data provided)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_settings
|
dict[str, Any] | None
|
PEP 517 config_settings dictionary |
None
|
pyproject_data
|
dict[str, Any] | None
|
Parsed pyproject.toml (optional, for default fallback) |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Odoo release string (e.g., "17.0") |
Raises:
| Type | Description |
|---|---|
ValueError
|
If release cannot be determined |
Source code in src/polytropos/primitives.py
get_pyproject_data(root)
¶
Load and parse pyproject.toml.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
Path to the project root |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Parsed pyproject.toml as dictionary |
Raises:
| Type | Description |
|---|---|
ValueError
|
If pyproject.toml not found |
Source code in src/polytropos/primitives.py
get_readme_info(pyproject_data, root=None, src_dir=None, module_name='')
¶
Get readme file path, content type, and optionally description content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pyproject_data
|
dict[str, Any]
|
Parsed pyproject.toml |
required |
root
|
Path | None
|
Project root directory (optional, for reading description) |
None
|
src_dir
|
str | None
|
Source directory relative to root (optional) |
None
|
module_name
|
str
|
Module name for image path rewriting |
''
|
Returns:
| Type | Description |
|---|---|
tuple[str, str, str | None] | None
|
Tuple of (readme_filename, content_type, description) or None if not specified. |
tuple[str, str, str | None] | None
|
Description is None if root not provided or readme is in src_dir. |
Source code in src/polytropos/primitives.py
get_render_dst_dirs(pyproject_data, src_dir=None)
¶
Get the project-relative destination directories of every render file map.
All releases are considered, since the sdist is release-independent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pyproject_data
|
dict[str, Any]
|
Parsed pyproject.toml |
required |
src_dir
|
str | None
|
Source directory of the project (e.g., "src"), if configured |
None
|
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of |
Source code in src/polytropos/primitives.py
get_render_entries(pyproject_data)
¶
Get every render file map entry, for all releases.
Unlike parse_file_maps, no release filter is applied: the sdist is
release-independent, and a build must not ship the leftovers of another
release.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pyproject_data
|
dict[str, Any]
|
Parsed pyproject.toml |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of the render file map entries |
Source code in src/polytropos/primitives.py
get_src_dir(root)
¶
Get the src directory from polytropos configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root
|
Path
|
Path to the project root |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The src directory path (e.g., "src") or None if not configured |
Source code in src/polytropos/primitives.py
get_src_dir_from_data(pyproject_data)
¶
Get the src directory from already parsed configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pyproject_data
|
dict[str, Any]
|
Parsed pyproject.toml |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
The src directory path (e.g., "src") or None if not configured |
Source code in src/polytropos/primitives.py
is_generated_gitignore(path)
¶
Check whether a .gitignore file was generated by Polytropos.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path
|
Path to the file |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True when the file was generated by Polytropos |
Source code in src/polytropos/primitives.py
matches_release_specifier(release_version, specifier)
¶
Check if release matches the given PEP 440 specifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
release_version
|
Version
|
Parsed Version object |
required |
specifier
|
str | None
|
PEP 440 version specifier (e.g., ">=18, <20") |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if release matches specifier |
Source code in src/polytropos/primitives.py
parse_file_maps(pyproject_data, odoo_release)
¶
Parse [[tool.polytropos.files]] entries filtered by release.
Each entry maps versioned source content into a destination directory. Only entries matching the current Odoo release are returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pyproject_data
|
dict[str, Any]
|
Parsed pyproject.toml |
required |
odoo_release
|
str
|
Odoo release string (e.g., "17.0") |
required |
Returns:
| Type | Description |
|---|---|
list[dict[str, Any]]
|
List of matching file map entries, each with "src_files"/"src_dir" and "dst_dir" keys |
Source code in src/polytropos/primitives.py
parse_release(release)
¶
Parse release string to Version object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
release
|
str
|
Release string (e.g., "17.0") |
required |
Returns:
| Type | Description |
|---|---|
Version
|
Version object |
Source code in src/polytropos/primitives.py
validate_render_file_maps(pyproject_data, src_dir=None)
¶
Check that no render file map renders into its own source directory.
Rendering from and to the same folder is a broken configuration: the
rendered files end up mixed with the sources, and the sources would be
hidden from Git by the generated .gitignore.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pyproject_data
|
dict[str, Any]
|
Parsed pyproject.toml |
required |
src_dir
|
str | None
|
Source directory of the project (e.g., "src"), if configured |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a render source and its destination overlap |
Source code in src/polytropos/primitives.py
write_dst_gitignore(dst_dir)
¶
Write a .gitignore that ignores the whole destination directory.
The generated file ignores every entry of dst_dir, including itself, so
the rendered files never reach version control. Polytropos recreates it on
every build, so there is nothing to track.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dst_dir
|
Path
|
Destination directory of a render file map |
required |
Returns:
| Type | Description |
|---|---|
Path
|
Path to the |