Skip to content

Commit 8c35ae2

Browse files
authored
Switch from hatch to uv (#1356)
* use dependency-groups in pyproject.toml * replace `hatch run foo` with `uv run poe foo` * install uv @ 0.7.12 in CI and disable caching * use `uv run --group docs` for the `docs` command * DRY docs between CONTRIBUTING and README * tell pyre to ignore `.venv` * set up uv to rebuild on rust, pyproject.toml, git changes
1 parent ab12c4c commit 8c35ae2

7 files changed

Lines changed: 2844 additions & 121 deletions

File tree

.github/workflows/ci.yml

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,35 +25,29 @@ jobs:
2525
- "3.14"
2626
- "3.14t"
2727
steps:
28-
- uses: actions/setup-python@v5
28+
- name: Install uv
29+
uses: astral-sh/setup-uv@v5
2930
with:
30-
python-version: "3.10"
31-
- name: Install hatch
32-
run: pip install -U hatch
31+
version: "0.7.12"
32+
python-version: ${{ matrix.python-version }}
3333
- uses: actions/checkout@v4
3434
with:
3535
fetch-depth: 0
3636
persist-credentials: false
37-
- uses: actions/setup-python@v5
38-
with:
39-
cache: pip
40-
cache-dependency-path: "pyproject.toml"
41-
python-version: ${{ matrix.python-version }}
42-
allow-prereleases: true
4337
- uses: dtolnay/rust-toolchain@stable
4438
- name: Build LibCST
45-
run: hatch -vv env create
39+
run: uv sync --locked --dev
4640
- name: Native Parser Tests
47-
run: hatch run test
41+
run: uv run poe test
4842
- name: Pure Parser Tests
4943
env:
5044
COVERAGE_FILE: .coverage.pure
5145
LIBCST_PARSER_TYPE: pure
52-
run: hatch run test
46+
run: uv run poe test
5347
- name: Coverage
5448
run: |
55-
hatch run coverage combine .coverage.pure
56-
hatch run coverage report
49+
uv run coverage combine .coverage.pure
50+
uv run coverage report
5751
5852
# Run linters
5953
lint:
@@ -63,15 +57,13 @@ jobs:
6357
with:
6458
fetch-depth: 0
6559
persist-credentials: false
66-
- uses: actions/setup-python@v5
60+
- name: Install uv
61+
uses: astral-sh/setup-uv@v5
6762
with:
68-
cache: pip
69-
cache-dependency-path: "pyproject.toml"
63+
version: "0.7.12"
7064
python-version: "3.10"
71-
- name: Install hatch
72-
run: pip install -U hatch
73-
- run: hatch run lint
74-
- run: hatch run fixtures
65+
- run: uv run poe lint
66+
- run: uv run poe fixtures
7567

7668
# Run pyre typechecker
7769
typecheck:
@@ -81,14 +73,12 @@ jobs:
8173
with:
8274
fetch-depth: 0
8375
persist-credentials: false
84-
- uses: actions/setup-python@v5
76+
- name: Install uv
77+
uses: astral-sh/setup-uv@v5
8578
with:
86-
cache: pip
87-
cache-dependency-path: "pyproject.toml"
79+
version: "0.7.12"
8880
python-version: "3.10"
89-
- name: Install hatch
90-
run: pip install -U hatch
91-
- run: hatch run typecheck
81+
- run: uv run poe typecheck
9282

9383
# Build the docs
9484
docs:
@@ -98,15 +88,13 @@ jobs:
9888
with:
9989
fetch-depth: 0
10090
persist-credentials: false
101-
- uses: actions/setup-python@v5
91+
- name: Install uv
92+
uses: astral-sh/setup-uv@v5
10293
with:
103-
cache: pip
104-
cache-dependency-path: "pyproject.toml"
94+
version: "0.7.12"
10595
python-version: "3.10"
106-
- name: Install hatch
107-
run: pip install -U hatch
10896
- uses: ts-graphviz/setup-graphviz@v2
109-
- run: hatch run docs:docs
97+
- run: uv run --group docs poe docs
11098
- name: Archive Docs
11199
uses: actions/upload-artifact@v4
112100
with:

.github/workflows/pypi_upload.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,17 @@ jobs:
3333
- uses: actions/setup-python@v5
3434
with:
3535
python-version: "3.10"
36-
- name: Install hatch
37-
run: pip install -U hatch
36+
- name: Install uv
37+
uses: astral-sh/setup-uv@v5
38+
with:
39+
version: "0.7.12"
40+
enable-cache: false
3841
- name: Build a source tarball
3942
env:
4043
LIBCST_NO_LOCAL_SCHEME: 1
4144
OUTDIR: ${{ steps.download.outputs.download-path }}
4245
run: >-
43-
hatch run python -m
46+
uv run python -m
4447
build
4548
--sdist
4649
--outdir "$OUTDIR"

.pyre_configuration

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"exclude": [
33
".*\/native\/.*"
44
],
5+
"ignore_all_errors": [
6+
".venv"
7+
],
58
"source_directories": [
69
"."
710
],

CONTRIBUTING.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ We actively welcome your pull requests.
1111

1212
### Setup Your Environment
1313

14-
1. Install a [Rust toolchain](https://rustup.rs) and [hatch](https://hatch.pypa.io)
14+
1. Install a [Rust toolchain](https://rustup.rs) and [uv](https://docs.astral.sh/uv/)
1515
2. Fork the repo on your side
1616
3. Clone the repo
1717
> git clone [your fork.git] libcst
1818
> cd libcst
1919
4. Sync with the main libcst version package
2020
> git fetch --tags https://github.com/instagram/libcst
2121
5. Setup the env
22-
> hatch env create
22+
> uv sync
2323
2424
You are now ready to create your own branch from main, and contribute.
2525
Please provide tests (using unittest), and update the documentation (both docstrings
@@ -28,13 +28,13 @@ and sphinx doc), if applicable.
2828
### Before Submitting Your Pull Request
2929

3030
1. Format your code
31-
> hatch run format
31+
> uv run poe format
3232
2. Run the type checker
33-
> hatch run typecheck
33+
> uv run poe typecheck
3434
3. Test your changes
35-
> hatch run test
35+
> uv run poe test
3636
4. Check linters
37-
> hatch run lint
37+
> uv run poe lint
3838
3939
## Contributor License Agreement ("CLA")
4040
In order to accept your pull request, we need you to submit a CLA. You only need

README.rst

Lines changed: 5 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -148,49 +148,7 @@ Further Reading
148148
Development
149149
-----------
150150

151-
You'll need a recent `Rust toolchain <https://rustup.rs>`_ for developing.
152-
153-
We recommend using `hatch <https://hatch.pypa.io/>` for running tests, linters,
154-
etc.
155-
156-
Then, start by setting up and building the project:
157-
158-
.. code-block:: shell
159-
160-
git clone [email protected]:Instagram/LibCST.git libcst
161-
cd libcst
162-
hatch env create
163-
164-
To run the project's test suite, you can:
165-
166-
.. code-block:: shell
167-
168-
hatch run test
169-
170-
You can also run individual tests by using unittest and specifying a module like
171-
this:
172-
173-
.. code-block:: shell
174-
175-
hatch run python -m unittest libcst.tests.test_batched_visitor
176-
177-
See the `unittest documentation <https://docs.python.org/3/library/unittest.html>`_
178-
for more examples of how to run tests.
179-
180-
We have multiple linters, including copyright checks and
181-
`slotscheck <https://slotscheck.rtfd.io>`_ to check the correctness of class
182-
``__slots__``. To run all of the linters:
183-
184-
.. code-block:: shell
185-
186-
hatch run lint
187-
188-
We use `ufmt <https://ufmt.omnilib.dev/en/stable/>`_ to format code. To format
189-
changes to be conformant, run the following in the root:
190-
191-
.. code-block:: shell
192-
193-
hatch run format
151+
See `CONTRIBUTING.md <CONTRIBUTING.md>`_ for more details.
194152

195153
Building
196154
~~~~~~~~
@@ -208,11 +166,11 @@ directory:
208166
209167
cargo build
210168
211-
To rebuild the ``libcst.native`` module, from the repo root:
169+
The ``libcst.native`` module should be rebuilt automatically, but to force it:
212170

213171
.. code-block:: shell
214172
215-
hatch env prune && hatch env create
173+
uv sync --reinstall-package libcst
216174
217175
Type Checking
218176
~~~~~~~~~~~~~
@@ -223,7 +181,7 @@ To verify types for the library, do the following in the root:
223181

224182
.. code-block:: shell
225183
226-
hatch run typecheck
184+
uv run poe typecheck
227185
228186
Generating Documents
229187
~~~~~~~~~~~~~~~~~~~~
@@ -232,7 +190,7 @@ To generate documents, do the following in the root:
232190

233191
.. code-block:: shell
234192
235-
hatch run docs
193+
uv run --group docs poe docs
236194
237195
Future
238196
======

pyproject.toml

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,8 @@ Documentation = "https://libcst.readthedocs.io/en/latest/"
2828
Github = "https://github.com/Instagram/LibCST"
2929
Changelog = "https://github.com/Instagram/LibCST/blob/main/CHANGELOG.md"
3030

31-
[tool.black]
32-
target-version = ["py39"]
33-
extend-exclude = '^/native/' # Prepend "^/" to specify root file/folder. See https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-format
34-
35-
[tool.coverage.report]
36-
fail_under = 93
37-
precision = 1
38-
show_missing = true
39-
skip_covered = true
40-
41-
[tool.hatch.envs.default]
42-
installer = "uv"
43-
dependencies = [
31+
[dependency-groups]
32+
dev = [
4433
"black==25.1.0",
4534
"coverage[toml]>=4.5.4",
4635
"build>=0.10.0",
@@ -58,6 +47,33 @@ dependencies = [
5847
"setuptools-rust>=1.5.2",
5948
"slotscheck>=0.7.1",
6049
]
50+
docs = [
51+
{include-group = "dev"},
52+
"Sphinx>=5.1.1",
53+
"sphinx-rtd-theme>=0.4.3",
54+
"jupyter>=1.0.0",
55+
"nbsphinx>=0.4.2",
56+
"jinja2==3.1.6",
57+
]
58+
59+
[tool.black]
60+
target-version = ["py39"]
61+
extend-exclude = '^/native/' # Prepend "^/" to specify root file/folder. See https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-format
62+
63+
[tool.coverage.report]
64+
fail_under = 93
65+
precision = 1
66+
show_missing = true
67+
skip_covered = true
68+
69+
[tool.uv]
70+
cache-keys = [
71+
{ file = "pyproject.toml" },
72+
{ git = {commit = true, tags = true}},
73+
{ file = "**/*.rs"},
74+
{ file = "**/Cargo.toml"},
75+
{ file = "**/Cargo.lock"},
76+
]
6177

6278
[tool.poe.tasks]
6379
fixtures = ["regenerate-fixtures", "_assert_no_changes"]
@@ -74,24 +90,6 @@ test = "python -m coverage run -m libcst.tests"
7490
typecheck = "pyre check"
7591
docs = "sphinx-build -ab html docs/source docs/build"
7692

77-
[tool.hatch.envs.default.scripts]
78-
fixtures = "poe fixtures"
79-
format = "poe format"
80-
lint = "poe lint"
81-
test = "poe test"
82-
typecheck = "poe typecheck"
83-
84-
[tool.hatch.envs.docs]
85-
extra-dependencies = [
86-
"Sphinx>=5.1.1",
87-
"sphinx-rtd-theme>=0.4.3",
88-
"jupyter>=1.0.0",
89-
"nbsphinx>=0.4.2",
90-
"jinja2==3.1.6",
91-
]
92-
[tool.hatch.envs.docs.scripts]
93-
docs = "poe docs"
94-
9593
[tool.slotscheck]
9694
exclude-modules = '^libcst\.(testing|tests)'
9795

0 commit comments

Comments
 (0)