Skip to content

Commit 0f6b163

Browse files
authored
Add poetry as an env manager (#460)
* add poetry as an env manager * Bump version * Add checklist for release process * add poetry build system * Tweak poetry help text to print properly
1 parent 435e0b3 commit 0f6b163

File tree

12 files changed

+113
-2
lines changed

12 files changed

+113
-2
lines changed

.github/workflows/tests.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ jobs:
8181
cache: false
8282
run-install: false
8383

84+
- name: Set up Poetry
85+
uses: abatilo/actions-poetry@v3
86+
with:
87+
poetry-version: latest
88+
8489
- name: Cache conda packages
8590
uses: actions/cache@v4
8691
env:
@@ -125,6 +130,8 @@ jobs:
125130
virtualenv --version
126131
which pixi
127132
pixi --version
133+
which poetry
134+
poetry --version
128135
which python
129136
python --version
130137
python -c "import platform; print(f'Python architecture: {platform.architecture()}')"

HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# cookiecutter-data-science Changelog
22

3+
## v2.3.0 (2025-07-23)
4+
5+
- Added `pixi` as a new environment manager option (supports `pyproject.toml` and `pixi.toml`). (PR [#459](https://github.com/drivendataorg/cookiecutter-data-science/pull/459), Issue [#406](https://github.com/drivendataorg/cookiecutter-data-science/issues/406))
6+
- Added `poetry` as a new environment manager option (supports `pyproject.toml`). (PR [#460](https://github.com/drivendataorg/cookiecutter-data-science/pull/460), Issue [#374](https://github.com/drivendataorg/cookiecutter-data-science/issues/374))
7+
38
## v2.2.0 (2025-03-23)
49

510
- Added `pyproject.toml` as a dependencies file format option. (PR [#436](https://github.com/drivendataorg/cookiecutter-data-science/pull/436))

RELEASING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@ To give the utility and the template a bit more stability, PR [#336](https://git
88

99
## Issuing a new release
1010

11+
- [ ] Update version in `pyproject.toml` file
12+
- [ ] Ensure `HISTORY.md` is up to date with the changes in this release and add version info and release date
13+
- [ ] Create new release on the GitHub [releases page](https://github.com/drivendataorg/cookiecutter-data-science/releases) with the tag `vMAJOR.MINOR.PATCH` (e.g., `v2.3.0`) and the contents of the relevant `HISTORY.md` section as the release notes.
14+
- [ ] Confirm release action runs successfully and the new release is available on [PyPI](https://pypi.org/project/cookiecutter-data-science/).
15+
1116
`ccds` uses [semantic versioning](https://semver.org/). When issuing a new release, **ensure that your release version tag has the format `vMAJOR.MINOR.PATCH`. The `v` prefix is important because the utility will look for the tag with that name to download by default.

ccds-help.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@
154154
"more_information": "[Docs](https://pixi.sh/)"
155155
}
156156
},
157+
{
158+
"choice": "poetry",
159+
"help": {
160+
"description": "A dependency management and packaging tool for Python with lock files for reproducible environments. Uses pyproject.toml for configuration. Requires poetry to be installed as a system binary.",
161+
"more_information": "[Docs](https://python-poetry.org/docs/)"
162+
}
163+
},
157164
{
158165
"choice": "none",
159166
"help": {

ccds.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"pipenv",
1818
"uv",
1919
"pixi",
20+
"poetry",
2021
"none"
2122
],
2223
"dependency_file": [

ccds/hook_utils/dependencies.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,13 @@ def write_dependencies(
178178
doc["project"].add("dependencies", sorted(packages))
179179
doc["project"]["dependencies"].multiline(True)
180180

181+
# poetry uses standard project dependencies, but we should use its build system
182+
if environment_manager == "poetry":
183+
# Update build system to use poetry-core
184+
doc["build-system"] = tomlkit.table()
185+
doc["build-system"]["requires"] = ["poetry-core>=2.0.0,<3.0.0"]
186+
doc["build-system"]["build-backend"] = "poetry.core.masonry.api"
187+
181188
with open(dependencies, "w") as f:
182189
f.write(tomlkit.dumps(doc))
183190

dev-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ mkdocs-gen-files
1212
mkdocs-include-markdown-plugin
1313
pexpect
1414
pipenv
15+
poetry
1516
pytest
1617
termynal
1718
twine

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "ccds"
77

88
[project]
99
name = "cookiecutter-data-science"
10-
version = "2.2.0"
10+
version = "2.3.0"
1111
description = "A logical, reasonably standardized but flexible project structure for doing and sharing data science work."
1212
authors = [
1313
{ name = "DrivenData", email = "info@drivendata.org" },

tests/conftest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ def _is_valid(config):
6262
config["dependency_file"] not in ["pixi.toml", "pyproject.toml"]
6363
):
6464
return False
65+
# poetry only supports pyproject.toml
66+
if (config["environment_manager"] == "poetry") and (
67+
config["dependency_file"] != "pyproject.toml"
68+
):
69+
return False
6570
return True
6671

6772
# remove invalid configs

tests/poetry_harness.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
set -ex
3+
4+
PROJECT_NAME=$(basename $1)
5+
CCDS_ROOT=$(dirname $0)
6+
MODULE_NAME=$2
7+
8+
# Check if poetry is installed
9+
if ! command -v poetry &> /dev/null; then
10+
echo "poetry is not installed. Please install poetry first:"
11+
echo " curl -sSL https://install.python-poetry.org | python3 -"
12+
echo " Or visit: https://python-poetry.org/docs/#installation"
13+
exit 1
14+
fi
15+
16+
# Configure exit / teardown behavior
17+
function finish {
18+
# Cleanup poetry environment if it exists
19+
if poetry env list | grep -q "$(basename $(pwd))"; then
20+
poetry env remove --all
21+
fi
22+
}
23+
trap finish EXIT
24+
25+
# Source the steps in the test
26+
source $CCDS_ROOT/test_functions.sh
27+
28+
cd $1
29+
30+
# Setup and run tests
31+
make
32+
make create_environment
33+
make requirements
34+
35+
# Run poetry-specific tests with simpler commands
36+
poetry run python --version
37+
echo "Testing basic import..."
38+
poetry run python -c "import $MODULE_NAME"
39+
40+
# Test config importable if scaffolded
41+
if [ -f "$MODULE_NAME/config.py" ]; then
42+
echo "Testing config import..."
43+
poetry run python -c "from $MODULE_NAME import config"
44+
fi
45+
46+
# Run linting and formatting through poetry
47+
poetry run make lint
48+
poetry run make format
49+
50+
# Custom poetry test function to avoid issues with test_functions.sh
51+
# Check that python is available in poetry environment
52+
echo "Testing poetry python availability..."
53+
if poetry run python -c "import sys" > /dev/null 2>&1; then
54+
echo "Python is available in poetry environment"
55+
else
56+
echo "ERROR: Python not available in poetry environment"
57+
exit 1
58+
fi
59+
60+
echo "All done!"

0 commit comments

Comments
 (0)