Skip to content

Commit

Permalink
chore: use dependency-groups
Browse files Browse the repository at this point in the history
Signed-off-by: Henry Schreiner <[email protected]>
  • Loading branch information
henryiii committed Jan 29, 2025
1 parent df21e44 commit 3a86baa
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 77 deletions.
15 changes: 9 additions & 6 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ package is in a virtual environment. This is how you would set one up with
Python's built-in venv:

```bash
python3 -m venv .env
source ./.env/bin/activate
pip install -U pip
pip install -ve .[all]
python3 -m venv .venv
source ./.venv/bin/activate
pip install dependency-groups
pip-install-dependency-groups dev
pip install -ve.
```

<details><summary>Optional: External Jupyter kernel (click to expand)</summary>
Expand Down Expand Up @@ -109,7 +110,8 @@ Here is the recommendation for a CMake install:
```bash
python3 -m venv env_cmake
source ./env_cmake/bin/activate
pip install -r dev-requirements.txt
pip install dependency-groups
pip-install-dependency-groups dev
cmake -S . -B build-debug \
-GNinja \
-DCMAKE_INSTALL_PREFIX=$(python -c "import distutils.sysconfig; print(distutils.sysconfig.get_python_lib(plat_specific=False,standard_lib=False))")
Expand Down Expand Up @@ -285,7 +287,8 @@ This requires LLVM 9+, and is based on [this post](https://aras-p.info/blog/2019
brew install llvm # macOS way to get clang-9
python3 -m venv .env_core # general environment (no install will be made)
. .env_core/bin/activate
pip install -r dev-requirements.txt
pip install dependency-groups
pip-install-dependency-groups dev
CXX="/usr/local/opt/llvm/bin/clang++" cmake -S . -B build-llvm \
-DCMAKE_CXX_FLAGS="-ftime-trace" \
-DPYTHON_EXECUTABLE=$(which python)
Expand Down
14 changes: 6 additions & 8 deletions .github/workflows/examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
paths:
- "examples/*.py"
- "notebooks/*.ipynb"
- ".github/workflows/examples.yml"
push:
branches:
- master
Expand All @@ -21,13 +22,10 @@ jobs:
- uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Pre-install NumPy
run: python -m pip install -r dev-requirements.txt nbconvert ipykernel
- name: Install kernel
run: python -m ipykernel install --user --name boost-hist
- name: Build
run: python -m pip install .[examples]
- uses: astral-sh/setup-uv@v4
- name: Build and install kernel
run: uv run --group examples -m ipykernel install --user --name boost-hist
- name: Examples
run: for f in examples/*.py; do python "$f"; done
run: for f in examples/*.py; do uv run "$f"; done
- name: Notebooks
run: jupyter nbconvert --execute --ExecutePreprocessor.timeout=90 --inplace notebooks/*.ipynb
run: uv run jupyter nbconvert --execute --ExecutePreprocessor.timeout=90 --inplace notebooks/*.ipynb
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ jobs:
key: ${{ matrix.python-version }}
create-symlink: true

- name: Make requirements.txt
run: |
uv pip install --system dependency-groups
dependency-groups dev > dev-requirements.txt
- name: Install python tools
run: uv pip install --system -r dev-requirements.txt pytest-github-actions-annotate-failures
env:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/weekly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ jobs:

- uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"

- name: Build and install wheel
run: pip install -v .[test]
run: |
pip install dependency-groups
pip-install-dependency-groups test
pip install -v .
- name: Test
run: python -m pytest
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ repos:
- id: debug-statements
- id: end-of-file-fixer
- id: mixed-line-ending
- id: requirements-txt-fixer
- id: trailing-whitespace

- repo: https://github.com/cheshirekow/cmake-format-precommit
Expand Down
20 changes: 7 additions & 13 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,14 @@
version: 2

build:
os: ubuntu-22.04
os: "ubuntu-22.04"
tools:
python: "3"

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# Include PDF and ePub
formats: all

python:
install:
- requirements: docs/requirements.txt
python: "3.12"
commands:
- asdf plugin add uv
- asdf install uv latest
- asdf global uv latest
- uv run --only-group docs sphinx-build -T -b html -d docs/_build/doctrees -D language=en docs $READTHEDOCS_OUTPUT/html

submodules:
exclude: all
7 changes: 0 additions & 7 deletions dev-requirements.txt

This file was deleted.

8 changes: 3 additions & 5 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
import contextlib
import importlib.metadata
import shutil
import sys
from pathlib import Path
Expand All @@ -31,11 +32,8 @@
copyright = "2020, Henry Schreiner, Hans Dembinski"
author = "Henry Schreiner, Hans Dembinski"

# It is better to use pkg_resources, but we can't build on RtD
from pkg_resources import DistributionNotFound, get_distribution

with contextlib.suppress(DistributionNotFound):
version = get_distribution("boost_histogram").version
with contextlib.suppress(ModuleNotFoundError):
version = importlib.metadata.version("boost_histogram")
# passed if no version (latest/git hash)


Expand Down
7 changes: 0 additions & 7 deletions docs/requirements.txt

This file was deleted.

39 changes: 26 additions & 13 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,55 @@

import argparse
from pathlib import Path
from typing import Any

import nox

nox.needs_version = ">=2024.3.2"
nox.needs_version = ">=2024.4.15"
nox.options.default_venv_backend = "uv|virtualenv"
nox.options.sessions = ["lint", "tests"]


@nox.session
def _get_group(name: str, groups: dict[str, Any]) -> list[str]:
group = groups[name]
return [d if isinstance(d, str) else _get_group(d, groups) for d in group]


def dependency_groups(pyproject: dict[str, Any], *names: str) -> list[str]:
groups = pyproject["dependency-groups"]
return [item for name in names for item in _get_group(name, groups)]


def tests(session: nox.Session) -> None:
"""
Run the unit and regular tests.
"""

session.install(".[test]")
pyproject = nox.project.load_toml("pyproject.toml")
session.install(".", *dependency_groups(pyproject, "test"))
session.run("pytest", *session.posargs)


@nox.session
@nox.session(default=False)
def hist(session: nox.Session) -> None:
"""
Run Hist's test suite
"""
pyproject = nox.project.load_toml("pyproject.toml")
session.install(".")
tmpdir = session.create_tmp()
session.chdir(tmpdir)
session.run("git", "clone", "https://github.com/scikit-hep/hist", external=True)
session.chdir("hist")
session.install(".[test,plot]")
session.install(".", *dependency_groups(pyproject, "test", "plot"))
session.run("pip", "list")
session.run("pytest", *session.posargs)


@nox.session(reuse_venv=True)
@nox.session(reuse_venv=True, default=False)
def docs(session: nox.Session) -> None:
"""
Build the docs. Pass --non-interactive to avoid serving. Pass "-b linkcheck" to check links.
"""
pyproject = nox.project.load_toml("pyproject.toml")

parser = argparse.ArgumentParser()
parser.add_argument(
Expand All @@ -49,7 +60,7 @@ def docs(session: nox.Session) -> None:
serve = args.builder == "html" and session.interactive

extra_installs = ["sphinx-autobuild"] if serve else []
session.install("-r", "docs/requirements.txt", *extra_installs)
session.install(*dependency_groups(pyproject, "docs"), *extra_installs)

shared_args = (
"-n", # nitpicky mode
Expand All @@ -67,13 +78,14 @@ def docs(session: nox.Session) -> None:
session.run("sphinx-build", "--keep-going", *shared_args)


@nox.session
@nox.session(default=False)
def build_api_docs(session: nox.Session) -> None:
"""
Build (regenerate) API docs.
"""
pyproject = nox.project.load_toml("pyproject.toml")

session.install(".", "-r", "docs/requirements.txt")
session.install(*dependency_groups(pyproject, "docs"))
session.run(
"sphinx-apidoc",
"-o",
Expand Down Expand Up @@ -121,10 +133,11 @@ def pylint(session: nox.Session) -> None:
session.run("pylint", "boost_histogram", *session.posargs)


@nox.session
@nox.session(default=False)
def make_pickle(session: nox.Session) -> None:
"""
Make a pickle file for this version
"""
session.install(".[dev]")
pyproject = nox.project.load_toml("pyproject.toml")
session.install(".", *dependency_groups(pyproject, "dev"))
session.run("python", "tests/pickles/make_pickle.py", *session.posargs)
31 changes: 16 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,29 @@ dependencies = [
"numpy",
]

[project.optional-dependencies]
[project.urls]
"Bug Tracker" = "https://github.com/scikit-hep/boost-histogram/issues"
Changelog = "https://boost-histogram.readthedocs.io/en/latest/CHANGELOG.html"
Chat = " https://gitter.im/HSF/PyHEP-histogramming"
Discussions = "https://github.com/scikit-hep/boost-histogram/discussions"
Documentation = "https://boost-histogram.readthedocs.io/"
Homepage = "https://github.com/scikit-hep/boost-histogram"

[dependency-groups]
dev = [
"cloudpickle",
"hypothesis>=6.0",
{ include-group = "test" },
"ipykernel",
"pytest-benchmark",
"pytest>=6.0",
"nbconvert",
"setuptools_scm",
"typer",
]
docs = [
"ipython",
"myst_parser>=0.13",
"nbsphinx",
"numpy",
"sphinx-book-theme>=0.0.33",
"Sphinx>=4.0",
"sphinx>=4.0",
"sphinx_copybutton",
]
examples = [
Expand All @@ -81,14 +90,6 @@ test = [
"pytest>=6.0",
]

[project.urls]
"Bug Tracker" = "https://github.com/scikit-hep/boost-histogram/issues"
Changelog = "https://boost-histogram.readthedocs.io/en/latest/CHANGELOG.html"
Chat = " https://gitter.im/HSF/PyHEP-histogramming"
Discussions = "https://github.com/scikit-hep/boost-histogram/discussions"
Documentation = "https://boost-histogram.readthedocs.io/"
Homepage = "https://github.com/scikit-hep/boost-histogram"


[tool.scikit-build]
minimum-version = "build-system.requires"
Expand Down Expand Up @@ -159,7 +160,7 @@ ignore_missing_imports = true

[tool.cibuildwheel]
build-frontend = "build[uv]"
test-extras = "test"
test-groups = ["test"]
test-command = "pytest --benchmark-disable {project}/tests"
skip = [
"pp38-*",
Expand Down

0 comments on commit 3a86baa

Please sign in to comment.