Skip to content

omm: make generated Python packages importable for custom and reserved names - #105

Open
0z5a wants to merge 1 commit into
NVIDIA:mainfrom
0z5a:omm-python-package-names
Open

0z5a wants to merge 1 commit into
NVIDIA:mainfrom
0z5a:omm-python-package-names

Conversation

@0z5a

@0z5a 0z5a commented Nov 17, 2026

Copy link
Copy Markdown

Fixes #104.

omm create --language python fails at the validation step whenever the import package is not the distribution-derived name, and whenever the derived package is a Python keyword or shadows another top-level module. Nothing is published in either case, but the user only sees a uv sync or pytest error after the downloads.

Changes

  • templates/python/pyproject.toml: set [tool.uv.build-backend] module-name = "__PACKAGE_NAME__". Without it, uv_build expects src/<distribution name>/, so --package-name (documented in the README) and numeric project names such as 123 (which the generator renames to middleware_123) cannot build.
  • generator.py: new _python_package_conflict(). A derived package that is a keyword, a standard-library module (sys.stdlib_module_names) or a template dependency (grpc, google) gets the existing middleware_ prefix, like numeric names and the Rust reserved-name handling. An explicit --package-name with such a name raises ProjectError in _template_context, before any network or filesystem work.
  • Tests: the override and numeric tests now check the generated module-name; new parametrized tests cover derived names (assert, logging, secrets, http, grpc, google) and rejected overrides (class, logging, grpc).

Validation (macOS arm64, uv 0.11.3)

  • The 11 new or extended test cases fail on main and pass with this change.

  • make check: ruff format --check, ruff check and ty check pass. pytest: 100 passed, 4 failed. The same 4 tests fail on main on macOS (test_publish_reports_filesystem_without_no_replace_support[22/78/102] and test_publish_translates_unexpected_rename_error: their fake libc defines only renameat2, while macOS takes the renamex_np path). They are unrelated to this change, and the coverage gate misses on macOS for the same reason (93.82% on main, 93.94% with this change). These checks were not run on Linux.

  • Real end-to-end runs with --openshell-version v0.0.86:

    command main this branch
    omm create audit-headers (control) exit 0, 5 passed exit 0, 5 passed, src/audit_headers
    omm create audit-headers --package-name custom_pkg exit 1 (Expected a Python module at: src/audit_headers/__init__.py) exit 0, 5 passed, src/custom_pkg
    omm create 123 exit 1 (src/123/__init__.py) exit 0, 5 passed, src/middleware_123
    omm create logging / secrets / http / grpc / google exit 1 (ModuleNotFoundError) exit 0, 5 passed, src/middleware_<name>
    omm create assert exit 1 (SyntaxError) exit 0, 5 passed, src/middleware_assert
    omm create proj --package-name logging exit 1 after sync/pytest exit 1 immediately: Python package name 'logging' shadows a Python standard-library module
  • With --package-name custom_pkg, uv build --wheel packages custom_pkg/server.py, and uv run audit-headers --help runs.

Rust projects and omm update are unchanged. update does not re-render pyproject.toml. Before this change, projects with these names could not be created at all, so no existing project is affected.

This change was drafted with Claude Code (claude-opus-5-5); the test results above are from the runs described.

…d names

The Python template used uv_build without module-name, so uv_build
expected src/<distribution name>/. --package-name and numeric project
names (renamed to middleware_<n>) therefore failed at uv sync.
Derived package names that are keywords or shadow a standard-library
or template-dependency module (logging, secrets, http, grpc, google,
assert) were used verbatim and failed at the generated project's
pytest step.

Set module-name in the template, give such derived names the existing
middleware_ prefix, and reject an explicit --package-name that would
shadow a module before any download.

Fixes NVIDIA#104

Signed-off-by: Dezhen Lu <dezhen.lu@student.uni-tuebingen.de>

This branch has not been deployed

No deployments
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.

omm create: Python projects fail validation when the import package differs from the project name (--package-name, numeric names, logging, secrets, ...)

1 participant