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
This commit is contained in:
Zsolt Dollenstein 2025-06-10 21:58:40 +01:00 committed by GitHub
parent ab12c4c266
commit 8c35ae20ef
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 2844 additions and 121 deletions

View file

@ -25,35 +25,29 @@ jobs:
- "3.14"
- "3.14t"
steps:
- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
python-version: "3.10"
- name: Install hatch
run: pip install -U hatch
version: "0.7.12"
python-version: ${{ matrix.python-version }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@v5
with:
cache: pip
cache-dependency-path: "pyproject.toml"
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- uses: dtolnay/rust-toolchain@stable
- name: Build LibCST
run: hatch -vv env create
run: uv sync --locked --dev
- name: Native Parser Tests
run: hatch run test
run: uv run poe test
- name: Pure Parser Tests
env:
COVERAGE_FILE: .coverage.pure
LIBCST_PARSER_TYPE: pure
run: hatch run test
run: uv run poe test
- name: Coverage
run: |
hatch run coverage combine .coverage.pure
hatch run coverage report
uv run coverage combine .coverage.pure
uv run coverage report
# Run linters
lint:
@ -63,15 +57,13 @@ jobs:
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
cache: pip
cache-dependency-path: "pyproject.toml"
version: "0.7.12"
python-version: "3.10"
- name: Install hatch
run: pip install -U hatch
- run: hatch run lint
- run: hatch run fixtures
- run: uv run poe lint
- run: uv run poe fixtures
# Run pyre typechecker
typecheck:
@ -81,14 +73,12 @@ jobs:
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
cache: pip
cache-dependency-path: "pyproject.toml"
version: "0.7.12"
python-version: "3.10"
- name: Install hatch
run: pip install -U hatch
- run: hatch run typecheck
- run: uv run poe typecheck
# Build the docs
docs:
@ -98,15 +88,13 @@ jobs:
with:
fetch-depth: 0
persist-credentials: false
- uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
cache: pip
cache-dependency-path: "pyproject.toml"
version: "0.7.12"
python-version: "3.10"
- name: Install hatch
run: pip install -U hatch
- uses: ts-graphviz/setup-graphviz@v2
- run: hatch run docs:docs
- run: uv run --group docs poe docs
- name: Archive Docs
uses: actions/upload-artifact@v4
with:

View file

@ -33,14 +33,17 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install hatch
run: pip install -U hatch
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
version: "0.7.12"
enable-cache: false
- name: Build a source tarball
env:
LIBCST_NO_LOCAL_SCHEME: 1
OUTDIR: ${{ steps.download.outputs.download-path }}
run: >-
hatch run python -m
uv run python -m
build
--sdist
--outdir "$OUTDIR"

View file

@ -2,6 +2,9 @@
"exclude": [
".*\/native\/.*"
],
"ignore_all_errors": [
".venv"
],
"source_directories": [
"."
],

View file

@ -11,7 +11,7 @@ We actively welcome your pull requests.
### Setup Your Environment
1. Install a [Rust toolchain](https://rustup.rs) and [hatch](https://hatch.pypa.io)
1. Install a [Rust toolchain](https://rustup.rs) and [uv](https://docs.astral.sh/uv/)
2. Fork the repo on your side
3. Clone the repo
> git clone [your fork.git] libcst
@ -19,7 +19,7 @@ We actively welcome your pull requests.
4. Sync with the main libcst version package
> git fetch --tags https://github.com/instagram/libcst
5. Setup the env
> hatch env create
> uv sync
You are now ready to create your own branch from main, and contribute.
Please provide tests (using unittest), and update the documentation (both docstrings
@ -28,13 +28,13 @@ and sphinx doc), if applicable.
### Before Submitting Your Pull Request
1. Format your code
> hatch run format
> uv run poe format
2. Run the type checker
> hatch run typecheck
> uv run poe typecheck
3. Test your changes
> hatch run test
> uv run poe test
4. Check linters
> hatch run lint
> uv run poe lint
## Contributor License Agreement ("CLA")
In order to accept your pull request, we need you to submit a CLA. You only need

View file

@ -148,49 +148,7 @@ Further Reading
Development
-----------
You'll need a recent `Rust toolchain <https://rustup.rs>`_ for developing.
We recommend using `hatch <https://hatch.pypa.io/>` for running tests, linters,
etc.
Then, start by setting up and building the project:
.. code-block:: shell
git clone git@github.com:Instagram/LibCST.git libcst
cd libcst
hatch env create
To run the project's test suite, you can:
.. code-block:: shell
hatch run test
You can also run individual tests by using unittest and specifying a module like
this:
.. code-block:: shell
hatch run python -m unittest libcst.tests.test_batched_visitor
See the `unittest documentation <https://docs.python.org/3/library/unittest.html>`_
for more examples of how to run tests.
We have multiple linters, including copyright checks and
`slotscheck <https://slotscheck.rtfd.io>`_ to check the correctness of class
``__slots__``. To run all of the linters:
.. code-block:: shell
hatch run lint
We use `ufmt <https://ufmt.omnilib.dev/en/stable/>`_ to format code. To format
changes to be conformant, run the following in the root:
.. code-block:: shell
hatch run format
See `CONTRIBUTING.md <CONTRIBUTING.md>`_ for more details.
Building
~~~~~~~~
@ -208,11 +166,11 @@ directory:
cargo build
To rebuild the ``libcst.native`` module, from the repo root:
The ``libcst.native`` module should be rebuilt automatically, but to force it:
.. code-block:: shell
hatch env prune && hatch env create
uv sync --reinstall-package libcst
Type Checking
~~~~~~~~~~~~~
@ -223,7 +181,7 @@ To verify types for the library, do the following in the root:
.. code-block:: shell
hatch run typecheck
uv run poe typecheck
Generating Documents
~~~~~~~~~~~~~~~~~~~~
@ -232,7 +190,7 @@ To generate documents, do the following in the root:
.. code-block:: shell
hatch run docs
uv run --group docs poe docs
Future
======

View file

@ -28,19 +28,8 @@ Documentation = "https://libcst.readthedocs.io/en/latest/"
Github = "https://github.com/Instagram/LibCST"
Changelog = "https://github.com/Instagram/LibCST/blob/main/CHANGELOG.md"
[tool.black]
target-version = ["py39"]
extend-exclude = '^/native/' # Prepend "^/" to specify root file/folder. See https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-format
[tool.coverage.report]
fail_under = 93
precision = 1
show_missing = true
skip_covered = true
[tool.hatch.envs.default]
installer = "uv"
dependencies = [
[dependency-groups]
dev = [
"black==25.1.0",
"coverage[toml]>=4.5.4",
"build>=0.10.0",
@ -58,6 +47,33 @@ dependencies = [
"setuptools-rust>=1.5.2",
"slotscheck>=0.7.1",
]
docs = [
{include-group = "dev"},
"Sphinx>=5.1.1",
"sphinx-rtd-theme>=0.4.3",
"jupyter>=1.0.0",
"nbsphinx>=0.4.2",
"jinja2==3.1.6",
]
[tool.black]
target-version = ["py39"]
extend-exclude = '^/native/' # Prepend "^/" to specify root file/folder. See https://black.readthedocs.io/en/stable/usage_and_configuration/the_basics.html#configuration-format
[tool.coverage.report]
fail_under = 93
precision = 1
show_missing = true
skip_covered = true
[tool.uv]
cache-keys = [
{ file = "pyproject.toml" },
{ git = {commit = true, tags = true}},
{ file = "**/*.rs"},
{ file = "**/Cargo.toml"},
{ file = "**/Cargo.lock"},
]
[tool.poe.tasks]
fixtures = ["regenerate-fixtures", "_assert_no_changes"]
@ -74,24 +90,6 @@ test = "python -m coverage run -m libcst.tests"
typecheck = "pyre check"
docs = "sphinx-build -ab html docs/source docs/build"
[tool.hatch.envs.default.scripts]
fixtures = "poe fixtures"
format = "poe format"
lint = "poe lint"
test = "poe test"
typecheck = "poe typecheck"
[tool.hatch.envs.docs]
extra-dependencies = [
"Sphinx>=5.1.1",
"sphinx-rtd-theme>=0.4.3",
"jupyter>=1.0.0",
"nbsphinx>=0.4.2",
"jinja2==3.1.6",
]
[tool.hatch.envs.docs.scripts]
docs = "poe docs"
[tool.slotscheck]
exclude-modules = '^libcst\.(testing|tests)'

2773
uv.lock generated Normal file

File diff suppressed because it is too large Load diff