Skip to content

Commit

Permalink
DX: modernize dev environment with uv
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Oct 18, 2024
1 parent eec79e5 commit a0d9563
Show file tree
Hide file tree
Showing 21 changed files with 2,325 additions and 238 deletions.
10 changes: 10 additions & 0 deletions .binder/postBuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash
set -ex
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.cargo/env
uv export \
> requirements.txt
uv pip install \
--requirement requirements.txt \
--system
uv cache clean
1 change: 1 addition & 0 deletions .binder/runtime.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python-3.12
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
],
"ignorePaths": [
"**/.cspell.json",
".envrc",
".github/workflows",
".gitignore",
".pre-commit-config.yaml",
Expand Down
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ indent_size = 4
[LICENSE]
indent_size = unset

[setup.cfg]
[uv.lock]
indent_size = 4
3 changes: 2 additions & 1 deletion .envrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
layout anaconda
uv sync --all-extras --quiet
source .venv/bin/activate
22 changes: 22 additions & 0 deletions .github/workflows/lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Update

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: |-
${{ github.ref != format('refs/heads/{0}', github.event.repository.default_branch) }}
on:
pull_request:
branches:
- main
- epic/*
paths:
- .pre-commit-config.yaml
- uv.lock
workflow_dispatch:

jobs:
lock:
uses: ComPWA/actions/.github/workflows/lock.yml@v2
secrets:
token: ${{ secrets.PAT }}
14 changes: 7 additions & 7 deletions .github/workflows/notebook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.9"
- uses: hynek/setup-cached-uv@v2
- name: Install dependencies
run: |
sudo apt-get -y install graphviz
pip install uv
python-version: "3.10"
- uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- name: Install graphviz
run: sudo apt-get -y install graphviz
- run: |
for notebook in $(git ls-files | grep ipynb); do
uv pip sync requirements.txt --quiet --system
uv sync --extra dev --quiet
pytest $notebook --no-header
done
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@
.ipynb_checkpoints/
.tox/
.virtual_documents/
condaenv.*.requirements.txt
node_modules/
59 changes: 30 additions & 29 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
ci:
autoupdate_commit_msg: "MAINT: autoupdate pre-commit hooks"
autoupdate_commit_msg: "MAINT: update lock files"
autoupdate_schedule: quarterly
skip:
- prettier
- taplo

repos:
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes

- repo: /data/local/redeboer/work/ComPWA/policy
rev: 0.5.0rc10
hooks:
- id: check-dev-files
args:
- --no-cd
- --no-cspell-update
- --no-github-actions
- --no-pypi
- --repo-name=ComPWA-demo
- --repo-title="ComPWA demos"
- id: colab-toc-visible
- id: remove-empty-tags

- repo: https://github.com/kynan/nbstripout
rev: 0.7.1
hooks:
- id: nbstripout
args:
- --drop-empty-cells
- --extra-keys
- |
cell.attachments
Expand All @@ -38,24 +50,8 @@ repos:
metadata.varInspector
metadata.vscode
- repo: https://github.com/ComPWA/policy
rev: 0.3.18
hooks:
- id: check-dev-files
args:
- --no-cspell-update
- --no-github-actions
- --no-gitpod
- --no-prettierrc
- --no-pypi
- --no-version-branches
- --repo-name=ComPWA-demo
- --repo-title="ComPWA demos"
- id: colab-toc-visible
- id: remove-empty-tags

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7
rev: v0.7.0
hooks:
- id: ruff
args: [--fix]
Expand All @@ -64,7 +60,7 @@ repos:
types_or: [python, pyi, jupyter]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-case-conflict
- id: check-json
Expand All @@ -80,15 +76,15 @@ repos:
- id: mixed-line-ending
- id: trailing-whitespace

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v4.0.0-alpha.8
- repo: https://github.com/ComPWA/prettier-pre-commit
rev: v3.3.3
hooks:
- id: prettier

- repo: https://github.com/ComPWA/mirrors-taplo
rev: v0.8.1
- repo: https://github.com/ComPWA/taplo-pre-commit
rev: v0.9.3
hooks:
- id: taplo
- id: taplo-format

- repo: https://github.com/pappasam/toml-sort
rev: v0.23.1
Expand All @@ -98,13 +94,18 @@ repos:
- --in-place

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

- repo: https://github.com/editorconfig-checker/editorconfig-checker.python
rev: 2.7.3
rev: 3.0.3
hooks:
- id: editorconfig-checker
name: editorconfig
alias: ec

- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.4.24
hooks:
- id: uv-lock
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
1 change: 1 addition & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"github.vscode-github-actions",
"mhutchie.git-graph",
"ms-python.python",
"ms-vsliveshare.vsliveshare",
"redhat.vscode-yaml",
Expand Down
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@
"ruff.enable": true,
"ruff.importStrategy": "fromEnvironment",
"ruff.organizeImports": true,
"search.exclude": {
"**/uv.lock": true
},
"telemetry.telemetryLevel": "off"
}
6 changes: 3 additions & 3 deletions 2021.12.13/ampform.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"source": [
"%load_ext autoreload\n",
"%autoreload\n",
"from functools import lru_cache\n",
"from functools import cache\n",
"\n",
"import ampform\n",
"import graphviz\n",
Expand Down Expand Up @@ -304,7 +304,7 @@
" return expr\n",
"\n",
"\n",
"@lru_cache(maxsize=None)\n",
"@cache\n",
"def get_amplitude(\n",
" name,\n",
" doit,\n",
Expand All @@ -327,7 +327,7 @@
" return expr\n",
"\n",
"\n",
"@lru_cache(maxsize=None)\n",
"@cache\n",
"def create_graph(expression, fig_size, visualize_cse):\n",
" if fig_size == \"full\":\n",
" fig_size = None\n",
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# ComPWA demo notebooks

[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![Spelling checked](https://img.shields.io/badge/cspell-checked-brightgreen.svg)](https://github.com/streetsidesoftware/cspell/tree/master/packages/cspell)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)

A collection of Jupyter notebooks that demonstrate features of the [ComPWA](https://github.com/ComPWA) packages [QRules](https://qrules.rtfd.io), [AmpForm](https://ampform.rtfd.io), and [TensorWaves](https://tensorwaves.rtfd.io). The notebooks are self-contained in the sense that they define their own pinned requirements and can be run independently in [Binder](https://mybinder.org) or [Google Colaboratory](https://research.google.com/colaboratory).

Expand Down
4 changes: 1 addition & 3 deletions binder/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
asttokens==2.4.1
comm==0.2.2
decorator==5.1.1
exceptiongroup==1.2.2
executing==2.1.0
ipython==8.18.1
ipython==8.28.0
ipywidgets==8.1.5
jedi==0.19.1
jupyterlab-widgets==3.0.13
Expand All @@ -19,7 +18,6 @@ pygments==2.18.0
six==1.16.0
stack-data==0.6.3
traitlets==5.14.3
typing-extensions==4.12.2
uv==0.4.20
wcwidth==0.2.13
widgetsnbextension==4.0.13
11 changes: 0 additions & 11 deletions environment.yml

This file was deleted.

64 changes: 62 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,28 @@
[project]
name = "compwa-demo"
requires-python = ">=3.9"
version = "0.0.0"

[project.optional-dependencies]
dev = [
"compwa-demo[binder]",
"jupyterlab >=3",
"jupyterlab-code-formatter >=3.0.0",
"jupyterlab-git",
"jupyterlab-lsp",
"nbmake",
"pre-commit-uv",
"pytest",
"python-lsp-ruff",
"python-lsp-server[rope]",
"ruff",
"tox",
"uv",
]

[tool.setuptools.dynamic]
dependencies = {file = ["binder/requirements.in"]}

[tool.pytest.ini_options]
addopts = [
"--color=yes",
Expand All @@ -12,7 +37,6 @@ filterwarnings = [
extend-include = ["*.ipynb"]
preview = true
show-fixes = true
target-version = "py37"

[tool.ruff.format]
docstring-code-format = true
Expand Down Expand Up @@ -90,6 +114,42 @@ sort_first = [
"tool.setuptools",
"tool.setuptools_scm",
]
sort_table_keys = true
spaces_indent_inline_array = 4
trailing_comma_inline_array = true

[tool.tox]
legacy_tox_ini = """
[tox]
envlist =
sty,
skip_install = True
skip_missing_interpreters = True
skipsdist = True
[testenv]
passenv = *
[testenv:nb]
allowlist_externals =
pytest
commands =
pytest {posargs}
description = Run all notebooks with pytest
[testenv:sty]
allowlist_externals =
pre-commit
commands =
pre-commit --all-files run {posargs}
description = Perform all linting, formatting, and spelling checks
[testenv:update]
allowlist_externals =
uv
uvx
commands =
uv pip compile binder/requirements.in -o binder/requirements.txt --no-annotate --strip-extras --upgrade
uv lock --upgrade
uvx pre-commit autoupdate
description = Update all lock files
"""
14 changes: 0 additions & 14 deletions requirements.in

This file was deleted.

Loading

0 comments on commit a0d9563

Please sign in to comment.