Skip to content

Commit 21f5849

Browse files
authored
build: Migrate from hatch to uv (#3723)
1 parent f45dcfb commit 21f5849

File tree

14 files changed

+3681
-213
lines changed

14 files changed

+3681
-213
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
fi
7070
- name: Test with pytest
7171
run: |
72-
uv run pytest --pyargs --numprocesses=logical --doctest-modules tests
72+
uv run pytest --pyargs --numprocesses=logical --doctest-modules --doctest-ignore-import-errors tests
7373
- name: Validate Vega-Lite schema
7474
run: |
7575
# We install all 'format' dependencies of jsonschema as check-jsonschema

.github/workflows/docbuild.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ name: docbuild
22

33
on: [push, pull_request]
44

5-
env:
6-
UV_SYSTEM_PYTHON: 1
7-
85
jobs:
96
build:
107
runs-on: ubuntu-latest
@@ -16,13 +13,18 @@ jobs:
1613
python-version: "3.12"
1714
- name: Install uv
1815
uses: astral-sh/setup-uv@v5
16+
with:
17+
enable-cache: true
18+
cache-dependency-glob: |
19+
**/uv.lock
20+
**/pyproject.toml
1921
- name: Install dependencies
20-
run: uv pip install -e ".[dev, all, doc]"
21-
- name: Run doc:build-html
22+
run: uv sync --all-extras
23+
- name: Build docs
2224
run: |
2325
mkdir -p doc/_images
2426
uv run sphinx-build -b html -d doc/_build/doctrees doc doc/_build/html
25-
- name: Run doc:doctest
27+
- name: Run doctests
2628
run: |
2729
uv run sphinx-build -b doctest -d doc/_build/doctrees doc doc/_build/doctest
2830

.github/workflows/lint.yml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@ jobs:
1414
- uses: actions/checkout@v4
1515
- name: Install uv
1616
uses: astral-sh/setup-uv@v5
17+
with:
18+
enable-cache: true
19+
cache-dependency-glob: |
20+
**/uv.lock
21+
**/pyproject.toml
1722
# Installing all dependencies and not just the linters as mypy needs them for type checking
1823
- name: Install dependencies
19-
run: uv pip install -e ".[dev, all]" --system
20-
- name: Lint with ruff
24+
run: uv sync --all-extras
25+
- name: ruff check (lint)
2126
run: |
2227
uv run ruff check
23-
- name: Check formatting with ruff
28+
- name: ruff format
2429
run: |
2530
uv run ruff format --check --diff
26-
- name: Lint with mypy
31+
- name: mypy (type check)
2732
run: |
2833
uv run mypy altair tests

CONTRIBUTING.md

Lines changed: 62 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,54 @@ git clone https://github.com/YOUR-USERNAME/altair.git
2828
To keep your fork up to date with changes in this repo,
2929
you can [use the fetch upstream button on GitHub](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork).
3030

31-
Now you can install the latest version of Altair locally using `pip`.
32-
The `-e` flag indicates that your local changes will be reflected
33-
every time you open a new Python interpreter
34-
(instead of having to reinstall the package each time).
31+
32+
[Install `uv`](https://docs.astral.sh/uv/getting-started/installation/), or update to the latest version:
33+
34+
```cmd
35+
uv self update
36+
```
37+
Install Python:
38+
39+
```cmd
40+
uv python install 3.12
41+
```
42+
43+
Initialize a new virtual environment:
3544

3645
```cmd
37-
cd altair/
38-
python -m pip install -e ".[all, dev]"
46+
cd altair/
47+
uv venv -p 3.12
3948
```
4049

41-
'[all, dev]' indicates that pip should also install the optional and development requirements
42-
which you can find in `pyproject.toml` (`[project.optional-dependencies]/all` and `[project.optional-dependencies]/dev`)
50+
Activate your environment:
51+
52+
<details><summary>macOS/Linux</summary>
53+
<p>
54+
55+
```bash
56+
source .venv/bin/activate
57+
```
58+
59+
</p>
60+
</details>
61+
62+
<details><summary>Windows</summary>
63+
<p>
64+
65+
```cmd
66+
.venv\Scripts\activate
67+
```
68+
69+
</p>
70+
</details>
71+
72+
Install the project with all development dependencies:
73+
```cmd
74+
uv sync --all-extras
75+
```
76+
77+
> [!TIP]
78+
> If you're new to `uv`, check out their [Getting started](https://docs.astral.sh/uv/getting-started/) guide for help
4379
4480
### Creating a Branch
4581

@@ -59,7 +95,7 @@ make sure to run the following to see if there are any changes
5995
to the automatically generated files:
6096

6197
```bash
62-
hatch run generate-schema-wrapper
98+
uv run task generate-schema-wrapper
6399
```
64100

65101
For information on how to update the Vega-Lite version that Altair uses,
@@ -72,7 +108,7 @@ it is recommended that you run the Altair test suite,
72108
which includes a number of tests to validate the correctness of your code:
73109

74110
```bash
75-
hatch test
111+
uv run task test
76112
```
77113

78114

@@ -83,14 +119,15 @@ Study the output of any failed tests and try to fix the issues
83119
before proceeding to the next section.
84120

85121
#### Failures on specific python version(s)
86-
By default, `hatch test` will run the test suite against the currently active python version.
122+
123+
By default, `uv run task test` will run the test suite against the currently active python version.
87124
Two useful variants for debugging failures that only appear *after* you've submitted your PR:
88125

89126
```bash
90127
# Test against all python version(s) in the matrix
91-
hatch test --all
92-
# Test against a specific python version
93-
hatch test --python 3.8
128+
uv run task test-all
129+
# Test against our minimum required version
130+
uv run task test-min
94131
```
95132

96133
See [hatch test](https://hatch.pypa.io/latest/cli/reference/#hatch-test) docs for other options.
@@ -99,7 +136,7 @@ See [hatch test](https://hatch.pypa.io/latest/cli/reference/#hatch-test) docs fo
99136
If `test_completeness_of__all__` fails, you may need to run:
100137

101138
```bash
102-
hatch run update-init-file
139+
uv run task update-init-file
103140
```
104141
However, this test usually indicates *unintentional* addition(s) to the top-level `alt.` namespace that will need resolving first.
105142

@@ -204,27 +241,20 @@ Some additional notes:
204241

205242
The process to build the documentation locally consists of three steps:
206243

207-
1. Clean any previously generated files to ensure a clean build.
208-
2. Generate the documentation in HTML format.
209-
3. View the generated documentation using a local Python testing server.
210-
211-
The specific commands for each step depend on your operating system.
212-
Make sure you execute the following commands from the root dir of altair and have [`hatch`](https://hatch.pypa.io/) installed in your local environment.
244+
1. **Clean** (remove) any previously generated documentation files.
245+
2. **Build** the documentation in HTML format.
246+
3. View the documentation using a *local* Python testing **server**.
213247

214-
- For MacOS and Linux, run the following commands in your terminal:
215-
```bash
216-
hatch run doc:clean-all
217-
hatch run doc:build-html
218-
hatch run doc:serve
219-
```
220-
221-
- For Windows, use these commands instead:
248+
Steps 1 & 2 can be run as a single command, followed by step 3:
222249
```cmd
223-
hatch run doc:clean-all-win
224-
hatch run doc:build-html-win
225-
hatch run doc:serve
250+
uv run task doc-clean-build
251+
uv run task doc-serve
226252
```
227253

254+
> [!TIP]
255+
> If these commands were not available for you, make sure you've [set up your environment](#setting-up-your-environment)
256+
257+
228258
To view the documentation, open your browser and go to `http://localhost:8000`. To stop the server, use `^C` (control+c) in the terminal.
229259

230260
---

NOTES_FOR_MAINTAINERS.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ The core Python API for Altair can be found in the following locations:
77
- ``altair/vegalite/v5/schema/``
88

99
All the files within these directories are created automatically by running
10-
the following script from the root of the repository:
10+
the following script:
1111

1212
```bash
13-
hatch run generate-schema-wrapper
13+
uv run task generate-schema-wrapper
1414
```
1515

1616
This script does a couple things:
@@ -86,7 +86,7 @@ These additional methods have fairly good test coverage, so running the test
8686
suite should identify any inconsistencies:
8787

8888
```bash
89-
hatch test
89+
uv run task test
9090
```
9191

9292
Generally, minor version updates (e.g. Vega-Lite 2.3->2.4) have been relatively

README.md

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,19 +108,10 @@ you can post it on [StackOverflow](https://stackoverflow.com/questions/tagged/al
108108
For bugs and feature requests, please open a [Github Issue](https://github.com/vega/altair/issues).
109109

110110
## Development
111-
112-
[![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch)
111+
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
113112
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
114113
[![pytest](https://img.shields.io/badge/logo-pytest-blue?logo=pytest&labelColor=5c5c5c&label=%20)](https://github.com/pytest-dev/pytest)
115114

116-
You can find the instructions on how to install the package for development in [the documentation](https://altair-viz.github.io/getting_started/installation.html).
117-
118-
To run the tests and linters, use
119-
120-
```bash
121-
hatch test
122-
```
123-
124115
For information on how to contribute your developments back to the Vega-Altair repository, see
125116
[`CONTRIBUTING.md`](https://github.com/vega/altair/blob/main/CONTRIBUTING.md)
126117

RELEASING.md

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
1. Check all [Vega project](https://github.com/orgs/vega/repositories?type=source) versions are up-to-date. See [NOTES_FOR_MAINTAINERS.md](NOTES_FOR_MAINTAINERS.md)
22

3-
2. Make sure to have an environment set up with `hatch` installed. See [CONTRIBUTING.md](CONTRIBUTING.md).
4-
Remove any existing environments managed by `hatch` so that it will create new ones
5-
with the latest dependencies when executing the commands further below:
3+
4+
2. Make sure to have [set up your environment](CONTRIBUTING.md#setting-up-your-environment).
5+
Update your environment with the latest dependencies:
66

7-
hatch env prune
7+
uv sync --all-extras
88

99
3. Make certain your branch is in sync with head, and that you have no uncommitted modifications. If you work on a fork, replace `origin` with `upstream`:
1010

1111
git checkout main
1212
git pull origin main
1313
git status # Should show "nothing to commit, working tree clean"
1414

15-
4. Do a clean doc build:
16-
17-
hatch run doc:clean-all
18-
hatch run doc:build-html
19-
hatch run doc:serve
15+
4. Do a [clean doc build](CONTRIBUTING.md#building-the-documentation-locally):
2016

2117
Navigate to http://localhost:8000 and ensure it looks OK (particularly
2218
do a visual scan of the gallery thumbnails).
@@ -38,20 +34,19 @@
3834

3935
8. Merge release branch into main, make sure that all required checks pass
4036

41-
9. On main, build source & wheel distributions. If you work on a fork, replace `origin` with `upstream`:
37+
9. Switch to main, If you work on a fork, replace `origin` with `upstream`:
4238

4339
git switch main
4440
git pull origin main
45-
hatch clean # clean old builds & distributions
46-
hatch build # create a source distribution and universal wheel
47-
48-
10. publish to PyPI (Requires correct PyPI owner permissions):
41+
42+
10. Build a source distribution and universal wheel,
43+
publish to PyPI (Requires correct PyPI owner permissions and [UV_PUBLISH_TOKEN](https://docs.astral.sh/uv/configuration/environment/#uv_publish_token)):
4944

50-
hatch publish
45+
uv run task publish
5146

52-
11. build and publish docs (Requires write-access to altair-viz/altair-viz.github.io):
47+
11. Build and publish docs (Requires write-access to [altair-viz/altair-viz.github.io](https://github.com/altair-viz/altair-viz.github.io)):
5348

54-
hatch run doc:publish-clean-build
49+
uv run task doc-publish-clean-build
5550

5651
12. On main, tag the release. If you work on a fork, replace `origin` with `upstream`:
5752

doc/getting_started/installation.rst

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,6 @@ Altair can also be installed with just the dependencies necessary for saving cha
3333
Development Installation
3434
========================
3535

36-
The `Altair source repository`_ is available on GitHub. Once you have cloned the
37-
repository and installed all the above dependencies, run the following command
38-
from the root of the repository to install the main version of Altair:
39-
40-
.. code-block:: bash
41-
42-
pip install -e .
43-
44-
To install optional and development dependencies as well, run
45-
46-
.. code-block:: bash
47-
48-
pip install -e ".[all, dev]"
49-
50-
If you do not wish to clone the source repository, you can install the
51-
development version directly from GitHub using:
52-
53-
.. code-block:: bash
54-
55-
pip install -e git+https://github.com/vega/altair.git
56-
5736
Please see `CONTRIBUTING.md <https://github.com/vega/altair/blob/main/CONTRIBUTING.md>`_
5837
for details on how to contribute to the Altair project.
5938

@@ -62,4 +41,3 @@ for details on how to contribute to the Altair project.
6241
.. _vega_datasets: https://github.com/altair-viz/vega_datasets
6342
.. _JupyterLab: http://jupyterlab.readthedocs.io/
6443
.. _Jupyter Notebook: https://jupyter-notebook.readthedocs.io/
65-
.. _Altair source repository: http://github.com/vega/altair

doc/sync_website.sh

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

0 commit comments

Comments
 (0)