Skip to content

Commit

Permalink
πŸ”¨ more tox, less poe (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
jorenham authored Jan 23, 2025
2 parents 3ac4dd6 + 75832d8 commit e24eff3
Show file tree
Hide file tree
Showing 8 changed files with 180 additions and 419 deletions.
75 changes: 47 additions & 28 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

env:
UV_FROZEN: 1

jobs:
lint:
timeout-minutes: 1
runs-on: ubuntu-latest
timeout-minutes: 2

steps:
- uses: actions/checkout@v4

- uses: scientific-python/repo-review@v0.11.3
with:
plugins: sp-repo-review

- name: markdownlint
uses: DavidAnson/markdownlint-cli2-action@v19
with:
Expand All @@ -28,10 +35,21 @@ jobs:
- name: typos
uses: crate-ci/typos@master

- uses: astral-sh/setup-uv@v5
with:
enable-cache: true
python-version: "3.13"
version: latest

- name: ruff
run: |
uv run ruff check --output-format=github
uv run ruff format --check
generate-matrix:
name: Generate Test Matrix
timeout-minutes: 1
runs-on: ubuntu-latest
timeout-minutes: 1

outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
Expand All @@ -41,10 +59,10 @@ jobs:

- name: Install uv
uses: astral-sh/setup-uv@v5

- name: Install dependencies
run: |
uv sync --locked
with:
enable-cache: true
python-version: "3.13"
version: latest

- name: Generate Matrix
id: set-matrix
Expand All @@ -55,8 +73,8 @@ jobs:
typetest:
needs: generate-matrix
timeout-minutes: 3
runs-on: ubuntu-latest
timeout-minutes: 3

strategy:
fail-fast: false
Expand All @@ -65,31 +83,32 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Install uv
- name: setup uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
python-version: ${{ matrix.python }}

- name: setup tox
run: uv tool install tox --with tox-uv

- name: Install dependencies
run: |
rm -rf .venv
uv add --no-build-package=numpy "numpy<=${{ matrix.numpy }}"
- name: Run typetest
run: uv run tox -e=typetest

- name: Run stubtest
run: uv run tox -e=stubtest

- name: lint
run: uv run tox -e=lint
- name: basedpyright
run: >
uv run --with="numpy==${{ matrix.numpy }}"
basedpyright
- name: basedmypy
run: uv run tox -e=mypy

- name: basedpyright
run: uv run tox -e=pyright
run: >
uv run --with="numpy==${{ matrix.numpy }}"
mypy
--tb
--hide-error-context
--hide-error-code-links
.
- name: stubtest
run: >
uv run --with="numpy==${{ matrix.numpy }}" --no-editable
stubtest
--tb
--ignore-unused-allowlist
--allowlist=.mypyignore
--mypy-config-file=pyproject.toml
scipy
15 changes: 5 additions & 10 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
ci:
autoupdate_branch: "master"
autoupdate_commit_msg: "⬆️ update pre-commit hooks"
skip:
- basedpyright

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
Expand Down Expand Up @@ -54,6 +52,11 @@ repos:
hooks:
- id: typos

- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.5.23
hooks:
- id: uv-lock

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.2
hooks:
Expand All @@ -63,11 +66,3 @@ repos:

- id: ruff-format
types_or: [python, pyi]

- repo: local
hooks:
- id: basedpyright
name: basedpyright
entry: uv run --no-sync --locked basedpyright
language: system
types_or: [python, pyi]
88 changes: 69 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,43 +192,93 @@ uv sync --frozen
### pre-commit

`scipy-stubs` uses [pre-commit](https://pre-commit.com/) to ensure that the code is
formatted and typed correctly when committing the changes.
formatted and typed correctly when committing the changes. For better performance,
you could additionally install [`pre-commit-uv`](https://github.com/tox-dev/pre-commit-uv):

```bash
poe pre-commit
uv tool install pre-commit --with pre-commit-uv --force-reinstall
```

<details>
<summary>Output:</summary>

```plaintext
Resolved 11 packages in 74ms
Prepared 11 packages in 1ms
Uninstalled 11 packages in 9ms
Installed 11 packages in 10ms
~ cfgv==3.4.0
~ distlib==0.3.9
~ filelock==3.17.0
~ identify==2.6.6
~ nodeenv==1.9.1
~ platformdirs==4.3.6
~ pre-commit==4.1.0
~ pre-commit-uv==4.1.4
~ pyyaml==6.0.2
~ uv==0.5.23
~ virtualenv==20.29.1
Installed 1 executable: pre-commit
```

</details>

Now to install the git hook script, make sure that your the root directory of the `scipy-stubs` repo, then run:

```bash
uvx pre-commit install
```

Output:

```plaintext
pre-commit installed at .git/hooks/pre-commit
```

> [!NOTE]
> Pre-commit doesn't run `stubtest`. This will be run by github actions
> when submitting a pull request. See the next section for more details.
> For performance reasons, `pre-commit` won't run `mypy` and `stubtest`. You could do this
> yourself with `tox -e mypy` and `tox -e stubtest`, as explained in the next section.
> That way you won't have to rely on the (slow) github actions workflow when you submit your PR.
### Tox

The pre-commit hooks and `stubtest` can easily be run with [tox](https://github.com/tox-dev/tox).
It can be installed with:

```bash
uv tool install tox --with tox-uv
uv tool install tox --with tox-uv --upgrade
```

To run all environments in parallel, run:

```shell
$ tox -p all
repo-review: OK βœ” in 0.4 seconds
3.12: OK βœ” in 10.38 seconds
3.10: OK βœ” in 10.62 seconds
3.11: OK βœ” in 11.04 seconds
3.13: OK βœ” in 19.42 seconds
repo-review: OK (0.40=setup[0.04]+cmd[0.36] seconds)
pre-commit: OK (24.91=setup[0.04]+cmd[24.87] seconds)
3.10: OK (10.62=setup[0.11]+cmd[10.51] seconds)
3.11: OK (11.04=setup[0.04]+cmd[11.00] seconds)
3.12: OK (10.38=setup[0.04]+cmd[10.34] seconds)
3.13: OK (19.42=setup[0.04]+cmd[19.38] seconds)
congratulations :) (24.96 seconds)
```bash
uvx tox p
```

<details>
<summary>Output:</summary>

```plaintext
lint: OK βœ” in 0.52 seconds
pre-commit: OK βœ” in 2.59 seconds
3.11: OK βœ” in 21.59 seconds
mypy: OK βœ” in 21.62 seconds
pyright: OK βœ” in 25.23 seconds
3.10: OK βœ” in 25.4 seconds
3.12: OK βœ” in 38.71 seconds
pre-commit: OK (2.59=setup[0.03]+cmd[2.56] seconds)
lint: OK (0.52=setup[0.04]+cmd[0.41,0.03,0.05] seconds)
pyright: OK (25.23=setup[0.03]+cmd[25.20] seconds)
mypy: OK (21.62=setup[0.03]+cmd[21.59] seconds)
3.13: OK (53.28=setup[0.03]+cmd[53.25] seconds)
3.12: OK (38.71=setup[0.03]+cmd[38.68] seconds)
3.11: OK (21.59=setup[0.03]+cmd[21.55] seconds)
3.10: OK (25.40=setup[0.03]+cmd[25.36] seconds)
congratulations :) (53.35 seconds)
```

</details>

### Commit message style

See <https://gitmoji.dev/>.
Expand Down
7 changes: 0 additions & 7 deletions codegen/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,3 @@ where `$NAME` is the name is the name of the codemod, which can be one of:
- `AnnotateMissing` - Sets the default return type to `None`, and sets the other missing annotations to `scipy._typing.Untyped`.
- `FixTrailingComma` - Adds a trailing comma to parameters that don't fit on one line, so that ruff formats them correctly.
- `PosOnlySelf` - nsures `self` is a positional-only parameter.

> [!NOTE]
> The codemods require `libcst`, which is installable through the **optional** `codegen` dependency group:
>
> ```bash
> poetry install --with=codegen
> ```
Loading

0 comments on commit e24eff3

Please sign in to comment.