Skip to content

Commit 59f4452

Browse files
Qazalbashnstarman
andauthored
CI(gh-2126): transition to uv for dependency management and testing (#2129)
* CI(gh-2126): transition to uv for dependency management and testing * fix: install packages in system * fix: update path * fix: specify uv python version in enviornment variable * chore: `setup.py` -> `pyproject.toml` Co-authored-by: nstarman <nstarman@users.noreply.github.com> * Revert "chore: `setup.py` -> `pyproject.toml`" This reverts commit c3ce49f. * chore: remove `UV_PYTHON` from env variable * chore: explicit python installation * fix: remove `--system` flag * fix: avoid installing pyro-api pyro-ppl/pyro-api#26 * fix: sync enviorment * chore: update logic for code coverage * fix: remove run from coverage * fix: remove run from coverage * ci: fix coveralls integration and coverage reporting - Add --cov-report=lcov to pytest commands for Coveralls compatibility. - Use --cov-append to aggregate coverage results across multiple test runs within jobs. - Explicitly point the Coveralls action to the generated LCOV files. - Synchronize the finish job condition with parallel test jobs. * fix: using uv to create env for readthedocs reference: https://docs.readthedocs.com/platform/stable/build-customization.html#install-dependencies-with-uv * fix: pinning jax version until #2154 is resolved * chore: use env variable for pytest flags * Revert "fix: pinning jax version until #2154 is resolved" This reverts commit 7202cc4. --------- Co-authored-by: nstarman <nstarman@users.noreply.github.com>
1 parent d1670c9 commit 59f4452

5 files changed

Lines changed: 125 additions & 126 deletions

File tree

.github/workflows/ci.yml

Lines changed: 83 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -9,203 +9,207 @@ on:
99
branches: [master]
1010

1111
env:
12-
PYTEST_ADDOPTS: "--cov=numpyro --cov-append"
12+
PYTEST_ADDOPTS: "--cov=numpyro --cov-append --cov-report=lcov"
1313

1414
jobs:
1515
prek:
16-
1716
runs-on: ubuntu-latest
18-
1917
steps:
20-
- uses: actions/checkout@v2
18+
- uses: actions/checkout@v6
2119
- name: prek check
2220
uses: j178/prek-action@v1
2321
with:
2422
extra-args: --all-files --skip ruff --skip ruff-format --skip ty --skip mypy
2523

26-
2724
lint:
28-
2925
runs-on: ubuntu-latest
3026
strategy:
3127
matrix:
3228
python-version: ["3.11", "3.13"]
3329

3430
steps:
35-
- uses: actions/checkout@v2
36-
- name: Set up Python ${{ matrix.python-version }}
37-
uses: actions/setup-python@v2
31+
- uses: actions/checkout@v6
32+
- name: Install uv
33+
uses: astral-sh/setup-uv@v7
3834
with:
35+
enable-cache: true
3936
python-version: ${{ matrix.python-version }}
4037
- name: Install dependencies
4138
run: |
4239
sudo apt install -y pandoc gsfonts
43-
python -m pip install --upgrade pip
44-
pip install jaxlib
45-
pip install jax
46-
pip install '.[doc,test]'
47-
pip install https://github.com/pyro-ppl/funsor/archive/master.zip
48-
pip install -r docs/requirements.txt
49-
pip freeze
40+
uv sync \
41+
--upgrade \
42+
--extra cpu \
43+
--group ci \
44+
--group docs \
45+
--group test
46+
uv pip freeze
5047
- name: Lint with mypy and ruff
5148
run: |
52-
make lint
49+
uv run make lint
5350
- name: Build documentation
5451
run: |
55-
make docs
52+
uv run make docs
5653
- name: Test documentation
5754
run: |
58-
make doctest
59-
python -m doctest -v README.md
60-
55+
uv run make doctest
56+
uv run python -m doctest -v README.md
6157
6258
test-modeling:
63-
6459
runs-on: ubuntu-latest
6560
needs: [lint, prek]
6661
strategy:
6762
matrix:
6863
python-version: ["3.11", "3.13"]
64+
env:
65+
UV_PYTHON: ${{ matrix.python-version }}
6966

7067
steps:
71-
- uses: actions/checkout@v2
72-
- name: Set up Python ${{ matrix.python-version }}
73-
uses: actions/setup-python@v2
68+
- uses: actions/checkout@v6
69+
- name: Install uv
70+
uses: astral-sh/setup-uv@v7
7471
with:
72+
enable-cache: true
7573
python-version: ${{ matrix.python-version }}
7674
- name: Install dependencies
7775
run: |
7876
sudo apt install -y graphviz
79-
python -m pip install --upgrade pip
80-
# Keep track of pyro-api master branch
81-
pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip
82-
pip install jaxlib
83-
pip install jax
84-
pip install https://github.com/pyro-ppl/funsor/archive/master.zip
85-
pip install -e '.[dev,test]'
86-
pip freeze
77+
uv sync \
78+
--upgrade \
79+
--extra cpu \
80+
--group ci \
81+
--group dev \
82+
--group test
83+
uv pip freeze
8784
- name: Test with pytest
8885
run: |
89-
CI=1 pytest -vs -k "not test_example" --durations=100 --ignore=test/infer/ --ignore=test/contrib/
86+
CI=1 uv run pytest -vs -k "not test_example" --durations=100 --ignore=test/infer/ --ignore=test/contrib/
9087
- name: Test x64
9188
run: |
92-
JAX_ENABLE_X64=1 pytest -vs test/test_distributions.py -k "powerLaw or Dagum"
89+
JAX_ENABLE_X64=1 uv run pytest -vs test/test_distributions.py -k "powerLaw or Dagum"
9390
- name: Test tracer leak
9491
if: matrix.python-version == '3.13'
9592
env:
9693
JAX_CHECK_TRACER_LEAKS: 1
9794
run: |
98-
pytest -vs test/infer/test_mcmc.py::test_chain_inside_jit
99-
pytest -vs test/infer/test_mcmc.py::test_chain_jit_args_smoke
100-
pytest -vs test/infer/test_mcmc.py::test_reuse_mcmc_run
101-
pytest -vs test/infer/test_mcmc.py::test_model_with_multiple_exec_paths
102-
pytest -vs test/test_distributions.py::test_mean_var -k Gompertz
103-
95+
uv run pytest -vs \
96+
test/infer/test_mcmc.py::test_chain_inside_jit \
97+
test/infer/test_mcmc.py::test_chain_jit_args_smoke \
98+
test/infer/test_mcmc.py::test_model_with_multiple_exec_paths \
99+
test/infer/test_mcmc.py::test_reuse_mcmc_run
100+
uv run pytest -vs test/test_distributions.py::test_mean_var -k Gompertz
104101
- name: Coveralls
105102
if: github.repository == 'pyro-ppl/numpyro' && matrix.python-version == '3.13'
106103
uses: coverallsapp/github-action@v2
107104
with:
108105
github-token: ${{ secrets.GITHUB_TOKEN }}
109106
parallel: true
110107
flag-name: test-modeling
111-
108+
file: coverage.lcov
112109

113110
test-inference:
114-
115111
runs-on: ubuntu-latest
116112
needs: [lint, prek]
117113
strategy:
118114
matrix:
119115
python-version: ["3.11", "3.13"]
116+
env:
117+
UV_PYTHON: ${{ matrix.python-version }}
120118

121119
steps:
122-
- uses: actions/checkout@v2
123-
- name: Set up Python ${{ matrix.python-version }}
124-
uses: actions/setup-python@v2
120+
- uses: actions/checkout@v6
121+
- name: Install uv
122+
uses: astral-sh/setup-uv@v7
125123
with:
124+
enable-cache: true
126125
python-version: ${{ matrix.python-version }}
126+
- name: Set up Python ${{ matrix.python-version }}
127+
run: uv python install ${{ matrix.python-version }}
127128
- name: Install dependencies
128129
run: |
129-
python -m pip install --upgrade pip
130-
# Keep track of pyro-api master branch
131-
pip install https://github.com/pyro-ppl/pyro-api/archive/master.zip
132-
pip install jaxlib
133-
pip install jax
134-
pip install https://github.com/pyro-ppl/funsor/archive/master.zip
135-
pip install -e '.[dev,test]'
136-
pip freeze
130+
uv sync \
131+
--upgrade \
132+
--extra cpu \
133+
--group ci \
134+
--group dev \
135+
--group test
136+
uv pip freeze
137137
- name: Test with pytest
138138
run: |
139-
pytest -vs --durations=20 test/infer/test_mcmc.py
140-
pytest -vs --durations=20 test/infer --ignore=test/infer/test_mcmc.py --ignore=test/contrib/test_nested_sampling.py
141-
pytest -vs --durations=20 test/contrib --ignore=test/contrib/stochastic_support/test_dcc.py
139+
uv run pytest -vs --durations=20 test/contrib --ignore=test/contrib/stochastic_support/test_dcc.py
140+
uv run pytest -vs --durations=20 test/infer --ignore=test/infer/test_mcmc.py --ignore=test/contrib/test_nested_sampling.py
141+
uv run pytest -vs --durations=20 test/infer/test_mcmc.py
142142
- name: Test x64
143143
run: |
144-
JAX_ENABLE_X64=1 pytest -vs test/infer/test_mcmc.py -k x64
144+
JAX_ENABLE_X64=1 uv run pytest -vs test/infer/test_mcmc.py -k x64
145145
- name: Test chains
146146
run: |
147-
XLA_FLAGS="--xla_force_host_platform_device_count=2" pytest -vs test/infer/test_mcmc.py -k "chain or pmap or vmap"
148-
XLA_FLAGS="--xla_force_host_platform_device_count=2" pytest -vs test/contrib/test_tfp.py -k "chain"
149-
XLA_FLAGS="--xla_force_host_platform_device_count=2" pytest -vs test/contrib/stochastic_support/test_dcc.py
150-
XLA_FLAGS="--xla_force_host_platform_device_count=2" pytest -vs test/infer/test_hmc_gibbs.py -k "chain"
147+
XLA_FLAGS="--xla_force_host_platform_device_count=2" uv run pytest -vs test/contrib/stochastic_support/test_dcc.py
148+
XLA_FLAGS="--xla_force_host_platform_device_count=2" uv run pytest -vs test/contrib/test_tfp.py -k "chain"
149+
XLA_FLAGS="--xla_force_host_platform_device_count=2" uv run pytest -vs test/infer/test_hmc_gibbs.py -k "chain"
150+
XLA_FLAGS="--xla_force_host_platform_device_count=2" uv run pytest -vs test/infer/test_mcmc.py -k "chain or pmap or vmap"
151151
- name: Test custom prng
152152
run: |
153-
JAX_ENABLE_CUSTOM_PRNG=1 pytest -vs test/infer/test_mcmc.py
153+
JAX_ENABLE_CUSTOM_PRNG=1 uv run pytest -vs test/infer/test_mcmc.py
154154
- name: Test nested sampling
155155
run: |
156-
JAX_ENABLE_X64=1 pytest -vs test/contrib/test_nested_sampling.py
156+
JAX_ENABLE_X64=1 uv run pytest -vs test/contrib/test_nested_sampling.py
157157
- name: Coveralls
158158
if: github.repository == 'pyro-ppl/numpyro' && matrix.python-version == '3.13'
159159
uses: coverallsapp/github-action@v2
160160
with:
161161
github-token: ${{ secrets.GITHUB_TOKEN }}
162162
parallel: true
163163
flag-name: test-inference
164-
164+
file: coverage.lcov
165165

166166
examples:
167-
168167
runs-on: ubuntu-latest
169168
needs: [lint, prek]
170169
strategy:
171170
matrix:
172171
python-version: ["3.13"]
172+
env:
173+
UV_PYTHON: ${{ matrix.python-version }}
173174

174175
steps:
175-
- uses: actions/checkout@v2
176-
- name: Set up Python ${{ matrix.python-version }}
177-
uses: actions/setup-python@v2
176+
- uses: actions/checkout@v6
177+
- name: Install uv
178+
uses: astral-sh/setup-uv@v7
178179
with:
180+
enable-cache: true
181+
update-path: true
179182
python-version: ${{ matrix.python-version }}
180183
- name: Install dependencies
181184
run: |
182-
python -m pip install --upgrade pip
183-
pip install jaxlib
184-
pip install jax
185-
pip install https://github.com/pyro-ppl/funsor/archive/master.zip
186-
pip install -e '.[dev,examples,test]'
187-
pip freeze
185+
uv sync \
186+
--upgrade \
187+
--extra cpu \
188+
--group ci \
189+
--group dev \
190+
--group examples \
191+
--group test
192+
uv pip freeze
188193
- name: Test with pytest
189194
run: |
190-
CI=1 XLA_FLAGS="--xla_force_host_platform_device_count=2" pytest -vs -k test_example
195+
CI=1 XLA_FLAGS="--xla_force_host_platform_device_count=2" uv run pytest -vs -k test_example
191196
- name: Coveralls
192197
if: github.repository == 'pyro-ppl/numpyro' && matrix.python-version == '3.13'
193198
uses: coverallsapp/github-action@v2
194199
with:
195200
github-token: ${{ secrets.GITHUB_TOKEN }}
196201
parallel: true
197202
flag-name: examples
198-
203+
file: coverage.lcov
199204

200205
finish:
201-
202206
needs: [test-modeling, test-inference, examples]
203207
runs-on: ubuntu-latest
208+
if: github.repository == 'pyro-ppl/numpyro'
204209
steps:
205210
- name: Coveralls finished
206211
uses: coverallsapp/github-action@v2
207212
with:
208213
github-token: ${{ secrets.GITHUB_TOKEN }}
209214
parallel-finished: true
210215
carryforward: "test-modeling,test-inference,examples"
211-

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
uv.lock
12
numpyro.egg-info
23
__pycache__/
34
.ipynb_checkpoints/

.readthedocs.yaml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ build:
44
os: ubuntu-24.04
55
tools:
66
python: "3.13"
7+
jobs: # https://docs.readthedocs.com/platform/stable/build-customization.html#install-dependencies-with-uv
8+
pre_create_environment:
9+
- asdf plugin add uv
10+
- asdf install uv latest
11+
- asdf global uv latest
12+
create_environment:
13+
- uv venv "${READTHEDOCS_VIRTUALENV_PATH}"
14+
install:
15+
- UV_PROJECT_ENVIRONMENT="${READTHEDOCS_VIRTUALENV_PATH}" uv sync --frozen --extra cpu --group dev --group docs --group test
716

817
sphinx:
918
configuration: docs/source/conf.py
1019

1120
formats:
1221
- pdf
13-
14-
python:
15-
install:
16-
- requirements: docs/requirements.txt

docs/requirements.txt

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

0 commit comments

Comments
 (0)