Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: convert dev dependencies to dependency groups #459

Merged
merged 20 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
b6ff45e
MAINT: clean up dependencies
redeboer Oct 28, 2024
bafb28f
MAINT: autoupdate pre-commit hooks
redeboer Oct 28, 2024
ce3ff89
FEAT: convert dev dependencies to dependency groups
redeboer Oct 28, 2024
1bc196e
BEHAVIOR: always install dependencies through `uv export`
redeboer Oct 28, 2024
ac666c9
ENH: remove output `requirements.txt` file
redeboer Oct 28, 2024
223d73e
FIX: install dependency groups in Binder
redeboer Oct 28, 2024
2e565a1
FIX: do not include non-dev groups in include-group
redeboer Oct 28, 2024
4a1b268
BEHAVIOR: switch to `--group` instead of `--extra`
redeboer Oct 28, 2024
31556c5
FIX: include extras in dependency groups
redeboer Oct 28, 2024
da103f6
FIX: call `remove_dependency()` over dependency groups
redeboer Oct 28, 2024
9d29f04
ENH: define `dependency-groups` in `PyprojectTOML`
redeboer Oct 28, 2024
018bb83
ENH: remove `optional-dependencies` and `dependency-groups` if empty
redeboer Oct 28, 2024
146481c
ENH: mark `mypy` as dependency group
redeboer Oct 28, 2024
c3021d1
DX: run `pyright` in `tox -e sty` job
redeboer Oct 28, 2024
2d2c94b
DX: rename `sty` dependency group to `style`
redeboer Oct 28, 2024
bb2bc04
FIX: auto-install dependencies into dependency groups
redeboer Oct 28, 2024
73c7ad5
ENH: install `ruff` into `dev`, not `style`
redeboer Oct 28, 2024
5728283
FIX: update to ComPWA/[email protected]
redeboer Oct 28, 2024
096351f
MAINT: split `add_dependency()` function
redeboer Oct 28, 2024
37fd403
FIX: use `itertools.pairwise()` correctly
redeboer Oct 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
"PyPA",
"pytest",
"PYTHONHASHSEED",
"QRules",
"rtoml",
"sympy",
"toctree",
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ on:

jobs:
doc:
uses: ComPWA/actions/.github/workflows/ci-docs.yml@v2
uses: ComPWA/actions/.github/workflows/ci-docs.yml@v2.1
permissions:
pages: write
id-token: write
with:
gh-pages: true
specific-pip-packages: ${{ inputs.specific-pip-packages }}
pytest:
uses: ComPWA/actions/.github/workflows/pytest.yml@v2
uses: ComPWA/actions/.github/workflows/pytest.yml@v2.1
with:
coverage-target: compwa_policy
macos-python-version: "3.9"
Expand All @@ -45,4 +45,4 @@ jobs:
if: inputs.specific-pip-packages == ''
secrets:
token: ${{ secrets.PAT }}
uses: ComPWA/actions/.github/workflows/pre-commit.yml@v2
uses: ComPWA/actions/.github/workflows/pre-commit.yml@v2.1
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ repos:
- id: check-useless-excludes

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
rev: v0.7.1
hooks:
- id: ruff
args: [--fix]
Expand Down Expand Up @@ -78,7 +78,7 @@ repos:
exclude: (?x)^(labels/.*\.toml)$

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

Expand All @@ -104,6 +104,6 @@ repos:
- python

- repo: https://github.com/ComPWA/pyright-pre-commit
rev: v1.1.384
rev: v1.1.386
hooks:
- id: pyright
57 changes: 28 additions & 29 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,43 @@ maintainers = [{email = "[email protected]"}]
name = "compwa-policy"
requires-python = ">=3.9"

[project.optional-dependencies]
[project.readme]
content-type = "text/markdown"
file = "README.md"

[project.scripts]
check-dev-files = "compwa_policy.check_dev_files:main"
colab-toc-visible = "compwa_policy.colab_toc_visible:main"
fix-nbformat-version = "compwa_policy.fix_nbformat_version:main"
remove-empty-tags = "compwa_policy.remove_empty_tags:main"
self-check = "compwa_policy.self_check:main"
set-nb-cells = "compwa_policy.set_nb_cells:main"

[project.urls]
Source = "https://github.com/ComPWA/policy"
Tracker = "https://github.com/ComPWA/policy/issues"

[dependency-groups]
dev = [
"compwa-policy[doc]",
"compwa-policy[sty]",
"compwa-policy[test]",
"labels",
"ruff",
"sphinx-autobuild",
{include-group = "doc"},
{include-group = "style"},
{include-group = "test"},
]
doc = [
"Sphinx",
"myst-parser",
"sphinx-api-relink >=0.0.4",
"sphinx",
"sphinx-api-relink",
"sphinx-argparse",
"sphinx-book-theme",
"sphinx-codeautolink",
"sphinx-copybutton",
]
sty = [
"compwa-policy[types]",
style = [
"mypy",
"ruff",
{include-group = "types"},
]
test = [
"pytest",
Expand All @@ -59,27 +74,11 @@ test = [
]
types = [
"pytest",
"sphinx-api-relink >=0.0.3",
"sphinx-api-relink",
"types-PyYAML",
"types-toml",
]

[project.readme]
content-type = "text/markdown"
file = "README.md"

[project.scripts]
check-dev-files = "compwa_policy.check_dev_files:main"
colab-toc-visible = "compwa_policy.colab_toc_visible:main"
fix-nbformat-version = "compwa_policy.fix_nbformat_version:main"
remove-empty-tags = "compwa_policy.remove_empty_tags:main"
self-check = "compwa_policy.self_check:main"
set-nb-cells = "compwa_policy.set_nb_cells:main"

[project.urls]
Source = "https://github.com/ComPWA/policy"
Tracker = "https://github.com/ComPWA/policy/issues"

[tool.setuptools]
include-package-data = false
license-files = ["LICENSE"]
Expand Down Expand Up @@ -169,6 +168,8 @@ reportUnusedFunction = true
reportUnusedImport = true
reportUnusedVariable = true
typeCheckingMode = "strict"
venv = ".venv"
venvPath = "."

[tool.pytest.ini_options]
addopts = [
Expand Down Expand Up @@ -358,8 +359,6 @@ setenv =
allowlist_externals =
pre-commit
commands =
pre-commit run {posargs} --all-files
pre-commit run --all-files {posargs}
description = Perform all linting, formatting, and spelling checks
setenv =
SKIP = pyright
"""
6 changes: 3 additions & 3 deletions src/compwa_policy/.github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,18 @@ on:

jobs:
doc:
uses: ComPWA/actions/.github/workflows/ci-docs.yml@v2
uses: ComPWA/actions/.github/workflows/ci-docs.yml@v2.1
permissions:
pages: write
id-token: write
with:
specific-pip-packages: ${{ inputs.specific-pip-packages }}
pytest:
uses: ComPWA/actions/.github/workflows/pytest.yml@v2
uses: ComPWA/actions/.github/workflows/pytest.yml@v2.1
with:
specific-pip-packages: ${{ inputs.specific-pip-packages }}
style:
if: inputs.specific-pip-packages == ''
secrets:
token: ${{ secrets.PAT }}
uses: ComPWA/actions/.github/workflows/pre-commit.yml@v2
uses: ComPWA/actions/.github/workflows/pre-commit.yml@v2.1
88 changes: 34 additions & 54 deletions src/compwa_policy/check_dev_files/binder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
import os
from dataclasses import dataclass
from textwrap import dedent
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any

from compwa_policy.errors import PrecommitError
from compwa_policy.utilities import CONFIG_PATH
from compwa_policy.utilities.executor import Executor
from compwa_policy.utilities.match import git_ls_files
from compwa_policy.utilities.pyproject import Pyproject

if TYPE_CHECKING:
from collections.abc import Mapping
from pathlib import Path

from compwa_policy.check_dev_files.conda import PackageManagerChoice
Expand Down Expand Up @@ -84,28 +84,16 @@ def __get_post_builder_for_pixi_with_uv() -> str:
for script in activation.scripts:
expected_content += "\nbash " + script
expected_content += "\npixi clean cache --yes\n"
notebook_extras = __get_notebook_extras()
if "uv.lock" in set(git_ls_files(untracked=True)):
expected_content += "\nuv export \\"
for extra in notebook_extras:
expected_content += f"\n --extra {extra} \\"
expected_content += dedent(R"""
> requirements.txt
uv pip install \
--requirement requirements.txt \
--system
uv cache clean
""")
else:
package = "."
if notebook_extras:
package = f"'.[{','.join(notebook_extras)}]'"
expected_content += dedent(Rf"""
uv pip install \
--editable {package} \
--no-cache \
--system
""")
expected_content += "\nuv export \\"
for groups in __get_notebook_groups():
expected_content += f"\n --group {groups} \\"
expected_content += dedent(R"""
> requirements.txt
uv pip install \
--requirement requirements.txt \
--system
uv cache clean
""")
return expected_content


Expand Down Expand Up @@ -135,41 +123,33 @@ def __get_post_builder_for_uv() -> str:
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.cargo/env
""").strip()
notebook_extras = __get_notebook_extras()
if "uv.lock" in set(git_ls_files(untracked=True)):
expected_content += "\nuv export \\"
for extra in notebook_extras:
expected_content += f"\n --extra {extra} \\"
expected_content += dedent(R"""
> requirements.txt
uv pip install \
--requirement requirements.txt \
--system
uv cache clean
""")
else:
package = "."
if notebook_extras:
package = f"'.[{','.join(notebook_extras)}]'"
expected_content += dedent(Rf"""
uv pip install \
--editable {package} \
--no-cache \
--system
""")
expected_content += "\nuv export \\"
for group in __get_notebook_groups():
expected_content += f"\n --group {group} \\"
expected_content += dedent(R"""
> requirements.txt
uv pip install \
--requirement requirements.txt \
--system
rm requirements.txt
uv cache clean
""")
return expected_content


def __get_notebook_extras() -> list[str]:
def __get_notebook_groups() -> list[str]:
dependency_groups = ___safe_get_table("dependency-groups")
allowed_groups = {"jupyter", "notebooks"}
return sorted(allowed_groups & set(dependency_groups))


def ___safe_get_table(dotted_header: str) -> Mapping[str, Any]:
if not CONFIG_PATH.pyproject.exists():
return []
return {}
pyproject = Pyproject.load()
table_key = "project.optional-dependencies"
if not pyproject.has_table(table_key):
return []
optional_dependencies = pyproject.get_table(table_key)
allowed_sections = {"jupyter", "notebooks"}
return sorted(allowed_sections & set(optional_dependencies))
if not pyproject.has_table(dotted_header):
return {}
return pyproject.get_table(dotted_header)


def _make_executable(path: Path) -> None:
Expand Down
2 changes: 1 addition & 1 deletion src/compwa_policy/check_dev_files/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ def _update_dev_requirements(no_ruff: bool) -> None:
}
packages.update(ruff_packages)
for package in sorted(packages):
pyproject.add_dependency(package, optional_key=["jupyter", "dev"])
pyproject.add_dependency(package, dependency_group=["jupyter", "dev"])
Loading
Loading