Skip to content

Update package structure to be installable #78

Description

@mihow

Background

The codebase imports its modules under the literal top-level name src (e.g. from src.dataset_tools.cli import cli), and the packaging entry points follow suit (ami-dataset = "src.dataset_tools.cli:cli"). After the Poetry→uv migration (#68), the wheel ships src/ and this works for editable installs and even for a non-editable pip install (verified by building the wheel and importing src.dataset_tools.cli from outside the repo).

It works, but src is not a good distribution package name:

  • src is a generic name. In a shared environment it can collide or merge (implicit namespace packages) with any other project that also ships a top-level src.
  • src/ is conventionally a layout container, not the package itself. The standard src-layout puts a single importable package one level down (src/<package>/) and imports it by name (<package>.…), never src.….
  • pip install ami-ml currently exposes a package called src, which is surprising for any downstream consumer.

This aligns the repo with the standard src-layout used elsewhere in the lab.

Goal

Rename the package so the project installs cleanly and is imported as ami_ml:

  • Move the modules under a single package: src/ami_ml/{dataset_tools,classification,localization}/
  • from src.dataset_tools import …from ami_ml.dataset_tools import …
  • Packaging: [tool.hatch.build.targets.wheel] packages = ["src/ami_ml"]
  • Update the entry points (ami-dataset, ami-classification), the tests (tests/ imports), and the flake8 per-file-ignores paths.

Sketch

mkdir -p src/ami_ml
git mv src/dataset_tools src/classification src/localization src/ami_ml/
# add src/ami_ml/__init__.py
grep -rl --include='*.py' --include='*.sh' '\bsrc\.' . | xargs sed -i 's/\bsrc\./ami_ml./g'
# then hand-fix: pyproject entry points + packages, flake8 per-file-ignores, any string refs

git mv is preferable to a Hatchling sources path remap: with the directory actually named ami_ml, both editable and wheel installs resolve ami_ml for free, and there's no dev/wheel import-name mismatch. (A build-time remap was tested and is fragile — it still forces the same import rewrite, so it buys nothing.)

Sequencing

This rewrites nearly every import line, so it should land after the in-flight PRs that heavily touch src/ (#74, #69) to avoid rebase conflicts.

Notes

  • Not a blocker for Migrate dependency management from Poetry to uv #68 — the current src packaging is verified working; this is a correctness/cleanliness follow-up.
  • Verify after: uv build --wheel, install the wheel non-editable in a clean venv, ami-dataset --help + import ami_ml.dataset_tools, and uv run pytest tests/.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions