From 78cbbb0ff7e0d3b70852cfd56d23970a96ece57b Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:16:37 +0200 Subject: [PATCH] DX: define developer environment with `uv` (#10) Co-authored-by: GitHub --- .cspell.json | 4 ++- .editorconfig | 3 ++ .envrc | 3 +- .github/workflows/cd.yml | 10 +++--- .github/workflows/ci.yml | 2 +- .github/workflows/clean-caches.yml | 4 +-- .github/workflows/lock.yml | 21 ++++++++++++ .github/workflows/pr-linting.yml | 2 +- .github/workflows/release-drafter.yml | 2 +- .gitignore | 3 +- .pre-commit-config.yaml | 46 ++++++++++++--------------- .python-version | 1 + .vscode/extensions.json | 1 + .vscode/settings.json | 6 ++-- CONTRIBUTING.md | 25 +++++++++++++-- README.md | 1 + environment.yml | 10 ------ pyproject.toml | 30 +++++++++++++++-- 18 files changed, 117 insertions(+), 57 deletions(-) create mode 100644 .github/workflows/lock.yml create mode 100644 .python-version delete mode 100644 environment.yml diff --git a/.cspell.json b/.cspell.json index 1a4c899..e67fa54 100644 --- a/.cspell.json +++ b/.cspell.json @@ -21,6 +21,7 @@ "ignorePaths": [ "**/.cspell.json", ".editorconfig", + ".envrc", ".gitignore", ".pre-commit-config.yaml", ".prettierignore", @@ -36,7 +37,8 @@ "prereleased", "rtfd", "sphinxcontrib", - "unsrt" + "unsrt", + "venv" ], "language": "en-US", "version": "0.2", diff --git a/.editorconfig b/.editorconfig index 265af0e..f47adce 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,3 +12,6 @@ indent_size = 4 [LICENSE] indent_size = unset + +[uv.lock] +indent_size = 4 diff --git a/.envrc b/.envrc index cce3aa5..41fd2ca 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,2 @@ -layout anaconda +uv sync --all-extras --quiet +source .venv/bin/activate diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 54ae3bc..cf34984 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -9,9 +9,9 @@ on: jobs: milestone: if: startsWith(github.ref, 'refs/tags') - uses: ComPWA/actions/.github/workflows/close-milestone.yml@v1 + uses: ComPWA/actions/.github/workflows/close-milestone.yml@v2 package-name: - uses: ComPWA/actions/.github/workflows/get-pypi-name.yml@v1 + uses: ComPWA/actions/.github/workflows/get-pypi-name.yml@v2 pypi: environment: name: PyPI @@ -22,11 +22,11 @@ jobs: - package-name permissions: id-token: write - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - - uses: ComPWA/actions/build-pypi-distribution@v1 + - uses: ComPWA/actions/build-pypi-distribution@v2 - uses: pypa/gh-action-pypi-publish@release/v1 push: if: startsWith(github.ref, 'refs/tags') && !github.event.release.prerelease secrets: inherit - uses: ComPWA/actions/.github/workflows/push-to-version-branches.yml@v1 + uses: ComPWA/actions/.github/workflows/push-to-version-branches.yml@v2 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b0163c6..a1b164a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,4 +31,4 @@ jobs: if: inputs.specific-pip-packages == '' secrets: token: ${{ secrets.PAT }} - uses: ComPWA/actions/.github/workflows/pre-commit.yml@v1 + uses: ComPWA/actions/.github/workflows/pre-commit.yml@v2 diff --git a/.github/workflows/clean-caches.yml b/.github/workflows/clean-caches.yml index a66c407..7986e0c 100644 --- a/.github/workflows/clean-caches.yml +++ b/.github/workflows/clean-caches.yml @@ -14,9 +14,9 @@ on: jobs: cleanup: name: Remove caches - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - - uses: ComPWA/actions/clean-caches@v1 + - uses: ComPWA/actions/clean-caches@v2 with: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} ref: ${{ inputs.ref }} diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml new file mode 100644 index 0000000..85fa09a --- /dev/null +++ b/.github/workflows/lock.yml @@ -0,0 +1,21 @@ +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 + workflow_dispatch: + +jobs: + lock: + uses: ComPWA/actions/.github/workflows/lock.yml@v2 + secrets: + token: ${{ secrets.PAT }} diff --git a/.github/workflows/pr-linting.yml b/.github/workflows/pr-linting.yml index 0fab841..44dc9e4 100644 --- a/.github/workflows/pr-linting.yml +++ b/.github/workflows/pr-linting.yml @@ -11,4 +11,4 @@ on: jobs: lint-pr: - uses: ComPWA/actions/.github/workflows/pr-linting.yml@v1 + uses: ComPWA/actions/.github/workflows/pr-linting.yml@v2 diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 5234093..32c6579 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -9,7 +9,7 @@ on: jobs: update_release_draft: - runs-on: ubuntu-22.04 + runs-on: ubuntu-24.04 steps: - uses: release-drafter/release-drafter@v6 env: diff --git a/.gitignore b/.gitignore index 03171f1..6f5b663 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,6 @@ version.py # Temporary files *.pyc -*condaenv.* .coverage .coverage.* .ipynb_checkpoints/ @@ -44,6 +43,7 @@ prof/ *venv/ .tox/ pyvenv*/ +uv.lock # Settings .idea/ @@ -59,5 +59,4 @@ pyvenv*/ !.readthedocs.yml !.vscode/*.json !codecov.yml -!environment.yml !pyrightconfig.json diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 46fadaa..eaad89f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,11 +1,9 @@ ci: - autoupdate_commit_msg: "MAINT: autoupdate pre-commit hooks" - autoupdate_schedule: quarterly # already done by requirements-cron.yml + autoupdate_commit_msg: "MAINT: update lock files" + autoupdate_schedule: quarterly skip: - mypy - - prettier - pyright - - taplo repos: - repo: meta @@ -13,15 +11,22 @@ repos: - id: check-hooks-apply - id: check-useless-excludes + - repo: https://github.com/ComPWA/policy + rev: 0.5.0 + hooks: + - id: check-dev-files + args: + - --repo-name=sphinx-pybtex-etal-style + - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.6 + rev: v0.7.0 hooks: - id: ruff args: [--fix] - id: ruff-format - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v5.0.0 hooks: - id: check-ast - id: check-case-conflict @@ -41,15 +46,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 @@ -58,24 +63,13 @@ repos: args: - --in-place - - repo: https://github.com/ComPWA/policy - rev: 0.3.18 - hooks: - - id: check-dev-files - args: - - --no-gitpod - - --no-notebooks - - --no-prettierrc - - --repo-name=sphinx-pybtex-etal-style - - --repo-title=sphinx-pybtex-etal-style - - repo: https://github.com/streetsidesoftware/cspell-cli - rev: v8.13.1 + 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 @@ -94,7 +88,7 @@ repos: types: - python - - repo: https://github.com/ComPWA/mirrors-pyright - rev: v1.1.374 + - repo: https://github.com/ComPWA/pyright-pre-commit + rev: v1.1.385 hooks: - id: pyright diff --git a/.python-version b/.python-version new file mode 100644 index 0000000..e4fba21 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.12 diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 9290f21..a57c6e3 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -6,6 +6,7 @@ "editorconfig.editorconfig", "esbenp.prettier-vscode", "github.vscode-github-actions", + "mhutchie.git-graph", "ms-python.mypy-type-checker", "ms-python.python", "ms-python.vscode-pylance", diff --git a/.vscode/settings.json b/.vscode/settings.json index bbd660b..23c27e5 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -29,11 +29,11 @@ "[yaml]": { "editor.defaultFormatter": "esbenp.prettier-vscode" }, + "cSpell.enabled": true, "coverage-gutters.coverageFileNames": ["coverage.xml"], "coverage-gutters.coverageReportFileName": "**/htmlcov/index.html", "coverage-gutters.showGutterCoverage": false, "coverage-gutters.showLineCoverage": true, - "cSpell.enabled": true, "diffEditor.experimental.showMoves": true, "editor.formatOnSave": true, "files.watcherExclude": { @@ -54,7 +54,6 @@ }, "notebook.formatOnSave.enabled": true, "python.analysis.autoImportCompletions": false, - "python.analysis.typeCheckingMode": "strict", "python.terminal.activateEnvironment": false, "python.testing.unittestEnabled": false, "redhat.telemetry.enabled": false, @@ -62,5 +61,8 @@ "ruff.enable": true, "ruff.importStrategy": "fromEnvironment", "ruff.organizeImports": true, + "search.exclude": { + "**/uv.lock": true + }, "telemetry.telemetryLevel": "off" } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c9ec7a6..dae2803 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,5 +1,26 @@ # How to contribute? -[![Open in Visual Studio Code](https://img.shields.io/badge/vscode-open-blue?logo=visualstudiocode)](https://open.vscode.dev/ComPWA/sphinx-pybtex-etal-style) +[![Open in Visual Studio Code](https://img.shields.io/badge/vscode-open-blue?logo=visualstudiocode)](https://github.dev/ComPWA/sphinx-pybtex-etal-style) -This package is part of the [ComPWA Organization](https://github.com/ComPWA). For more information about how to contribute to the packages, go to **[compwa.github.io/develop](https://compwa.github.io/develop)**. +> [!TIP] +> This package is part of the [ComPWA Organization](https://github.com/ComPWA). For more information about how to contribute to the packages, go to **[compwa.github.io/develop](https://compwa.github.io/develop)**! + +To contribute to the project, you need to install the package in a virtual environment. This can be done best with [`uv`](https://docs.astral.sh/uv) (see installation instructions [here](https://docs.astral.sh/uv/getting-started/installation)). For this, you first need to get the source code with [Git](https://git-scm.com): + +```shell +git clone https://github.com/ComPWA/sphinx-pybtex-etal-style +cd sphinx-pybtex-etal-style +``` + +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 +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**: + +```shell +pre-commit install --install-hooks +``` diff --git a/README.md b/README.md index f469a7b..be5ea82 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ [![Spelling checked](https://img.shields.io/badge/cspell-checked-brightgreen.svg)](https://github.com/streetsidesoftware/cspell/tree/master/packages/cspell) [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier) [![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) This Sphinx extension defines a new bibliography style for the [`sphinxcontrib-bibtex`](https://sphinxcontrib-bibtex.rtfd.io) extension. Install through [PyPI](https://pypi.org) with `pip`: diff --git a/environment.yml b/environment.yml deleted file mode 100644 index b9f5e11..0000000 --- a/environment.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: sphinx-pybtex-etal-style -channels: - - defaults -dependencies: - - python==3.9.* - - pip - - pip: - - -e .[dev] -variables: - PRETTIER_LEGACY_CLI: "1" diff --git a/pyproject.toml b/pyproject.toml index 1030ddf..96743d8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,7 @@ mypy = [ "mypy", ] sty = [ - "pre-commit >=1.4.0", + "pre-commit-uv", "ruff", "sphinx-pybtex-etal-style[format]", "sphinx-pybtex-etal-style[lint]", @@ -75,6 +75,8 @@ namespaces = false where = ["src"] [tool.setuptools_scm] +local_scheme = "no-local-version" +version_scheme = "only-version" write_to = "src/version.py" [tool.coverage.run] @@ -102,6 +104,7 @@ exclude = [ "**/.mypy_cache", "**/.pytest_cache", "**/.tox", + "**/.venv/", "**/__pycache__", "**/_build", ] @@ -122,10 +125,10 @@ reportUnusedVariable = true typeCheckingMode = "strict" [tool.ruff] +extend-include = ["*.ipynb"] preview = true show-fixes = true src = ["src"] -target-version = "py39" [tool.ruff.format] docstring-code-format = true @@ -163,10 +166,32 @@ ignore = [ select = ["ALL"] task-tags = ["cspell"] +[tool.ruff.lint.flake8-builtins] +builtins-ignorelist = ["display"] + +[tool.ruff.lint.flake8-comprehensions] +allow-dict-calls-with-keyword-arguments = true + [tool.ruff.lint.isort] split-on-trailing-comma = false [tool.ruff.lint.per-file-ignores] +"*.ipynb" = [ + "B018", + "C90", + "D", + "E303", + "E703", + "N806", + "N816", + "PLR09", + "PLR2004", + "PLW0602", + "PLW0603", + "S101", + "T20", + "TCH00", +] "setup.py" = ["D100"] "tests/*" = [ "D", @@ -190,6 +215,5 @@ sort_first = [ "tool.setuptools", "tool.setuptools_scm", ] -sort_table_keys = true spaces_indent_inline_array = 4 trailing_comma_inline_array = true