Skip to content

Commit

Permalink
FIX: define dev dependencies as dependency groups (#299)
Browse files Browse the repository at this point in the history
* DX: run `pyright` in `tox -e sty` job
* FIX: remove `pre-commit-uv` and `tox` from environment
* MAINT: address Ruff issues
* MAINT: update lock files
  • Loading branch information
redeboer authored Oct 29, 2024
1 parent f610cf9 commit c156ea3
Show file tree
Hide file tree
Showing 9 changed files with 361 additions and 465 deletions.
6 changes: 4 additions & 2 deletions .binder/postBuild
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ set -ex
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.cargo/env
uv export \
--extra jupyter \
--extra notebooks \
--group jupyter \
--group notebooks \
--no-dev \
> requirements.txt
uv pip install \
--requirement requirements.txt \
--system
rm requirements.txt
uv cache clean
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ on:

jobs:
doc:
uses: ComPWA/actions/.github/workflows/ci-docs.yml@v2
uses: ComPWA/actions/.github/workflows/ci-docs.yml@v2.1
permissions:
pages: write
id-token: write
Expand All @@ -37,7 +37,7 @@ jobs:
python-version: "3.9"
specific-pip-packages: ${{ inputs.specific-pip-packages }}
pytest:
uses: ComPWA/actions/.github/workflows/pytest.yml@v2
uses: ComPWA/actions/.github/workflows/pytest.yml@v2.1
with:
coverage-target: qrules
macos-python-version: "3.9"
Expand All @@ -47,6 +47,6 @@ jobs:
if: inputs.specific-pip-packages == ''
secrets:
token: ${{ secrets.PAT }}
uses: ComPWA/actions/.github/workflows/pre-commit.yml@v2
uses: ComPWA/actions/.github/workflows/pre-commit.yml@v2.1
with:
python-version: "3.9"
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
- id: check-useless-excludes

- repo: https://github.com/ComPWA/policy
rev: 0.5.0
rev: 0.5.5
hooks:
- id: check-dev-files
args:
Expand Down Expand Up @@ -61,7 +61,7 @@ repos:
metadata.vscode
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
rev: v0.7.1
hooks:
- id: ruff
args: [--fix]
Expand Down Expand Up @@ -123,7 +123,7 @@ repos:
pass_filenames: false

- repo: https://github.com/streetsidesoftware/cspell-cli
rev: v8.15.1
rev: v8.15.2
hooks:
- id: cspell

Expand All @@ -149,11 +149,11 @@ repos:
- python

- repo: https://github.com/ComPWA/pyright-pre-commit
rev: v1.1.385
rev: v1.1.386
hooks:
- id: pyright

- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.4.24
rev: 0.4.28
hooks:
- id: uv-lock
6 changes: 5 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ build:
pixi global install graphviz uv
- |-
export UV_LINK_MODE=copy
uv run --extra doc --locked --with tox \
uv run \
--group doc \
--locked \
--no-dev \
--with tox \
tox -e doc
mkdir -p $READTHEDOCS_OUTPUT
mv docs/_build/html $READTHEDOCS_OUTPUT
22 changes: 20 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,30 @@ cd qrules
Now it's simply a matter of creating and activating the [virtual environment](https://docs.astral.sh/uv/pip/environments) with [`uv sync`](https://docs.astral.sh/uv/reference/cli/#uv-sync). The dependencies for the project are 'pinned' in each commit through the [`uv.lock` file](https://docs.astral.sh/uv/concepts/projects/#project-lockfile).

```shell
uv sync
uv sync --all-extras
source .venv/bin/activate
```

Formatting and linting checks are automatically performed when committing changes. This is done with [pre-commit](https://pre-commit.com). To install the hooks in your local repository, run [`pre-commit install`](https://pre-commit.com/#3-install-the-git-hook-scripts) **once**:
Formatting and linting checks are automatically performed when committing changes. This is done with [pre-commit](https://pre-commit.com). To install the hooks in your local repository, run install `pre-commit` with `uv`:

```shell
uv tool install pre-commit --with pre-commit-uv --force-reinstall
```

and [`pre-commit install`](https://pre-commit.com/#3-install-the-git-hook-scripts) **once**:

```shell
pre-commit install --install-hooks
```

In addition, it may be handy to install `tox`:

```shell
uv tool install tox --with tox-uv
```

If the repository provides a Tox configuration under [`pyproject.toml`](./pyproject.toml), you can see which jobs it defines with:

```shell
tox list
```
1 change: 1 addition & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ python3 -m pip install git+https://github.com/ComPWA/qrules@main

:::{include} ../CONTRIBUTING.md
:start-after: **[compwa.github.io/develop](https://compwa.github.io/develop)**!
:end-before: If the repository provides a Tox configuration
:::

That's all! Have a look at {doc}`/usage` to try out the package. You can also have a look at {doc}`compwa:develop` for tips on how to work with this 'editable' developer setup!
63 changes: 28 additions & 35 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,29 @@ name = "qrules"
requires-python = ">=3.9"

[project.optional-dependencies]
all = [
"qrules[viz]",
]
viz = ["graphviz"]

[project.readme]
content-type = "text/markdown"
file = "README.md"

[project.urls]
Changelog = "https://github.com/ComPWA/qrules/releases"
Documentation = "https://qrules.rtfd.io"
Source = "https://github.com/ComPWA/qrules"
Tracker = "https://github.com/ComPWA/qrules/issues"

[dependency-groups]
dev = [
"qrules[all]",
"qrules[doc]",
"qrules[jupyter]",
"qrules[sty]",
"qrules[test]",
"ruff",
"sphinx-autobuild",
"tox",
{include-group = "doc"},
{include-group = "jupyter"},
{include-group = "style"},
{include-group = "test"},
]
doc = [
"myst-nb",
"qrules[notebooks]",
"sphinx",
"sphinx-api-relink",
"sphinx-book-theme",
Expand All @@ -76,56 +84,41 @@ doc = [
"sphinx-thebe",
"sphinx-togglebutton",
"sphinxcontrib-bibtex >=2",
{include-group = "notebooks"},
]
jupyter = [
"ipywidgets",
"jupyterlab",
"jupyterlab-code-formatter >=3.0.0",
"jupyterlab-code-formatter",
"jupyterlab-git",
"jupyterlab-lsp",
"jupyterlab-myst",
"python-lsp-ruff",
"python-lsp-server[rope]",
{include-group = "notebooks"},
]
notebooks = [
"qrules[viz]",
]
sty = [
notebooks = ["qrules[viz]"]
style = [
"mypy",
"pre-commit-uv",
"qrules[types]",
"ruff",
{include-group = "types"},
]
test = [
"ipython",
"nbmake",
"pydot <2", # problem with pydot.graph_from_dot_data
"pydot <2",
"pytest",
"pytest-cov",
"pytest-profiling",
"pytest-xdist",
]
types = [
"ipython",
"pydot <2", # problem with pydot.graph_from_dot_data
"pydot <2",
"pytest",
"sphinx-api-relink",
"types-PyYAML",
"types-setuptools",
]
viz = [
"graphviz",
]

[project.readme]
content-type = "text/markdown"
file = "README.md"

[project.urls]
Changelog = "https://github.com/ComPWA/qrules/releases"
Documentation = "https://qrules.rtfd.io"
Source = "https://github.com/ComPWA/qrules"
Tracker = "https://github.com/ComPWA/qrules/issues"

[tool.setuptools]
include-package-data = false
Expand Down Expand Up @@ -242,6 +235,8 @@ reportUnusedFunction = true
reportUnusedImport = true
reportUnusedVariable = true
typeCheckingMode = "strict"
venv = ".venv"
venvPath = "."

[tool.pytest.ini_options]
addopts = [
Expand Down Expand Up @@ -512,8 +507,6 @@ allowlist_externals =
commands =
pre-commit run --all-files {posargs}
description = Perform all linting, formatting, and spelling checks
setenv =
SKIP = pyright
[testenv:test]
allowlist_externals =
Expand Down
5 changes: 3 additions & 2 deletions src/qrules/transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,10 +250,11 @@ def __init__( # noqa: C901, PLR0912, PLR0917
self.__number_of_threads = NumberOfThreads.get()
if interaction_type_settings is None:
interaction_type_settings = {}
if formalism not in set(SpinFormalism.__args__): # type: ignore[attr-defined]
spin_formalisms = SpinFormalism.__args__ # type: ignore[attr-defined]
if formalism not in set(spin_formalisms):
msg = (
f'Formalism "{formalism}" not implemented. Use one of'
f" {', '.join(SpinFormalism.__args__)} instead." # type: ignore[attr-defined]
f" {', '.join(spin_formalisms)} instead."
)
raise NotImplementedError(msg)
self.__formalism = formalism
Expand Down
Loading

0 comments on commit c156ea3

Please sign in to comment.