Skip to content

build: migrate to uv, add ruff/ty, format all files#95

Open
FIrgolitsch wants to merge 21 commits intomainfrom
pr-a-build-tooling
Open

build: migrate to uv, add ruff/ty, format all files#95
FIrgolitsch wants to merge 21 commits intomainfrom
pr-a-build-tooling

Conversation

@FIrgolitsch
Copy link
Copy Markdown
Contributor

@FIrgolitsch FIrgolitsch commented Apr 1, 2026

PR #95 — Build Tooling & Formatting

Migrates the build system to modern Python tooling and applies consistent formatting across the codebase. Prerequisite for all other stacked PRs (#87, #96#104).

Build system: setup.py → uv + pyproject.toml

  • Full pyproject.toml: project metadata, core deps, optional extras (gpu, gpu-cuda12, gpu-cuda13, docs, dev), entries in [project.scripts]
  • uv.lock for reproducible resolution
  • Remove setup.py, requirements.txt, requirements-pytest.txt
  • Dockerfile updated to use uv

Lint & format: ruff + ty

  • [tool.ruff] — target py312, line-length 127, rules E/F/W/I/UP/B/RUF/SIM/C4/PIE/PTH
  • [tool.ruff.lint.isort]_thread_config in its own section (must import before numpy/jax to set thread caps)
  • [tool.ty] — linumpy-only, py312, cupy/cupyx/numba → Any, relaxed overrides for tests and GPU modules
  • .pre-commit-config.yaml — ruff-format, ruff lint (--fix), ty (advisory / non-blocking)
  • ruff format applied to all Python files; ruff check --fix applied (import ordering, f-strings, type upgrades, PTH replacements where safe)

CI & Docker

  • .github/workflows/python-app.ymlastral-sh/setup-uv@v5, uv sync, uv run ruff, uv run ty, uv run pytest
  • Dockerfile switched from pip to uv

Other

  • linumpy/py.typed marker
  • .gitignore additions for uv / ty caches and local benchmark outputs

Commits

  1. build: migrate to uv, add ruff/ty, format all files
  2. build: expand ruff rules, refresh uv.lock, add ty pre-commit — enables PTH/SIM/C4/PIE, refreshes uv.lock, wires ty into pre-commit as advisory

Notes

  • Some pre-existing lint warnings remain (a few PTH/SIM/E501) — will be mopped up in the dependent PRs as they touch those files
  • [project.scripts] here only contains scripts present at the branch point; each stacked PR adds its own entries

Copy link
Copy Markdown
Contributor

@CHrlS98 CHrlS98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it as mostly formatting but I still went through all the files. It has been a good opportunity to get back into the code. I have a few comments of course. Hopefully there are not too many other 125 files PR 🥲

Comment thread linumpy/io/__init__.py
Comment thread linumpy/io/data_io.py Outdated
Comment thread linumpy/io/npz.py Outdated
Comment thread linumpy/io/npz.py Outdated
Comment thread linumpy/microscope/oct.py
Comment thread scripts/linum_detect_rehoming.py
Comment thread scripts/linum_resample_nifti.py Outdated
Comment thread scripts/linum_stack_slices.py
Comment thread linumpy/imaging/transform.py
Comment thread linumpy/mosaic/quick_stitch.py
Relocates thread-pool configuration into a dedicated config sub-package.
- Remove dead modules data_io.py and npz.py (unused).
- Move Allen brain atlas helpers from io/allen.py into a new
  linumpy.reference sub-package.
- Drop star imports from io/__init__.py.
- Modernize remaining io/ modules (Path, type hints, docstrings).
- Move utils/io.py argparse helpers to a new linumpy.cli.args module.
- Move utils/metrics.py into a top-level linumpy.metrics package.
- Remove now-empty linumpy.utils package.
…in.py

Promotes the single-file linumpy.segmentation module into a package
with a dedicated brain.py module for clarity and future extension.
- imaging/transform.py: image transformation helpers.
- imaging/overlay.py: overlay/composite helpers.
…osaic.quick_stitch

- mosaic/discovery.py: tile-discovery helpers.
- mosaic/quick_stitch.py: quick low-resolution stitching helpers.
- mosaic/grid.py:    grid construction (from stitching/mosaic_grid.py).
- mosaic/overlap.py: tile overlap helpers (extracted from stitching).
- registration/manual.py:           interactive registration GUI
                                    (from stitching/manual_registration.py).
- registration/sitk.py:             SimpleITK-based registration
                                    (from stitching/registration.py).
- registration/phase_correlation.py: phase-correlation registration.
- registration/refinement.py:       multi-stage refinement helpers.
- registration/transforms.py:       affine/rigid transform utilities.
- Drop dead modules stitching/FileUtils.py, stitching/topology.py,
  stitching/stitch_utils.py.
…ckage

Splits the 1786-line linumpy/preproc/icorr.py module into focused modules:

- intensity/normalize.py:   intensity normalization helpers.
- intensity/attenuation.py: attenuation correction.
- intensity/psf_model.py:   PSF-model-based illumination correction.
- intensity/vignette.py:    vignetting correction.
- intensity/artifact.py:    artifact removal helpers.
- intensity/convert.py:     intensity conversion helpers.
…ckage

Splits xyzcorr.py into focused modules:

- geometry/crop.py:      volume cropping helpers.
- geometry/resample.py:  resampling utilities.
- geometry/interface.py: tissue-interface detection and fitting.
- geometry/galvo.py:     galvo / scanner geometry helpers.

Repoints linumpy.microscope.oct to use the new geometry.galvo module.
…it utils.py

- stack_alignment/io.py:     I/O helpers (CSV/JSON read/write).
- stack_alignment/units.py:  unit conversion helpers.
- stack_alignment/filter.py: outlier filtering helpers.

Renames the corresponding test module from test_utils_shifts.py to
test_stack_alignment.py.
- psf/synthetic.py: synthesize_3d_psf helper (renamed from get_3d_psf
  for clarity).
- psf/extract.py:   extract experimental PSFs from data.
Updates all 43 linum_*.py scripts plus 2 script tests to use the
new sub-packages introduced in this refactor:

  linumpy.preproc.icorr    -> linumpy.intensity.{normalize,attenuation,
                                                 psf_model,vignette,
                                                 artifact,convert}
  linumpy.preproc.xyzcorr  -> linumpy.geometry.{crop,resample,
                                                interface,galvo}
  linumpy.shifts.utils     -> linumpy.stack_alignment.{io,units,filter}
  linumpy.psf.psf_estimator -> linumpy.psf.{synthetic,extract}
  linumpy.stitching        -> linumpy.mosaic.{grid,overlap,discovery,
                                              quick_stitch} and
                              linumpy.registration.{manual,sitk,
                                                    phase_correlation,
                                                    refinement,transforms}
  linumpy.utils_images     -> linumpy.imaging.{transform,overlay}
  linumpy.utils.io         -> linumpy.cli.args
  linumpy.utils.metrics    -> linumpy.metrics
  linumpy.io.allen         -> linumpy.reference.allen
  linumpy.segmentation     -> linumpy.segmentation.brain
  linumpy.reconstruction   -> linumpy.mosaic.{discovery,quick_stitch}
  linumpy._thread_config   -> linumpy.config.threads
- Update setuptools `packages.find` and ruff `per-file-ignores` to
  reflect the renamed/split modules (intensity/, geometry/, mosaic/,
  registration/, stack_alignment/, etc.).
- Update isort `thread-config` section to reference
  linumpy.config.threads.
- Refresh uv.lock to pick up incidental dependency updates.
- Pre-existing tooling tweaks (expanded ruff rule set, ty config,
  GPU dependency cleanup) carried in the working tree.
Refreshes all transitive package versions to current resolutions
(idna, magicgui, ome-zarr, pre-commit, pydantic, pytest, ruff, ty,
typer, virtualenv, etc.).
Removed pins on numpy, scipy, hyperactive, pynrrd, and numcodecs.
basicpy 2.0.0 (latest available) transitively pins scipy<1.13, which
forces numpy<2; override that ceiling via [tool.uv].override-dependencies
so we resolve modern numpy 2.x and scipy 1.17 across the stack.
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