Skip to content

Add flakeModules.python: uv2nix, ruff, ty and org versioning for Python repos - #35

Merged
andrewthomaslee merged 1 commit into
mainfrom
python-flake-module
Nov 14, 2026
Merged

andrewthomaslee merged 1 commit into
mainfrom
python-flake-module

Conversation

@andrewthomaslee

Copy link
Copy Markdown
Member

Summary

Python becomes part of the org standard: a repo with pyproject.toml + uv.lock gets everything from flakeModules.default, with no uv2nix inputs of its own.

 flakeModules/
   dev.nix                 # default: + python
+  python.nix              # packages, apps, checks, ruff in treefmt, vmTests.python-cli
+  python/workspace.nix    # the builder (also lib.python.mkWorkspace)
+  python/fixture/         # self-test workspace (checks.python-module)
 devenv/
+  python/devenv.nix       # org-pkgs/devenv/python: editable venv, uv, ruff, ty
 flake-parts/
+  lib-python.nix          # lib.python.mkWorkspace bound to pkgs' uv2nix pins
 templates/default/        # nixd org-overlay expr, Python editor settings, extensions
 documentation/docs/
+  python.md               # the standard: versions, consumption, devenv, editors, nixd

What a Python repo gets:

packages.<project>/.default   scripts wrapped (makeWrapper), pname/version/meta
                              version <major>.<minor>.<self.revCount>
apps.<script>
checks.python-{pytest,ty,uv-lock,version}   + ruff check/format in checks.treefmt
vmTests.python-cli            each script --version / --help, as a user, offline
  • Versioning: pyproject keeps X.Y.0 (checked against ci.yml major/minor); the shipped set stamps the patch with the commit count. Org git dependencies (another repo's library, locked by uv) are stamped from their own fetched commit count. Checks use the unstamped set, so they don't rebuild per commit.
  • devenv: the editable .pth holds a literal path (works without $DEVENV_ROOT), and editable members build from pyproject/readme/__init__.py only, so .py edits no longer rebuild the venv. UV_PROJECT_ENVIRONMENT keeps uv run on the Nix venv.
  • ruff: Astral defaults, run by treefmt only in Python repos. ty: --error-on-warning (option python.ty.args).
  • Generated packages/apps are mkDefault: a repo's own definition wins (also keeps the moscripts main this flake consumes evaluating unchanged until it adopts the module).

Evidence

  • nix run .#flake-check → rc=0, no evaluation warnings (incl. new checks.python-module: fixture stamped 0.1.7, unstamped 0.1.0, fixture --version → fixture 0.1.7).
  • moscripts on a branch using this module (locally locked to this commit, never pushed):
    • python-pytest (39 passed), python-ty (All checks passed), python-uv-lock, python-version, treefmt → PASS
    • clean tree with 80 commits: nix build → moscripts-0.2.80, motmp --version → moscripts 0.2.80
    • vm-test python-cli --remote --rebuild → passed (101s), 4 CLIs
    • devenv: python -c 'import moscripts' resolves to the checkout with DEVENV_ROOT unset; uv run uses the Nix venv, no .venv; a .py edit leaves .devenv/profile unchanged (before: rebuilt)
  • nixd expr (pkgs): import nixpkgs { overlays = [ f.overlays.default ]; } → moscripts-0.2.0, headroom 0.43.1, zen-browser 1.24b.

Merge Danger

Door: two-way

Additive: repos without pyproject.toml + uv.lock see no change (the module stays off and never fetches uv2nix). Template changes only affect new repos.

Blast Radius: Python repos

Only moscripts uses Python today; its own wiring keeps winning (mkDefault) until its PR adopts the module.

Merge order: this PR → andrewthomaslee/moscripts adopts the module → pkgs takes moscripts via git+https → skills (uv2nix + external-systems skills) → modules → home. A separate pkgs PR adds git credentials to org-ci for private Python repos.

🤖 Generated with Claude Code

…on repos

A repo with pyproject.toml + uv.lock at its root now gets packages, apps,
checks (pytest, ty, uv-lock, version), ruff in treefmt and a python-cli
VM test from flakeModules.default, with no uv2nix inputs of its own. The
shipped packages are versioned <major>.<minor>.<commit count> from
self.revCount; org git dependencies get their own commit count. The
devenv module org-pkgs/devenv/python builds the editable venv from the
same builder, with a literal editable root and a minimal editable source,
so .py edits rebuild nothing. The template's nixd settings evaluate
nixpkgs with the org overlay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant