Skip to content

Commit

Permalink
DX: define developer environment with uv (#103)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub <[email protected]>
  • Loading branch information
redeboer and web-flow authored Oct 18, 2024
1 parent 58d7081 commit 84f990d
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 70 deletions.
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"ignorePaths": [
"**/.cspell.json",
".editorconfig",
".envrc",
".gitignore",
".pre-commit-config.yaml",
".prettierignore",
Expand Down
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ trim_trailing_whitespace = true

[*.{py,toml}]
indent_size = 4

[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
2 changes: 1 addition & 1 deletion .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions .github/workflows/clean-caches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
11 changes: 10 additions & 1 deletion .github/workflows/lock.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-drafter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
.eggs/

# Temporary files
condaenv.*.requirements.txt
node_modules/
uv.lock
57 changes: 26 additions & 31 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
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
hooks:
- 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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
29 changes: 22 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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
```
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
10 changes: 0 additions & 10 deletions environment.yml

This file was deleted.

15 changes: 4 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ requires = ["setuptools>=61.2"]

[project]
authors = [{name = "Common Partial Wave Analysis", email = "[email protected]"}]
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"]
Expand All @@ -24,7 +16,7 @@ dev = [
"compwa-actions[sty]",
]
sty = [
"pre-commit",
"pre-commit-uv",
"ruff",
]

Expand All @@ -37,6 +29,9 @@ include-package-data = false
license-files = ["LICENSE"]

[tool.pyright]
exclude = [
"**/.venv/",
]
reportMissingTypeArgument = false
reportUnknownArgumentType = false
reportUnknownMemberType = false
Expand All @@ -47,7 +42,6 @@ typeCheckingMode = "strict"
[tool.ruff]
preview = true
show-fixes = true
target-version = "py312"

[tool.ruff.format]
docstring-code-format = true
Expand Down Expand Up @@ -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

0 comments on commit 84f990d

Please sign in to comment.