Skip to content

Build: swap flit_core for hatchling + uv-dynamic-versioning#301

Open
jeandet wants to merge 127 commits into
SciQLop:mainfrom
jeandet:modernisation/pr10-build-backend-hatchling
Open

Build: swap flit_core for hatchling + uv-dynamic-versioning#301
jeandet wants to merge 127 commits into
SciQLop:mainfrom
jeandet:modernisation/pr10-build-backend-hatchling

Conversation

@jeandet
Copy link
Copy Markdown
Member

@jeandet jeandet commented May 14, 2026

Summary

Tenth PR of the modernisation effort. Replaces flit_core with hatchling + uv-dynamic-versioning so the version is derived from git tags. Drops the 5-file bumpversion machinery; replaces with a small scripts/release.sh.

Plan: docs/superpowers/plans/2026-05-14-pr10-build-backend-hatchling.md.

Stacked on PR #299 (CDPP3DView), which stacks on #298#296#295#294#293#292#291#290.

What this PR does

  • pyproject.toml: flit_core.buildapihatchling.build + uv-dynamic-versioning. [project] version becomes dynamic. [tool.bumpversion] block deleted.
  • speasy/__init__.py: __version__ reads from importlib.metadata with a PackageNotFoundError → "0.0.0+dev" fallback for vendored-source checkouts.
  • docs/conf.py: reads version from speasy.__version__.
  • VERSION file deleted; source of truth is the git tag.
  • scripts/release.sh: small bash that updates CITATION.cff (version: + date-released:) + commits + tags. Maintainer pushes manually.

Wheel/sdist diff vs flit baseline

Wheel: only .dist-info/ filenames differ (new version string in dir name; AUTHORS.rst now bundled as a license-style file). All speasy/* content identical.

Sdist: hatchling sdist is a strict superset of flit's. Additions: AUTHORS.rst, CITATION.cff, CONTRIBUTING.rst, HISTORY.rst, full docs/ (incl. RST sources for downstream re-builds), full tests/ (tests + resources). tests/cassettes/, docs/superpowers/, docs/_build/, .publish_staging/ correctly excluded. No speasy/* files lost.

Version derivation example

After uv sync, import speasy; print(speasy.__version__) returns 1.7.2.dev245+c7b141c — tag v1.7.1 + 245 commits ahead + git hash. PEP 440 bump=true style. Real version, not the 0.0.0+dev fallback.

twine check

Checking dist/speasy-1.7.2.dev245+c7b141c-py3-none-any.whl: PASSED
Checking dist/speasy-1.7.2.dev245+c7b141c.tar.gz: PASSED

Test plan

  • CI: unit tier green
  • CI: release-check (build + twine check) green
  • Local: `uv build` produces a valid wheel + sdist with the tag-derived version
  • Local: fresh-venv install of the hatchling-built wheel imports and shows the right version

jeandet and others added 30 commits May 8, 2026 15:55
Captures decisions on UV adoption, hatchling build backend, ruff/basedpyright
tooling, and three-tier test strategy (unit/contract/e2e). Sequences the work
as 17 small PRs ending with a mass reformat.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Per-task implementation plan for the first PR of the modernisation effort.
Covers pyproject.toml updates, uv.lock generation, CI/RTD switch to uv,
deletion of requirements*.txt / tox.ini / setup.cfg, and developer-doc
updates to drop the PYTHONPATH=. pattern.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- Add SPEASY_CORE_HTTP_REWRITE_RULES env to PRs.yml non-3.10 pytest step
  (previously only on push/scheduled tests.yml — would have hit a
  non-existent server on PR builds for non-3.10 matrix entries).
- Add --with wheel to PRs.yml build step for parity with tests.yml.
- Scope flake8 to 'speasy tests' in both workflows (matches Makefile
  lint target). Avoids silently broadening lint to docs/conf.py and
  removes the .venv exclusion workaround that was needed when
  flake8 ran from repo root.
Without UV_PROJECT_ENVIRONMENT, uv creates .venv/ inside the project
and RTD's sphinx step (which calls $READTHEDOCS_VIRTUALENV_PATH/bin/python
directly) fails with 'python: not found'. Point uv at RTD's venv so the
install lands where the runner looks for it.
Classified via devtools/apply_test_markers.py:
- 12 files marked unit (pure-logic, no network)
- 19 files marked contract (real-server, will be migrated to cassettes in PRs 4-9)

Reclassifications during manual review:
- test_cache.py: contract -> unit (pure cache-logic, no network or speasy provider use)
- test_file_access.py: unit -> contract (uses HTTP via any_loc_open against live servers)

test_wasm.py was manually adjusted to place pytestmark at module level (the
file's body lives inside a try/except ImportError block, so the script's
naive insertion landed at wrong indentation).
…le path and sample across the inventory

The flat_inventories.generic_archive lookup uses module attribute access on
an instance, not a submodule import. Also, the first N parameters in the
flat inventory are clustered by mission, so a fixed time range can miss all
of them; sample across the full list instead.
- test_e2e_smoke.test_generic_archive: fail loudly if every candidate
  raises (was silently skipping, defeating the e2e tier's purpose).
- pyproject.toml: drop dead --ignore=setup.py from addopts and document
  the -m unit override semantics so future contributors don't trip on
  'pytest tests/test_amda.py' silently collecting nothing.
- contract.yml / e2e.yml: add concurrency groups so a manual run can't
  overlap with a cron run hammering the same upstream servers.
- CONTRIBUTING.rst: add a short note explaining the three test tiers
  and how to invoke each from local dev.
CI failure (blocking):
- unit.yml: 'make doctest' was using system Python (no sphinx in scope).
  Prefix with 'uv run' so make uses the project venv.

Reviewer findings:
- wasm_tests.yml: pytest tests/test_wasm.py without -m collected 0 tests
  under the new addopts default (test_wasm.py is contract-marked). Add
  -m '' to override.
- CLAUDE.md: examples like 'uv run pytest tests/test_amda.py' silently
  collected 0 tests under -m unit default. Replaced with tier-aware
  examples and added -m '' for the all-tests case.
- unit.yml: only sync --group docs on the coverage runner that needs it,
  not on every matrix entry.
nbsphinx requires the system pandoc binary (not the Python pandoc
wrapper that's in the docs dependency group). PR 1's tests.yml had
'sudo apt install -y texlive pandoc' before make doctest; my unit.yml
rewrite in PR 2 dropped that line, so the doctest job failed with
'nbsphinx.NotebookError: PandocMissing in examples/AMDA.ipynb'.
Restored as a separate apt step on the coverage runner.
The doctest step's examples reference all data providers (cdpp3dview
included) and live inventories. The job-level
SPEASY_CORE_DISABLED_PROVIDERS='cdpp3dview' makes the inventory tree's
cdpp3dview attribute missing during doctest, surfacing as
'types.SimpleNamespace object has no attribute cdpp3dview' and a chain
of NameErrors for variables defined in earlier doctest blocks.

Original tests.yml overrode SPEASY_CORE_DISABLED_PROVIDERS="" on the
combined pytest+doctest step, plus set HTTP_REWRITE_RULES (re-routes
the placeholder URL used in some examples to LPP's mirror) and
USER_AGENT. My PR 2 rewrite dropped the env block; restoring it on
the doctest step.
Pandas now prints its public name in type() repr ('pandas.DataFrame')
rather than the internal module path ('pandas.core.frame.DataFrame').
The user/numpy.rst doctest was written against the old form.
Surfaced now that uv.lock pins a recent pandas; pip-installed envs
were getting older pandas where the old form still applied.
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
9 Security Hotspots
E Security Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

if any("import pytest" in ln for ln in lines):
block = [f"\n{MARKER_LINE_PREFIX}{tier}\n", "\n"]
lines[insert_at:insert_at] = block
path.write_text("".join(lines))
from __future__ import annotations

import unittest
from datetime import datetime
@codecov
Copy link
Copy Markdown

codecov Bot commented May 15, 2026

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.68%. Comparing base (93ce7a0) to head (c7b141c).
⚠️ Report is 44 commits behind head on main.

Files with missing lines Patch % Lines
speasy/__init__.py 60.00% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (93ce7a0) and HEAD (c7b141c). Click for more details.

HEAD has 3 uploads less than BASE
Flag BASE (93ce7a0) HEAD (c7b141c)
unittests 3 0
Additional details and impacted files
@@             Coverage Diff             @@
##             main     #301       +/-   ##
===========================================
- Coverage   85.10%   74.68%   -10.42%     
===========================================
  Files          69       82       +13     
  Lines        4834     5096      +262     
  Branches      668      693       +25     
===========================================
- Hits         4114     3806      -308     
- Misses        479     1049      +570     
  Partials      241      241               
Flag Coverage Δ
unit 74.68% <77.77%> (?)
unittests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

2 participants