Skip to content

Commit fbb16c4

Browse files
selmanozleyenpre-commit-ci[bot]flying-sheep
authored
Moving to uv + hatch (#1029)
* try to move to uv+hatch * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update test.yml * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * problems of vibe coding :( * retry * try out this setting * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix2 * remove scanpy specific options * remove junit * remove juntxml uplaod * dont publish debug data and upload test data * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * upload figures * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * just slack the tests for less flaky tests * update assertion * update matrix * update matrix * update configs * ofc you can't set os in hatch * fix hatch * set notebook to main again * simplify test.yml * clean up * fix the yaml names * no need for build in test.yml * undo test change and remove tox.ini * fix macos dir error * fix archive filepath problem * add tolerance for tests/graph/test_ppatterns.py::test_spatial_autocorr_reproducibility[1-moran] * fix attempt for coverage * fix the path * don't specify .xml * match the versions so they are the same * undo the tolerance * update the python versions in hatch * point to old commit * replace bash script in CI to avoid .sh'es * use matrix.os instead of runner.os * redo scheduled job * remove unnecessary lines * remove scripts instead will use uv defaults * remove set -u * use hatch matrix * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix the bash code * fix names and where matrix is * update matrix os * incorperate the cache again as in old code * reduce number of versions and conditionally upload coverage * update docs * use v5 instead * the results aren't from version 6 * check if the floating point dep. is related to matrix list * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update yml * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add 3.12 * fix the issue finally * change the versions * 3.11, 3.12, 3.13 ubuntu and 3.12 macos. bc macos is slow * check if this is the issue * pin versions * no pytest-cov * undo the version pin testing * Python source: 'from __future__ imports must occur at the beginning of the file' at line 10 * add tolerance and explain why * refer to issue instead of commit * Allow download fail on darwin * give it as condition expression * simplify the matrix and get rid of python 3.10 ci test * mark internet required --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Philipp A. <[email protected]>
1 parent 10e5e44 commit fbb16c4

File tree

12 files changed

+221
-240
lines changed

12 files changed

+221
-240
lines changed

.github/workflows/test.yml

Lines changed: 70 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,58 @@
1-
name: Test
1+
name: CI
22

33
on:
44
schedule:
55
- cron: 00 00 * * 1 # every Monday at 00:00
66
push:
7-
branches: [main]
7+
branches:
8+
- main
9+
- "[0-9]+.[0-9]+.x"
810
pull_request:
9-
branches: [main]
10-
workflow_dispatch:
11-
inputs:
12-
reason:
13-
description: Reason for the workflow dispatch. Only "release" is valid.
14-
required: true
15-
default: release
11+
12+
env:
13+
PYTEST_ADDOPTS: "-v --color=yes -n auto"
14+
FORCE_COLOR: "1"
15+
MPLBACKEND: agg
16+
# It's impossible to ignore SyntaxWarnings for a single module,
17+
# so because leidenalg 0.10.0 has them, we pre-compile things: https://github.com/vtraag/leidenalg/issues/173
18+
UV_COMPILE_BYTECODE: "1"
1619

1720
jobs:
1821
test:
1922
runs-on: ${{ matrix.os }}
2023
strategy:
2124
fail-fast: false
2225
matrix:
23-
python: ["3.10", "3.11", "3.12"]
24-
os: [ubuntu-latest]
2526
include:
26-
- python: "3.12"
27+
- name: hatch-test.py3.11-stable
28+
os: ubuntu-latest
29+
python: "3.11"
30+
- name: hatch-test.py3.12-stable
31+
os: ubuntu-latest
32+
python: "3.12"
33+
- name: hatch-test.py3.13-stable
34+
os: ubuntu-latest
35+
python: "3.13"
36+
test-type: "coverage"
37+
- name: hatch-test.py3.13-pre
2738
os: macos-latest
28-
pre-release: "allow"
29-
name: "Python 3.12 (pre-release)"
30-
31-
env:
32-
OS: ${{ matrix.os }}
33-
PYTHON: ${{ matrix.python }}
34-
UV_PRERELEASE: ${{ matrix.pre-release || 'disallow' }}
35-
39+
python: "3.13"
40+
env: # environment variable for use in codecov's env_vars tagging
41+
ENV_NAME: ${{ matrix.name }}
3642
steps:
37-
- uses: actions/checkout@v5
38-
- name: Set up Python ${{ matrix.python }}
39-
uses: astral-sh/setup-uv@v6
43+
- uses: actions/checkout@v4
4044
with:
41-
python-version: ${{ matrix.python }}
42-
enable-cache: true
45+
fetch-depth: 0
46+
filter: blob:none
4347

44-
- name: Install dependencies
45-
run: |
46-
./.scripts/ci/install_dependencies.sh
48+
- uses: astral-sh/setup-uv@v6
49+
with:
50+
enable-cache: true
51+
python-version: ${{ matrix.python }}
52+
cache-dependency-glob: pyproject.toml
4753

48-
- name: Install pip dependencies
49-
run: uv tool install tox --with=tox-uv --with=tox-gh-actions
54+
- name: Ensure figure directory exists
55+
run: mkdir -p "$GITHUB_WORKSPACE/tests/figures"
5056

5157
- name: Restore data cache
5258
id: data-cache
@@ -59,46 +65,54 @@ jobs:
5965
- name: Download datasets
6066
if: steps.data-cache.outputs.cache-hit != 'true'
6167
run: |
62-
tox -e download-data
68+
uvx hatch run ${{ matrix.name }}:download
6369
64-
# caching .tox is not encouraged, but since we're private and this shaves off ~1min from the step
65-
# if any problems occur and/or once the package is public, this can be removed
66-
- name: Restore tox cache
67-
uses: actions/cache@v4
68-
with:
69-
path: .tox
70-
key: tox-${{ runner.os }}-${{ matrix.python }}-${{ hashFiles('**/requirements.txt', '**/tox.ini') }}
70+
- name: System dependencies (Linux)
71+
if: matrix.os == 'ubuntu-latest'
72+
run: |
73+
sudo apt-get update -y
74+
sudo apt-get install automake -y
75+
76+
# PyQt5 related
77+
sudo apt install libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 libxcb-xfixes0 -y
78+
sudo Xvfb :42 -screen 0 1920x1080x24 -ac +extension GLX </dev/null &
79+
80+
- name: System dependencies (macOS)
81+
if: matrix.os == 'macos-latest'
82+
run: brew install automake
83+
84+
- name: Install dependencies
85+
run: uvx hatch -v env create ${{ matrix.name }}
7186

72-
- name: Test
73-
timeout-minutes: 60
74-
env:
75-
MPLBACKEND: agg
76-
PLATFORM: ${{ matrix.os }}
77-
DISPLAY: :42
78-
PYTEST_ADDOPTS: "-n auto"
87+
- name: Run tests
88+
if: matrix.test-type == null
89+
run: uvx hatch run ${{ matrix.name }}:run
90+
- name: Run tests (coverage)
91+
if: matrix.test-type == 'coverage'
7992
run: |
80-
tox -vv
81-
# check if this can be deprecated
82-
#- name: List figures for potential debugging
83-
# ls -alh /home/runner/work/squidpy/squidpy/tests/figures
93+
uvx hatch run ${{ matrix.name }}:run-cov
94+
uvx hatch run ${{ matrix.name }}:coverage combine
95+
uvx hatch run ${{ matrix.name }}:coverage xml
8496
8597
- name: Archive figures generated during testing
8698
if: always()
8799
uses: actions/upload-artifact@v4
88100
with:
89-
name: visual_test_results_${{ matrix.os }}-python${{ matrix.python }}
90-
path: /home/runner/work/squidpy/squidpy/tests/figures/*
101+
name: visual_test_results_${{ runner.os }}_py${{ matrix.name }}
102+
path: ${{ github.workspace }}/tests/figures/*
91103

92-
- name: Upload coverage to Codecov
104+
- name: Upload coverage data
105+
if: matrix.test-type == 'coverage'
93106
uses: codecov/codecov-action@v5
94107
with:
95-
name: coverage
96-
verbose: true
97-
token: ${{ secrets.CODECOV_TOKEN }} # required
108+
token: ${{ secrets.CODECOV_TOKEN }}
109+
env_vars: ENV_NAME
110+
fail_ci_if_error: true
98111

99112
check:
100113
if: always()
101-
needs: [test]
114+
needs:
115+
- test
102116
runs-on: ubuntu-latest
103117
steps:
104118
- uses: re-actors/alls-green@release/v1

.scripts/ci/install_dependencies.sh

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

CONTRIBUTING.rst

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ Tests structure:
6161
Code style guide
6262
----------------
6363
We rely on ``black`` and ``isort`` to do the most of the formatting - both of them are integrated as pre-commit hooks.
64-
You can use ``tox`` to check the changes::
65-
66-
tox -e lint
6764

6865
Furthermore, we also require that:
6966

@@ -75,26 +72,28 @@ Furthermore, we also require that:
7572

7673
Testing
7774
-------
78-
We use ``tox`` to automate our testing, as well as linting and documentation creation. To run the tests, run::
7975

80-
tox -e py{38,39,310}-{linux,macos}
76+
77+
We use [pytest][] to test squidpy.
78+
To run the tests, simply run `hatch test`.
79+
80+
It can take a while to run the whole test suite. There are a few ways to cut down on this while working on a PR:
81+
82+
1. Only run a subset of the tests.
83+
This can be done by specifying paths or test name patterns using the `-k` argument (e.g. `hatch test tests/graph/test_nhood.py` or `hatch test -k "test_umap*"`)
84+
2. Run the tests in parallel using the `-n` argument (e.g. `hatch test -n 8`).
85+
8186

8287
depending on the Python version(s) in your ``PATH`` and your operating system. We use ``flake8`` and ``mypy`` to further
8388
analyze the code. Use ``# noqa: <error1>,<error2>`` to ignore certain ``flake8`` errors and
8489
``# type: ignore[error1,error2]`` to ignore specific ``mypy`` errors.
8590

86-
To run only a subset of tests, run::
8791

88-
tox -e <environment> -- <name>
8992

90-
where ``<name>`` can be a path to a test file/directory or a name of a test function/class.
91-
For example, to run only the tests in the ``nhood`` module, use::
9293

93-
tox -e py39-linux -- tests/graph/test_nhood.py
9494

95-
If needed, a specific ``tox`` environment can be recreated as::
95+
[pytest]: https://docs.pytest.org/en/stable/
9696

97-
tox -e <environment> --recreate
9897

9998
Writing documentation
10099
---------------------
@@ -106,20 +105,25 @@ We use ``numpy``-style docstrings for the documentation with the following addit
106105
- prefer putting references in the ``references.bib`` instead under the ``References`` sections of the docstring.
107106
- use ``docrep`` for repeating documentation.
108107

109-
In order to build the documentation, run::
110108

111-
tox -e docs
109+
To build the docs, run run::
110+
hatch run docs:build
111+
112+
Afterwards, you can run run::
113+
hatch run docs:open
114+
115+
to open {file}`docs/_build/html/index.html`.
112116

113117
Since the tutorials are hosted on a separate repository (see `Writing tutorials/examples`_), we download the newest
114118
tutorials/examples from there and build the documentation here.
115119

116120
To validate the links inside the documentation, run::
117121

118-
tox -e check-docs
122+
hatch run docs:check
119123

120124
If you need to clean the artifacts from previous documentation builds, run::
121125

122-
tox -e clean-docs
126+
hatch run docs:clean
123127

124128
Writing tutorials/examples
125129
--------------------------

MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
include requirements.txt
22
include LICENSE
33
include README.rst
4-
include tox.ini
4+
include hatch.toml
55

66
prune tests/_data
77
prune tests/_images

docs/notebooks

hatch.toml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[envs.default]
2+
installer = "uv"
3+
features = ["dev"]
4+
5+
[envs.coverage]
6+
extra-dependencies = [
7+
"coverage[toml]",
8+
"diff_cover",
9+
]
10+
11+
[envs.coverage.scripts]
12+
clean = "coverage erase"
13+
report = "coverage report --omit='tox/*'"
14+
xml = "coverage xml --omit='tox/*' -o coverage.xml"
15+
diff = "diff-cover --compare-branch origin/main coverage.xml"
16+
17+
[envs.docs]
18+
features = ["docs"]
19+
extra-dependencies = [
20+
"setuptools",
21+
]
22+
23+
[envs.docs.scripts]
24+
build = "make -C docs html {args}"
25+
clean = "make -C docs clean"
26+
check = "make -C docs linkcheck {args}"
27+
28+
[envs.data]
29+
[envs.data.scripts]
30+
download = "python ./.scripts/ci/download_data.py {args}"
31+
32+
33+
[envs.hatch-test]
34+
features = ["test"]
35+
extra-dependencies = [
36+
"pytest",
37+
"pytest-xdist",
38+
"pytest-cov",
39+
"pytest-mock",
40+
"pytest-timeout",
41+
]
42+
43+
44+
45+
[[envs.hatch-test.matrix]]
46+
deps = ["stable"]
47+
python = ["3.11", "3.12", "3.13"]
48+
49+
# Test the newest supported Python version also with pre-release deps
50+
[[envs.hatch-test.matrix]]
51+
deps = [ "pre" ]
52+
python = [ "3.13" ]
53+
54+
[envs.hatch-test.overrides]
55+
# If the matrix variable `deps` is set to "pre",
56+
# set the environment variable `UV_PRERELEASE` to "allow".
57+
matrix.deps.env-vars = [
58+
{ key = "UV_PRERELEASE", value = "allow", if = [ "pre" ] },
59+
]

0 commit comments

Comments
 (0)