Skip to content

Commit 15a7c40

Browse files
committed
Update project configuration
* move dependency management to uv * move (most) config info to pyproject.toml * bump minimum supported Python version * bump development status metadata * update github workflows * remove requirements files * update dev docs re: uv
1 parent 4bc3f95 commit 15a7c40

22 files changed

+3243
-541
lines changed

.github/workflows/dev.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ jobs:
2929

3030
- name: install developer dependencies
3131
run: |
32+
# NOTE: production use of this command
33+
# would be python -m pip ...
3234
pip install --upgrade pip
33-
pip install -r requirements.txt
35+
pip install -e . --group test --group lint --group docs

.github/workflows/docs.yaml

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,19 @@ jobs:
2222
with:
2323
python-version: "3.12"
2424

25-
- name: Install dependencies
26-
run: |
27-
pip install --upgrade pip
28-
pip install -r requirements_minimal_CI.txt
29-
pip install -r requirements_docs_CI.txt
30-
python -m pip install build packaging
25+
- name: Install the latest version of uv
26+
uses: astral-sh/setup-uv@v7
27+
with:
28+
activate-environment: true
29+
version: "latest"
30+
python-version: ${{ matrix.python }}
3131

32-
- name: Build package
32+
- name: Install python dependencies
3333
run: |
34-
# Generate the version string which appears in the docs.
35-
python -m build --sdist
34+
# uv sync install the project into the venv
35+
# NOTE: we do not specify -p here, so
36+
# we rely on python-version above
37+
uv sync --frozen --group docs
3638
3739
- name: Build Docs
3840
run: |

.github/workflows/lint.yaml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,17 @@ jobs:
1515
with:
1616
python-version: "3.12"
1717

18-
- name: Install dependencies
18+
- name: Install the latest version of uv
19+
uses: astral-sh/setup-uv@v7
20+
with:
21+
activate-environment: true
22+
version: "latest"
23+
python-version: ${{ matrix.python }}
24+
25+
- name: Install python dependencies
1926
run: |
20-
pip install -r requirements_minimal_CI.txt
21-
pip install -r requirements_lint_CI.txt
22-
# Mypy also checks types in the tests/ folder
23-
pip install -r requirements_tests_CI.txt
24-
pip install build
25-
python -m build .
27+
# uv sync install the project into the venv
28+
uv sync --frozen --group lint
2629
2730
- name: black
2831
run: black --check .

.github/workflows/tests.yaml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,23 @@ jobs:
4141
with:
4242
python-version: ${{ matrix.python-version }}
4343

44-
- name: install dependencies
45-
run: |
46-
pip install -r requirements_minimal_CI.txt
47-
pip install -r requirements_tests_CI.txt
44+
- name: Install the latest version of uv
45+
uses: astral-sh/setup-uv@v7
46+
with:
47+
activate-environment: true
48+
version: "latest"
49+
python-version: ${{ matrix.python }}
4850

49-
# Check that demes installs as expected.
50-
# Also check the "demes" CLI entry point.
51-
- name: install demes
51+
- name: Install python dependencies
5252
run: |
53-
pip install .
54-
demes -h
53+
# uv sync install the project into the venv
54+
# and the -p installs the correct Python
55+
# version if it is not the version in $PATH
56+
uv sync -p ${{ matrix.python-version }} --frozen --group test
5557
5658
- name: run pytest
5759
run: |
58-
python -m pytest -n auto \
60+
uv run -m pytest -n auto \
5961
--cov=demes --cov-report=term-missing --cov-report=xml -v tests
6062
6163
- name: upload coverage report to codecov

.github/workflows/wheel.yaml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ on:
44
push:
55
tags:
66
- '*'
7+
pull_request:
8+
branches: [ main ]
79
release:
810
types: [published]
911

@@ -16,16 +18,18 @@ jobs:
1618
with:
1719
python-version: "3.12"
1820

19-
- name: install dependencies
20-
run: |
21-
pip install -r requirements_minimal_CI.txt
22-
pip install build
21+
- name: Install the latest version of uv
22+
uses: astral-sh/setup-uv@v7
23+
with:
24+
activate-environment: true
25+
version: "latest"
26+
python-version: ${{ matrix.python }}
2327

2428
- name: build wheel
25-
run: python -m build
29+
run: uv build
2630

2731
- name: upload wheel
28-
uses: actions/upload-artifact@v3
32+
uses: actions/upload-artifact@v5
2933
with:
3034
name: wheel-and-sdist
3135
path: dist/
@@ -40,11 +44,11 @@ jobs:
4044
fail-fast: false
4145
matrix:
4246
os: [ubuntu-latest, windows-latest, macos-latest]
43-
python-version: [3.7, 3.8, 3.9, "3.10"]
47+
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
4448

4549
steps:
4650
- name: download wheel
47-
uses: actions/download-artifact@v4
51+
uses: actions/download-artifact@v6.0.0
4852
with:
4953
name: wheel-and-sdist
5054
path: dist/
@@ -71,7 +75,7 @@ jobs:
7175
needs: ['wheel_test']
7276
steps:
7377
- name: download wheel
74-
uses: actions/download-artifact@v4
78+
uses: actions/download-artifact@v6.0.0
7579
with:
7680
name: wheel-and-sdist
7781
path: dist/

demes/demes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,9 +1349,7 @@ class Graph:
13491349
)
13501350
metadata: collections.abc.Mapping = attr.ib(
13511351
factory=dict,
1352-
validator=attr.validators.instance_of(
1353-
collections.abc.Mapping # type: ignore[type-abstract]
1354-
),
1352+
validator=attr.validators.instance_of(collections.abc.Mapping),
13551353
)
13561354
demes: List[Deme] = attr.ib(factory=list, init=False)
13571355
migrations: List[AsymmetricMigration] = attr.ib(factory=list, init=False)

docs/development.md

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,37 +11,71 @@ of "pull requests" against our
1111
`Demes` aims to have minimal dependencies when used as a library by other
1212
projects. However, additional dependencies are required during development, as
1313
developers regularly run the test suite, build the documentation, and assess
14-
whether their code changes conform to style guidelines. The `requirements.txt`
14+
whether their code changes conform to style guidelines. The `pyproject.toml`
1515
file in the top-level folder lists all development dependencies, which can
16-
be installed using `pip`. In the following documentation, we assume the reader
16+
be installed using `uv`.
17+
In the following documentation, we assume the reader
1718
has cloned the source repository and installed the developer requirements as
1819
follows.
1920

21+
To install `uv`, take one of the following paths:
22+
23+
* Follow that project's [documentation](https://docs.astral.sh/uv/).
24+
* Use the package manager of your choice on your operating system.
25+
26+
Then:
27+
2028
```sh
2129
# Clone the repository.
2230
git clone https://github.com/popsim-consortium/demes-python.git
2331
cd demes-python
24-
# Create a virtual environment for development.
25-
python -m venv venv
26-
# Activate the environment.
27-
source venv/bin/activate
28-
# Install the developer dependencies.
29-
pip install -r requirements.txt
30-
# Generate the version string from the most recent git tag/commit.
31-
python setup.py build
32+
# update the demes-spec submodule
33+
git submodule update --init
34+
# Use uv to install dependencies and build the demes package:
35+
uv sync --all-groups
3236
```
3337

34-
```{warning}
35-
Due to conflicting version dependencies, it may not be possible to install
36-
all developer requirements on older versions of Python. If you experience
37-
problems, please install the latest Python version (3.10 at time of writing).
38+
You may now do things like run the test suite:
39+
40+
```sh
41+
uv run python -m pytest tests
3842
```
3943

44+
The `--all-groups` flag will install all build dependencies,
45+
runtime dependencies, and developer dependencies listed in
46+
`dependency-groups` in `pyproject.toml`.
47+
If you want to only install specific dependency groups, do
48+
so following the `uv` [documentation](https://docs.astral.sh/uv/).
49+
4050
```{note}
41-
Non-developer requirements are listed in the `install_requires` section
42-
of the ``setup.cfg`` file in the top-level folder of the sources.
51+
Non-developer requirements are listed in the `dependency-groups` section
52+
of the ``pyproject.toml`` file in the top-level folder of the sources.
53+
```
54+
55+
## Updating `uv.lock` ("dependency management")
56+
57+
If any of the following occur in `pyproject.toml`, then the contents of `uv.lock`
58+
may no longer by valid:
59+
60+
* Changing a dependency version number pin
61+
* Adding/removing a dependency
62+
* Changing the supported range of Python versions
63+
* Changing the set of supported operating systems / platforms.
64+
65+
To rebuild the lock file:
66+
67+
```sh
68+
uv lock
4369
```
4470

71+
Then, commit the new lock file!
72+
73+
### Updating individual packages in `uv.lock`
74+
75+
One may occastionally need to update the locked version of a specific dependency.
76+
Currently, this happens via arguments to `uv lock`.
77+
Counsult the `uv` [documentation](https://docs.astral.sh/uv/) for details.
78+
4579
## Continuous integration (CI)
4680

4781
After a pull request is submitted, an automated process known as
@@ -107,6 +141,12 @@ manually from the top-level folder of the sources.
107141
python -m pytest -v tests --cov=demes --cov-report=term-missing
108142
```
109143

144+
or
145+
146+
```sh
147+
uv run python -m pytest -v tests --cov=demes --cov-report=term-missing
148+
```
149+
110150
This will produce lots of output, indicating which tests passed, and which
111151
failed (if any). There may also be warnings. Any warnings that are triggered
112152
by code in `demes` (rather than third-party libraries), should be fixed.

pyproject.toml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,76 @@
11
[build-system]
22
# We need setup.cfg support, which setuptools introduced in 30.3.0.
33
requires = ["setuptools>=30.3.0", "wheel", "setuptools_scm"]
4+
5+
[project]
6+
name = "demes"
7+
authors = [
8+
{name = "PopSim Consortium", email = "krthornt@uci.edu"}
9+
]
10+
description = "tools for describing demographic models"
11+
readme = {file = "README.md", content-type = "text/markdown"}
12+
license = {text = "ISC"}
13+
classifiers = [
14+
"Development Status :: 5 - Stable",
15+
"License :: OSI Approved :: ISC License (ISCL)",
16+
"Operating System :: OS Independent",
17+
"Intended Audience :: Science/Research",
18+
"Programming Language :: Python :: 3",
19+
"Topic :: Scientific/Engineering",
20+
"Topic :: Scientific/Engineering :: Bio-Informatics"
21+
]
22+
23+
requires-python = ">=3.10"
24+
25+
dynamic = ["version"]
26+
27+
dependencies = [
28+
"attrs>=20.3.0",
29+
"ruamel.yaml>=0.15.78"
30+
]
31+
32+
[project.urls]
33+
Repository = "https://github.com/popsim-consortium/demes-python"
34+
Documentation = "https://popsim-consortium.github.io/demes-docs/"
35+
Issues = "https://github.com/popsim-consortium/demes-python/issues"
36+
37+
[project.scripts]
38+
demes = "demes.__main__:cli"
39+
40+
[dependency-groups]
41+
test = [
42+
"numpy",
43+
"pytest==8.3.3",
44+
"pytest-cov",
45+
"pytest-xdist"
46+
]
47+
48+
lint = [
49+
"black==24.10.0",
50+
"flake8==7.1.1",
51+
"mypy==1.13.0",
52+
{include-group = "test"},
53+
]
54+
55+
docs = [
56+
"demesdraw",
57+
"jupyter-book==0.15.1",
58+
"piccolo_theme",
59+
"sphinx_issues",
60+
"sphinxcontrib-programoutput",
61+
# Below here are hacks to make the docs
62+
# build until we can deal w/updating
63+
# jupyter-book
64+
"ipython==8.29.0"
65+
]
66+
67+
[tool.setuptools_scm]
68+
write_to = "demes/_version.py"
69+
70+
# NOTE to future developers
71+
# mypy can be configured here, and perhaps
72+
# "should" be.
73+
# For now, we've left its config in setup.cfg
74+
#
75+
# flake8 cannot be configured here unless we
76+
# introduce a dependency on flake8-pyproject.

requirements.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

requirements/docs.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)