Skip to content

Commit

Permalink
FEAT: switch to uv as default package manager (#424)
Browse files Browse the repository at this point in the history
* BEHAVIOR: use `uv` as default package manager
* BEHAVIOR: write "MAINT: update lock files" in update PRs
* BREAK: generalize `remove_from_gitignore()`
* BREAK: rename `--package-managers` to `--package-manager`
* DX: extend cSpell ignore path list
* DX: add `uv.lock` pre-commit hook
* DX: automatically remove Pixi support if `pixi` not package manager
* ENH: add `.venv` to Pyright excludes
* ENH: add `uv.lock` to EditorConfig
* ENH: add Pixi and `uv` badge
* ENH: add support for environment variables in `.envrc`
* ENH: automatically update `CONTRIBUTING.md` file
* ENH: create `.python-version` file for dev Python version
* ENH: create dedicated `.envrc` for `uv`
* ENH: do not add `myst-highlight` if unwanted
* ENH: ignore `.prettierrc` check if `.prettierrc.yml` already available
* ENH: only set `python.terminal.activateEnvironment` if Python repo
* ENH: only set `rewrap.wrappingColumn` if Python repo
* ENH: run `uv sync` on Read the Docs
* FEAT: add `none` as --package-managers` choice
* FEAT: implement `pixi+uv` environment manager with `pixi.toml`
* FIX: do not open `pyproject.toml` if not existing
* MAINT: autoupdate pre-commit hooks
* MAINT: split `check_dev_files.pixi` sub-module
  • Loading branch information
redeboer authored Oct 14, 2024
1 parent 1fb5e51 commit 9c1ca85
Show file tree
Hide file tree
Showing 38 changed files with 2,550 additions and 325 deletions.
1 change: 0 additions & 1 deletion .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"*.ico",
".editorconfig",
".envrc",
".gitattributes",
".gitignore",
".gitpod.*",
".pre-commit-config.yaml",
Expand Down
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ indent_size = 4

[LICENSE]
indent_size = unset

[uv.lock]
indent_size = 4
12 changes: 2 additions & 10 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,2 @@
if [ -e .venv ]; then
source .venv/bin/activate
elif [ -e venv ]; then
source venv/bin/activate
elif [ -e .pixi ]; then
watch_file pixi.lock
eval "$(pixi shell-hook)"
else
layout anaconda
fi
uv sync --all-extras --quiet
source .venv/bin/activate
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ version.py

# Temporary files
*.pyc
*condaenv.*
.coverage
.coverage.*
.ipynb_checkpoints/
Expand All @@ -35,10 +34,8 @@ prof/

# Virtual environments
*venv/
.pixi/
.tox/
pyvenv*/
pixi.lock

# Settings
.idea/
Expand All @@ -54,5 +51,4 @@ pixi.lock
!.readthedocs.yml
!.vscode/*.json
!codecov.yml
!environment.yml
!pyrightconfig.json
14 changes: 10 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
ci:
autoupdate_commit_msg: "MAINT: autoupdate pre-commit hooks"
autoupdate_commit_msg: "MAINT: update lock files"
autoupdate_schedule: quarterly
skip:
- check-dev-files
- mypy
- pyright
- self-check
- uv-lock

repos:
- repo: meta
Expand All @@ -14,14 +15,14 @@ repos:
- id: check-useless-excludes

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.3
rev: v0.6.9
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 Down Expand Up @@ -79,7 +80,7 @@ repos:
exclude: (?x)^(labels/.*\.toml)$

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

Expand Down Expand Up @@ -108,3 +109,8 @@ repos:
rev: v1.1.384
hooks:
- id: pyright

- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.4.20
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 @@ -16,6 +16,7 @@
"ms-vsliveshare.vsliveshare",
"redhat.vscode-yaml",
"ryanluker.vscode-coverage-gutters",
"samuelcolvin.jinjahtml",
"soulcode.vscode-unwanted-extensions",
"stkb.rewrap",
"streetsidesoftware.code-spell-checker",
Expand Down
5 changes: 1 addition & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@
"coverage-gutters.showLineCoverage": true,
"diffEditor.experimental.showMoves": true,
"editor.formatOnSave": true,
"files.associations": {
"**/pixi.lock": "yaml"
},
"files.watcherExclude": {
"**/*_cache/**": true,
"**/.eggs/**": true,
Expand Down Expand Up @@ -66,7 +63,7 @@
"ruff.organizeImports": true,
"search.exclude": {
"**/tests/**/__init__.py": true,
".constraints/*.txt": true,
"**/uv.lock": true,
".github/workflows/cd.yml": true,
".github/workflows/ci.yml": true,
".taplo.toml": true,
Expand Down
26 changes: 26 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# How to contribute?

[![Open in Visual Studio Code](https://img.shields.io/badge/vscode-open-blue?logo=visualstudiocode)](https://github.dev/ComPWA/policy)

> [!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/policy
cd policy
```

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 @@ -5,6 +5,7 @@
[![pytest](https://github.com/ComPWA/qrules/workflows/pytest/badge.svg)](https://github.com/ComPWA/qrules/actions?query=branch%3Amain+workflow%3Apytest)
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/ComPWA/policy/main.svg)](https://results.pre-commit.ci/latest/github/ComPWA/policy/main)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![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)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

This repository sets the policies for developer environment in repositories if the [ComPWA organization](https://github.com/ComPWA) (See our [Help developing](https://compwa.github.io/develop) page). The policies are automatically enforced through [pre-commit](https://pre-commit.com).
Expand Down
8 changes: 0 additions & 8 deletions environment.yml

This file was deleted.

45 changes: 2 additions & 43 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies = [
"attrs >=20.1.0", # https://www.attrs.org/changelog.html#id82
"html2text",
"ini2toml",
"jinja2",
"nbformat",
"packaging",
"pathspec",
Expand Down Expand Up @@ -134,56 +135,14 @@ module = ["ruamel.*"]
ignore_missing_imports = true
module = ["nbformat.*"]

[tool.pixi.project]
channels = ["conda-forge"]
platforms = ["linux-64"]

[tool.pixi.activation]
env = {PRETTIER_LEGACY_CLI = "1"}

[tool.pixi.dependencies]
python = "3.12.*"

[tool.pixi.environments]
default = {features = [
"dev",
"doc",
"sty",
"test",
"types",
]}

[tool.pixi.feature.dev.tasks.ci]
depends_on = ["cov", "doc", "linkcheck", "sty"]

[tool.pixi.feature.dev.tasks.cov]
cmd = "tox -e cov"

[tool.pixi.feature.dev.tasks.doc]
cmd = "tox -e doc"

[tool.pixi.feature.dev.tasks.doclive]
cmd = "tox -e doclive"

[tool.pixi.feature.dev.tasks.linkcheck]
cmd = "tox -e linkcheck"

[tool.pixi.feature.dev.tasks.sty]
cmd = "pre-commit run --all-files"

[tool.pixi.feature.dev.tasks.tests]
cmd = "pytest"

[tool.pixi.pypi-dependencies]
compwa-policy = {path = ".", editable = true}

[tool.pyright]
exclude = [
"**/.git",
"**/.ipynb_checkpoints",
"**/.mypy_cache",
"**/.pytest_cache",
"**/.tox",
"**/.venv/",
"**/__pycache__",
"**/_build",
]
Expand Down
5 changes: 4 additions & 1 deletion src/compwa_policy/.template/.cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"**/.cspell.json",
"**/Manifest.toml",
"**/Project.toml",
"*.csl",
"*.ico",
"*.root",
"*.svg",
Expand All @@ -31,6 +32,7 @@
".gitattributes",
".gitignore",
".gitpod.*",
".htaccess",
".mypy.ini",
".pre-commit-config.yaml",
".prettierignore",
Expand All @@ -53,7 +55,8 @@
"setup.cfg",
"setup.py",
"tox.ini",
"typings"
"typings",
"update-www"
],
"language": "en-US",
"words": [
Expand Down
26 changes: 26 additions & 0 deletions src/compwa_policy/.template/CONTRIBUTING.md.jinja
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# How to contribute?

[![Open in Visual Studio Code](https://img.shields.io/badge/vscode-open-blue?logo=visualstudiocode)](https://github.dev/ComPWA/{{ REPO_NAME }})

> [!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/{{ REPO_NAME }}
cd {{ REPO_NAME }}
```

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
```
Loading

0 comments on commit 9c1ca85

Please sign in to comment.