Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
22 changes: 14 additions & 8 deletions .github/workflows/lockfiles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ jobs:

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

- name: "Update Lockfiles and Open PR"
uses: tedivm/action-python-lockfile-update@v2
with:
pip_extras: "dev"
# This key will bypass workflow limitations to ensure tests are run.
# deploy_key: ${{ secrets.WRITEABLE_DEPLOY_KEY }}
- name: Install Poetry
run: pip install "poetry==1.8.3"

- name: Update Lockfile
run: poetry update

- name: Open PR with updated lockfile
uses: peter-evans/create-pull-request@v7
with:
commit-message: "Update poetry.lock"
branch: chore/update-lockfile
title: "Update poetry.lock"
body: "Automated dependency update via `poetry update`."
delete-branch: true
env:
# Needed to open pull request- automatically set for all actions.
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 3 additions & 1 deletion .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ jobs:
fetch-tags: true
- uses: actions/setup-python@v5
with:
python-version-file: .python-version
python-version: "3.11"
- name: Install Poetry
run: pip install poetry==1.8.3
- name: Install Dependencies
run: make install
- name: Build Wheel
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version-file: .python-version
python-version: "3.11"
- name: Install Poetry
run: pip install poetry==1.8.3
- name: Install Dependencies
run: make install
- name: Test
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ Pipfile.lock
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
poetry.lock

# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
Expand Down
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

53 changes: 34 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,41 @@ postprocessing utilities.
Development is a little weird if you're not used to modern python projects,
especially because [python development and packaging evolves so
quickly](https://dev.to/farcellier/i-migrate-to-poetry-in-2023-am-i-right--115).
To isolate the development environment, `pyenv` and `pip`
install a toolchain locally.
To isolate the development environment, this project uses
[Poetry](https://python-poetry.org/) to manage dependencies, virtual
environments, and lockfiles.

## Setting up

External dependencies (easily installed through [Homebrew](https://brew.sh/) or
another package manager):
- [pyenv](https://github.com/pyenv/pyenv), which will install its own python versions in an isolated environment
- [Poetry](https://python-poetry.org/)
- Python 3.11 or newer

After cloning the repository, run `make pre-commit` to:
- Install the development version of python specified in `.python-version` to
your `pyenv` prefix (default: `~/.pyenv`, configurable with the `PYENV_ROOT`
variable)
- Set up a virtual environment in `.venv` that will contain all the development
dependencies, including a `celerpy` symlink in its environment that will
point to your working copy
- Install pre-commit hooks that use the tools just installed in your virtual
environment.
- Create and/or update the Poetry-managed virtual environment
- Install all project and development dependencies from `poetry.lock`
- Install pre-commit hooks.

If you have multiple Python versions installed, you can select one explicitly
for the project:
```console
$ poetry env use python3.11
```

## Versioning

Package versions are generated dynamically from git tags using
`poetry-dynamic-versioning`.

- Tagged commits produce release versions (for example `v0.2.0` -> `0.2.0`)
- Untagged commits use a derived pre-release/dev form from git history

To create a new release tag:
```console
$ git tag v0.2.0
$ git push origin v0.2.0
```

## Testing and committing

Expand All @@ -43,14 +60,12 @@ automatically. (Use `git commit --no-verify` to disable.)
The makefile specifies a few useful targets:
- `style`: apply style fixups to all the python files in development
- `test`: run tests
- `pip`: reinstall all the dependencies in your virtual environment
- `rebuild_dependencies`: update the `requirements` file if you add a new
dependency to `pyproject.toml`
- `install`: install/update dependencies with Poetry
- `rebuild_dependencies`: update dependencies and refresh `poetry.lock`

You can also test independently once your virtual environment is set up. For
example, to run a single python test function from a single python test, with
the most verbose output and sending stdout/stderr to the console, run:
You can also run tools directly through Poetry. For example, to run a single
python test function from a single python test, with verbose output and sending
stdout/stderr to the console, run:
```console
$ . .venv/bin/activate
$ pytest -vv -s test/test_process.py -k test_context
$ poetry run pytest -vv -s test/test_process.py -k test_context
```
10 changes: 5 additions & 5 deletions celerpy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Copyright 2024 UT-Battelle, LLC, and other Celeritas developers.
# See the top-level LICENSE file for details.
# SPDX-License-Identifier: Apache-2.0
try:
from . import _version # type: ignore[attr-defined]
from importlib.metadata import PackageNotFoundError, version

__version__ = _version.__version__
except: # noqa: E722
__version__ = "0.0.0-dev"
try:
__version__ = version("celerpy")
except PackageNotFoundError:
__version__ = "0.1.0-dev"

# Expose __version__ for type checkers
__all__ = ["__version__"]
4 changes: 2 additions & 2 deletions celerpy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ def load_settings():

def print_version(value: bool):
if value:
from . import _version
from . import __version__

typer.echo(_version.version)
typer.echo(__version__)
raise typer.Exit()


Expand Down
79 changes: 16 additions & 63 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,59 +1,22 @@
PACKAGE_SLUG=celerpy
ifdef CI
PYENV_TARGET:=
PYENV_PYTHON=python
PYTHON_VERSION:=$(shell $(PYENV_PYTHON) --version|cut -d" " -f2)
else
PYENV_TARGET:=pyenv
PYENV_PYTHON:=pyenv exec python
PYTHON_VERSION:=$(shell cat .python-version)
endif

ifeq ($(USE_SYSTEM_PYTHON), true)
PYTHON_PACKAGE_PATH:=$(shell $(PYENV_PYTHON) -c "import sys; print(sys.path[-1])")
PYTHON_ENV:=
VENV_TARGET:=
else
PYTHON_SHORT_VERSION:=$(shell echo $(PYTHON_VERSION) | grep -o '[0-9].[0-9]*')
PYTHON_PACKAGE_PATH:=.venv/lib/python$(PYTHON_SHORT_VERSION)/site-packages
PYTHON_ENV:= . .venv/bin/activate &&
VENV_TARGET:= .venv
endif

PYTHON:=$(PYTHON_ENV) python

# Used to confirm that pip has run at least once
BUILD_DIR:=$(PYTHON_PACKAGE_PATH)/build
PYTHON:=poetry run python
PYTHON_ENV:=poetry run

.PHONY: all
all: $(PYENV_TARGET) $(BUILD_DIR)
all: poetry.lock

.PHONY: install
install: $(PYENV_TARGET) $(VENV_TARGET) pip
install: poetry-install

.PHONY: pyenv
pyenv:
pyenv install --skip-existing $(PYTHON_VERSION)
.PHONY: poetry-install
poetry-install:
poetry install
Comment on lines 8 to +13

.venv:
$(PYENV_PYTHON) -m venv .venv
poetry.lock: pyproject.toml
poetry lock


# Note that CI is defined when running through github actions
.PHONY: pip
pip: $(VENV_TARGET) pip-install

.PHONY: pip-install
pip-install:
ifdef CI
$(PYTHON) -m pip install -r requirements-dev.txt
else
$(PYTHON) -m pip install -e .[dev]
endif

$(BUILD_DIR): $(VENV_TARGET) pip-install
.PHONY: pre-commit
pre-commit: $(BUILD_DIR)
pre-commit: poetry.lock
$(PYTHON_ENV) pre-commit install

#
Expand All @@ -77,13 +40,13 @@ style/dapperdata:

.PHONY: style/tomlsort
style/tomlsort:
$(PYTHON_ENV) toml-sort $$(find . -not -path "./.venv/*" -name "*.toml") -i
$(PYTHON_ENV) toml-sort $$(find . -name "*.toml") -i

#
# Testing
#
.PHONY: test
test: $(BUILD_DIR) test/all
test: poetry.lock test/all

.PHONY: test/all
test/all: test/pytest test/ruff test/black test/mypy test/dapperdata test/tomlsort
Expand Down Expand Up @@ -114,28 +77,18 @@ test/dapperdata:

.PHONY: test/tomlsort
test/tomlsort:
$(PYTHON_ENV) toml-sort $$(find . -not -path "./.venv/*" -name "*.toml") --check
$(PYTHON_ENV) toml-sort $$(find . -name "*.toml") --check

#
# Dependencies
#
.PHONY: rebuild_dependencies
rebuild_dependencies:
$(PYTHON) -m uv pip compile --output-file=requirements.txt pyproject.toml
$(PYTHON) -m uv pip compile --output-file=requirements-dev.txt --extra=dev pyproject.toml

.PHONY: dependencies
dependencies: requirements.txt requirements-dev.txt

requirements.txt: $(BUILD_DIR) pyproject.toml
$(PYTHON) -m uv pip compile --upgrade --output-file=requirements.txt pyproject.toml

requirements-dev.txt: $(BUILD_DIR) pyproject.toml
$(PYTHON) -m uv pip compile --upgrade --output-file=requirements-dev.txt --extra=dev pyproject.toml
poetry update

#
# Packaging
#
.PHONY: build
build: $(BUILD_DIR)
$(PYTHON) -m build
build: poetry.lock
poetry build
89 changes: 41 additions & 48 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,48 +1,54 @@
[build-system]
build-backend = "setuptools.build_meta"
requires = ["setuptools>=67.0", "setuptools_scm[toml]>=7.1"]
build-backend = "poetry_dynamic_versioning.backend"
requires = [
"poetry-core>=2.0.0,<3.0.0",
"poetry-dynamic-versioning>=1.9.1,<2.0.0"
]

[project]
authors = [{"name" = "Seth R. Johnson et al."}]
[tool.mypy]
plugins = [
"pydantic.mypy"
]

[tool.poetry]
authors = ["Seth R. Johnson et al."]
description = ""
dynamic = ["version"]
license = {"file" = "LICENSE"}
license = "Apache-2.0"
name = "celerpy"
readme = {file = "README.md", content-type = "text/markdown"}
dependencies = [
"pydantic~=2.0",
"pydantic-settings",
"matplotlib>=3.7",
"numpy>=1.20",
"typer"
]
packages = [{include = "celerpy"}]
readme = "README.md"
requires-plugins = {poetry-dynamic-versioning = {version = ">=1.9.1,<2.0.0", extras = ["plugin"]}}
version = "0.0.0"

[project.optional-dependencies]
dev = [
"build",
"dapperdata",
"glom",
"mypy",
"pre-commit",
"pytest",
"pytest-cov",
"pytest-pretty",
"ruamel.yaml",
"ruff",
"toml-sort",
"uv"
]
[tool.poetry.dependencies]
matplotlib = ">=3.7"
numpy = ">=1.20"
pydantic = ">=2.0,<3.0"
pydantic-settings = ">=2.0,<3.0"
python = ">=3.11,<4.0"
typer = "*"

[tool.poetry.group.dev.dependencies]
dapperdata = "0.4.0"
glom = "24.11.0"
mypy = "1.18.2"
pre-commit = "4.3.0"
pytest = "8.4.2"
pytest-cov = "7.0.0"
pytest-pretty = "1.3.0"
"ruamel.yaml" = "0.18.15"
ruff = "0.13.3"
toml-sort = "0.24.3"

[project.scripts]
[tool.poetry.scripts]
celerpy = "celerpy.cli:app"

[tool.mypy]
plugins = [
"pydantic.mypy"
]
[tool.poetry-dynamic-versioning]
enable = true
vcs = "git"
style = "semver"

[tool.ruff]
exclude = [".venv", "./celerpy/_version.py"]
line-length = 80
indent-width = 4

Expand All @@ -61,16 +67,3 @@ select = [
# isort
"I"
]

[tool.setuptools.dynamic]
readme = {file = ["README.md"]}

[tool.setuptools.package-data]
celerpy = ["py.typed"]

[tool.setuptools.packages]
find = {}

[tool.setuptools_scm]
fallback_version = "0.0.0-dev"
write_to = "celerpy/_version.py"
Loading
Loading