Skip to content

Commit

Permalink
DX: define developer environment with uv (#10)
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 ba4e366 commit 78cbbb0
Show file tree
Hide file tree
Showing 18 changed files with 117 additions and 57 deletions.
4 changes: 3 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"ignorePaths": [
"**/.cspell.json",
".editorconfig",
".envrc",
".gitignore",
".pre-commit-config.yaml",
".prettierignore",
Expand All @@ -36,7 +37,8 @@
"prereleased",
"rtfd",
"sphinxcontrib",
"unsrt"
"unsrt",
"venv"
],
"language": "en-US",
"version": "0.2",
Expand Down
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ indent_size = 4

[LICENSE]
indent_size = unset

[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
10 changes: 5 additions & 5 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 }}
21 changes: 21 additions & 0 deletions .github/workflows/lock.yml
Original file line number Diff line number Diff line change
@@ -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 }}
2 changes: 1 addition & 1 deletion .github/workflows/pr-linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ version.py

# Temporary files
*.pyc
*condaenv.*
.coverage
.coverage.*
.ipynb_checkpoints/
Expand All @@ -44,6 +43,7 @@ prof/
*venv/
.tox/
pyvenv*/
uv.lock

# Settings
.idea/
Expand All @@ -59,5 +59,4 @@ pyvenv*/
!.readthedocs.yml
!.vscode/*.json
!codecov.yml
!environment.yml
!pyrightconfig.json
46 changes: 20 additions & 26 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
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
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:
- --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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
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 @@ -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",
Expand Down
6 changes: 4 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -54,13 +54,15 @@
},
"notebook.formatOnSave.enabled": true,
"python.analysis.autoImportCompletions": false,
"python.analysis.typeCheckingMode": "strict",
"python.terminal.activateEnvironment": false,
"python.testing.unittestEnabled": 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"
}
25 changes: 23 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -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
```
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:

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

This file was deleted.

30 changes: 27 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]",
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -102,6 +104,7 @@ exclude = [
"**/.mypy_cache",
"**/.pytest_cache",
"**/.tox",
"**/.venv/",
"**/__pycache__",
"**/_build",
]
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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

0 comments on commit 78cbbb0

Please sign in to comment.