From 84f990d5f3d4dfee0b585537bd8e34c23af25bb2 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Fri, 18 Oct 2024 14:36:10 +0200 Subject: [PATCH] DX: define developer environment with `uv` (#103) Co-authored-by: GitHub --- .cspell.json | 1 + .editorconfig | 3 ++ .envrc | 3 +- .github/workflows/cd.yml | 2 +- .github/workflows/ci.yml | 4 +- .github/workflows/clean-caches.yml | 4 +- .github/workflows/lock.yml | 11 +++++- .github/workflows/release-drafter.yml | 2 +- .gitignore | 1 - .pre-commit-config.yaml | 57 ++++++++++++--------------- .python-version | 1 + .vscode/settings.json | 4 +- CONTRIBUTING.md | 29 ++++++++++---- README.md | 1 + environment.yml | 10 ----- pyproject.toml | 15 ++----- 16 files changed, 78 insertions(+), 70 deletions(-) create mode 100644 .python-version delete mode 100644 environment.yml diff --git a/.cspell.json b/.cspell.json index 04a09e29..d1f4ffca 100644 --- a/.cspell.json +++ b/.cspell.json @@ -35,6 +35,7 @@ "ignorePaths": [ "**/.cspell.json", ".editorconfig", + ".envrc", ".gitignore", ".pre-commit-config.yaml", ".prettierignore", diff --git a/.editorconfig b/.editorconfig index 0371c826..980af208 100644 --- a/.editorconfig +++ b/.editorconfig @@ -9,3 +9,6 @@ trim_trailing_whitespace = true [*.{py,toml}] indent_size = 4 + +[uv.lock] +indent_size = 4 diff --git a/.envrc b/.envrc index cce3aa58..41fd2cab 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 d1309885..85b7fd74 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -9,7 +9,7 @@ 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 push-to-version-branches: name: Push to version branches if: startsWith(github.ref, 'refs/tags') && !github.event.release.prerelease diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c5374296..a1b164a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -31,6 +31,4 @@ jobs: if: inputs.specific-pip-packages == '' secrets: token: ${{ secrets.PAT }} - uses: ComPWA/actions/.github/workflows/pre-commit.yml@v1 - with: - python-version: "3.12" + uses: ComPWA/actions/.github/workflows/pre-commit.yml@v2 diff --git a/.github/workflows/clean-caches.yml b/.github/workflows/clean-caches.yml index a66c407b..7986e0cf 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 index 356c36b6..dfdd2525 100644 --- a/.github/workflows/lock.yml +++ b/.github/workflows/lock.yml @@ -1,7 +1,15 @@ +name: Update + env: COMMIT_TITLE: "MAINT: update lock files" on: + pull_request: + branches: + - main + - epic/* + paths: + - .pre-commit-config.yaml workflow_call: secrets: token: @@ -14,6 +22,7 @@ on: This page tells more about creating a PAT: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token required: true + workflow_dispatch: jobs: find-lock-files: @@ -134,7 +143,7 @@ jobs: steps: - uses: actions/checkout@v4 with: - token: ${{ secrets.token }} + token: ${{ secrets.token || github.token}} - uses: actions/download-artifact@v4 with: merge-multiple: true diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 52340935..32c6579c 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 497aad75..7e332414 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,5 @@ .eggs/ # Temporary files -condaenv.*.requirements.txt node_modules/ uv.lock diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6c465393..da6fce97 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,8 @@ ci: - autoupdate_commit_msg: "MAINT: autoupdate pre-commit hooks" + autoupdate_commit_msg: "MAINT: update lock files" autoupdate_schedule: quarterly skip: - - prettier - pyright - - taplo repos: - repo: meta @@ -12,15 +10,29 @@ 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: + - --allow-deprecated-workflows + - --dependabot=update + - --keep-pr-linting + - --no-pypi + - --no-version-branches + - --repo-name=actions + - --repo-title=ComPWA actions and shared workflows + - --update-lock-files=no + - 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 @@ -31,15 +43,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 @@ -48,30 +60,13 @@ repos: args: - --in-place - - repo: https://github.com/ComPWA/policy - rev: 0.3.18 - hooks: - - id: check-dev-files - args: - - --allow-deprecated-workflows - - --dependabot=update - - --dev-python-version=3.12 - - --keep-pr-linting - - --no-gitpod - - --no-notebooks - - --no-prettierrc - - --no-pypi - - --no-version-branches - - --repo-name=actions - - --repo-title=ComPWA actions and shared workflows - - 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 @@ -81,7 +76,7 @@ repos: .*\.py )$ - - 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 00000000..e4fba218 --- /dev/null +++ b/.python-version @@ -0,0 +1 @@ +3.12 diff --git a/.vscode/settings.json b/.vscode/settings.json index 500484f1..2dcf4ebb 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -35,12 +35,14 @@ "notebook.source.organizeImports": "explicit" }, "notebook.formatOnSave.enabled": true, - "python.analysis.typeCheckingMode": "basic", "python.terminal.activateEnvironment": false, "redhat.telemetry.enabled": false, "rewrap.wrappingColumn": 88, "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 2b3ad999..e321da3e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,11 +1,26 @@ -# Help developing +# How to contribute? -## Local set-up +[![Open in Visual Studio Code](https://img.shields.io/badge/vscode-open-blue?logo=visualstudiocode)](https://github.dev/ComPWA/actions) -Please install `pre-commit`, for example [through Conda](https://anaconda.org/conda-forge/pre_commit). For more information, see [Help developing](https://compwa.github.io/develop) on [compwa.github.io](https://compwa.github.io). +> [!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)**! -## Conventions +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): -- It is assumed that repositories that use shared workflows from this repository can run their CI jobs locally with [`tox`](https://tox.wiki). Names of the workflow files should therefore be the same as the name of the corresponding `tox` job. For example, a common job is `docnb`, which builds HTML pages with [Sphinx](https://www.sphinx-doc.org) using the [`myst-nb`](https://myst-nb.rtfd.io) extension. The corresponding job file for this job is [`docnb.yml`](./.github/workflows/docnb.yml). -- Workflow definitions are located under [`.github/workflows`](./.github/workflows/): GitHub Actions [does not yet support sharing workflows in subdirectories](https://docs.github.com/en/actions/using-workflows/reusing-workflows#creating-a-reusable-workflow). -- Actions are located under directories in the root folder, for example [`pip-install/action.yml`](./pip-install/action.yml). +```shell +git clone https://github.com/ComPWA/actions +cd actions +``` + +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 cd295a3b..a5efc866 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ [![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) This repository hosts [shared workflows for GitHub Actions](https://docs.github.com/en/actions/using-workflows/reusing-workflows) and [shared actions](https://docs.github.com/en/actions/creating-actions) that are used by [repositories of the ComPWA Project](https://github.com/orgs/ComPWA/repositories). See also [ComPWA/repo-maintenance](https://github.com/ComPWA/repo-maintenance), which enforces policies on those repositories. diff --git a/environment.yml b/environment.yml deleted file mode 100644 index ce392399..00000000 --- a/environment.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: compwa-actions -channels: - - defaults -dependencies: - - python==3.12.* - - pip - - pip: - - -e .[dev] -variables: - PRETTIER_LEGACY_CLI: 1 diff --git a/pyproject.toml b/pyproject.toml index 14e45ad0..ef1ce377 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,14 +4,6 @@ requires = ["setuptools>=61.2"] [project] authors = [{name = "Common Partial Wave Analysis", email = "compwa-admin@ep1.rub.de"}] -classifiers = [ - "Development Status :: 4 - Beta", - "Intended Audience :: Developers", - "Natural Language :: English", - "Operating System :: OS Independent", - "Programming Language :: Python :: 3.12", - "Programming Language :: Python", -] dependencies = ["packaging"] description = "Python scripts used by the ComPWA/actions repository" dynamic = ["version"] @@ -24,7 +16,7 @@ dev = [ "compwa-actions[sty]", ] sty = [ - "pre-commit", + "pre-commit-uv", "ruff", ] @@ -37,6 +29,9 @@ include-package-data = false license-files = ["LICENSE"] [tool.pyright] +exclude = [ + "**/.venv/", +] reportMissingTypeArgument = false reportUnknownArgumentType = false reportUnknownMemberType = false @@ -47,7 +42,6 @@ typeCheckingMode = "strict" [tool.ruff] preview = true show-fixes = true -target-version = "py312" [tool.ruff.format] docstring-code-format = true @@ -100,6 +94,5 @@ sort_first = [ "tool.setuptools", "tool.setuptools_scm", ] -sort_table_keys = true spaces_indent_inline_array = 4 trailing_comma_inline_array = true