Skip to content

📦 Split heavy deps into optional extras and slim the wheel#11

Merged
dariocazzani merged 1 commit into
mainfrom
feat/dep-split-minimal-install
May 3, 2026
Merged

📦 Split heavy deps into optional extras and slim the wheel#11
dariocazzani merged 1 commit into
mainfrom
feat/dep-split-minimal-install

Conversation

@dariocazzani

Copy link
Copy Markdown
Contributor

What does this PR do?

Ships the correct minimal dependency set for pip install devol. Before this PR, installing the library pulled in torch, torchvision, gymnasium, and matplotlib — hundreds of MB — even though the runtime code in src/devol/ never imports any of them. After this PR the base install is just numpy, pydantic, and pydantic-yaml; the heavy stack moves under the examples extra where the cartpole/MNIST/two-peaks demos actually use it.

Details

Required dependencies reduced to 3 packages

  • numpy>=1.26, pydantic>=2.0, pydantic-yaml>=1.6
  • Dropped unused pydantic-settings (leftover import from an abandoned cleanup branch, never referenced in code)

Extras restructured

  • examplesmatplotlib, gymnasium[classic-control], torch, torchvision
  • benchmarkmatplotlib, rich, tqdm
  • devruff, mypy, pytest, twine (added twine so the build CI job can validate metadata without an ad-hoc install)
  • all — meta-extra that resolves to devol[dev,examples,benchmark]

Wheel narrowed to src/devol/ only

  • examples/ was previously shipped inside the wheel even though it's demo code; now it stays in the repo but out of the package
  • Verified: fresh devol-0.1.0-py3-none-any.whl contains 9 files under devol/ + metadata — no examples, no benchmark, no tests

Pytest pythonpath config

  • tests/test_ci_n_peaks.py imports from tests.ci.n_peaks. With examples/ previously shipped as a top-level wheel package, the editable install accidentally exposed the repo root on sys.path, which is where pytest found the tests namespace. After narrowing the wheel, that side effect is gone, so pytest gets an explicit pythonpath = ["."] and testpaths = ["tests"] config.

README and CHANGELOG

Verification

Minimal install (no extras) runs the algorithm end-to-end:

uv sync --no-dev --no-extra dev --no-extra examples --no-extra benchmark --no-extra all
python -c "from devol import DiffusionEvolution, DiffusionConfig; import numpy as np; \
  algo = DiffusionEvolution(DiffusionConfig(population_size=32, num_steps=10, param_dim=4, sigma_m=0.5, seed=42), \
                             lambda x: float(-np.sum(x**2))); \
  algo.run(); print('best:', algo.get_best_individual()[1])"
# → best: -0.1714

python -c "import torch"
# → ModuleNotFoundError: No module named 'torch'   ✓

All CI gates green locally:

  • uv run ruff check
  • uv run ruff format --check
  • uv run mypy src/devol
  • uv run pytest ✓ (15 passed)
  • uv build + twine check dist/*

The core devol package only uses numpy, pydantic, and pydantic-yaml, but
the shipped dependency list forced every user to install torch,
torchvision, gymnasium, and matplotlib — a ~2 GB footprint for a library
whose runtime doesn't touch any of them.

- Required deps reduced to numpy, pydantic, pydantic-yaml
- Drop unused pydantic-settings (leftover from an abandoned branch)
- Move torch, torchvision, gymnasium[classic-control], matplotlib into
  the examples extra (where cartpole/mnist/live-two-peaks actually use
  them)
- Add twine to the dev extra so the build CI job works from a sync
- Add an `all` meta-extra that pulls dev + examples + benchmark
- Narrow the wheel target to src/devol so examples/ and benchmark/
  ship only in the repo, not in the pip install
- Add pytest pythonpath config — narrowing the wheel removed the
  accidental side-effect that let `tests.ci.n_peaks` resolve via
  editable install, so configure it explicitly
- Update README with an Installation section covering the extras
- Update CHANGELOG with the dependency changes, the wheel narrowing,
  and the earlier CI/typing work from PR #10
@dariocazzani dariocazzani merged commit 362fe85 into main May 3, 2026
6 checks passed
@dariocazzani dariocazzani deleted the feat/dep-split-minimal-install branch May 3, 2026 18:05
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