Skip to content

Commit

Permalink
FIX: define dev dependencies as dependency groups (#535)
Browse files Browse the repository at this point in the history
* BREAK: remove `all` optional depdency
* BREAK: remove `phasespace` optional depdency group
* BREAK: remove `tensorflow` optional depdency group
* BREAK: remove `viz` optional dependency group
* DX: move `nbmake` to `dev` dependencies
* DX: run `pyright` in `tox -e sty` job
* DX: set `PYTHONHASHSEED` in `direnv` environment
* FIX: remove `pre-commit-uv` and `tox` from environment
* FIX: update links to TRs
* MAINT: address Ruff issues
* MAINT: update lock files
  • Loading branch information
redeboer authored Oct 29, 2024
1 parent a25c6cf commit 010faa3
Show file tree
Hide file tree
Showing 14 changed files with 633 additions and 818 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
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
uv sync --all-extras --quiet
source .venv/bin/activate

export PYTHONHASHSEED=0
23 changes: 13 additions & 10 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,24 @@ on:
jobs:
benchmark:
name: Performance regression
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: ComPWA/actions/pip-install@v1
- uses: actions/setup-python@v5
with:
editable: "yes"
extras: test,all
python-version: "3.9"
specific-packages: ${{ inputs.specific-pip-packages }}
python-version: "3.12"
- uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- name: Run pytest-benchmark
run: |
pytest \
-k benchmark \
--benchmark-json output.json \
--durations=0
uv run \
--group test \
--no-dev \
pytest \
-k benchmark \
--benchmark-json output.json \
--durations=0
working-directory: benchmarks
- name: Store result
if: github.event_name == 'push'
Expand Down
7 changes: 3 additions & 4 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,9 +37,8 @@ jobs:
python-version: "3.10"
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:
additional-extras: all
coverage-target: tensorwaves
macos-python-version: "3.9"
specific-pip-packages: ${{ inputs.specific-pip-packages }}
Expand All @@ -48,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.10"
12 changes: 6 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ 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:
- --ci-test-extras=all
- --dev-python-version=3.10
- --doc-apt-packages=graphviz
- --environment-variables=PYTHONHASHSEED=0
- --repo-name=tensorwaves
- --repo-title=TensorWaves
- --update-lock-files=monthly
Expand Down Expand Up @@ -62,7 +62,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 @@ -128,7 +128,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 @@ -154,11 +154,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 tensorwaves
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
```
2 changes: 1 addition & 1 deletion docs/amplitude-analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@
"source": [
"::::{margin}\n",
":::{tip}\n",
"{doc}`TR-018<compwa-report:018>` explains some of the mechanisms behind the phase space generator as well as how to do {ref}`importance sampling<compwa-report:018:Intensity distribution>`.\n",
"{doc}`TR-018<compwa-report:018/index>` explains some of the mechanisms behind the phase space generator as well as how to do {ref}`importance sampling<compwa-report:018/index:Intensity distribution>`.\n",
":::\n",
"::::\n",
"\n",
Expand Down
1 change: 1 addition & 0 deletions docs/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ python3 -m pip install "tensorwaves[jax,pwa] @ git+https://github.com/ComPWA/ten
:::{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!
2 changes: 1 addition & 1 deletion docs/usage.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@
" symbol = sp.Dummy(name)\n",
" latex = sp.latex(symbol)\n",
" values.append(f\"{latex}={value:.2g}\")\n",
" return f'${\",\".join(values)}$'"
" return f\"${','.join(values)}$\""
]
},
{
Expand Down
126 changes: 50 additions & 76 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,46 @@ name = "tensorwaves"
requires-python = ">=3.9"

[project.optional-dependencies]
all = [
"tensorwaves[jax]",
"tensorwaves[numba]",
"tensorwaves[pwa]",
"tensorwaves[scipy]",
"tensorwaves[tensorflow]",
"tensorwaves[viz]",
jax = [
"jax",
"jaxlib",
]
numba = ["numba"]
phsp = [
"phasespace[tf] >=1.7.0",
"tensorwaves[tf]",
]
pwa = [
"ampform[viz]>=0.12.0",
"tensorwaves[phsp]",
]
scipy = ["scipy >=1"]
tf = [
"numpy~=1.0",
"tensorflow >=2.4",
]

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

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

[dependency-groups]
dev = [
"nbmake",
"ruff",
"sphinx-autobuild",
"tensorwaves[all]",
"tensorwaves[doc]",
"tensorwaves[jupyter]",
"tensorwaves[sty]",
"tensorwaves[test]",
"tox",
{include-group = "doc"},
{include-group = "jupyter"},
{include-group = "style"},
{include-group = "test"},
]
doc = [
"jupyter",
"matplotlib",
"myst-nb",
"sphinx",
"sphinx-api-relink",
Expand All @@ -80,98 +100,52 @@ doc = [
"sphinx-thebe",
"sphinx-togglebutton",
"sphobjinv",
"tensorwaves[notebooks]",
]
jax = [
"jax",
"jaxlib",
"tensorwaves[all]",
{include-group = "notebooks"},
]
jupyter = [
"jupyterlab",
"jupyterlab-code-formatter >=3.0.0",
"jupyterlab-code-formatter",
"jupyterlab-git",
"jupyterlab-lsp",
"jupyterlab-myst",
"python-lsp-ruff",
"python-lsp-server[rope]",
"tensorwaves[doc]",
{include-group = "doc"},
]
notebooks = [
"black",
"ipympl",
"matplotlib",
"pandas",
"tensorwaves[jax,pwa]",
]
numba = [
"numba",
]
phasespace = [
"tensorwaves[phsp]",
]
phsp = [
"phasespace[tf] >=1.7.0",
"tensorwaves[tensorflow]",
]
pwa = [
"ampform >=0.12.0", # https://github.com/ComPWA/ampform/pull/177
"tensorwaves[phsp]",
]
scipy = [
"scipy >=1",
]
sty = [
"mypy >=0.570", # attrs support
"pre-commit-uv",
"ruff",
"tensorwaves[types]",
]
tensorflow = [
"tensorwaves[tf]",
style = [
"mypy",
{include-group = "types"},
]
test = [
"ampform >=0.13", # https://github.com/ComPWA/ampform/issues/208
"nbmake",
"pyarrow", # https://github.com/pandas-dev/pandas/issues/54466
"ampform >=0.13",
"pyarrow",
"pytest-benchmark",
"pytest-cov",
"pytest-xdist",
"tensorflow !=2.17.0", # https://github.com/ComPWA/tensorwaves/actions/runs/10274147572/job/28430227465?pr=530
"tensorwaves[test-types]",
"tensorwaves[jax,numba,pwa]",
{include-group = "test-types"},
]
test-types = [
"ipython", # test _repr_pretty_
"pytest",
"pytest-mock",
]
tf = [
"numpy<2",
"tensorflow !=2.15.0.post1", # https://github.com/ComPWA/tensorwaves/actions/runs/7147814088/job/19467965144?pr=509
"tensorflow >=2.4", # tensorflow.experimental.numpy
]
types = [
"sphinx-api-relink",
"tensorwaves[jax]",
"tensorwaves[pwa]",
"tensorwaves[test-types]",
"tensorwaves[jax,pwa]",
"types-PyYAML",
"types-requests",
"types-tensorflow",
"types-tqdm",
{include-group = "test-types"},
]
viz = [
"graphviz",
]

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

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

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

[tool.pytest.ini_options]
addopts = ["--color=yes"]
Expand Down Expand Up @@ -609,6 +585,4 @@ allowlist_externals =
commands =
pre-commit run --all-files {posargs}
description = Perform all linting, formatting, and spelling checks
setenv =
SKIP = pyright
"""
Loading

0 comments on commit 010faa3

Please sign in to comment.