Skip to content

Commit 3cfe39f

Browse files
authored
Add pyproject.toml as a dependencies file option (#436)
* Add pyproject.toml option for dependencies file * Update make requirements * Prefer uv sync over uv pip install * Deduplicate in verify_files * Update configuration * Undo whitespace changes * Undo whitespace change * Shouldn't need set on existing_files --------- Co-authored-by: Jay Qi <[email protected]>
1 parent 9005cb5 commit 3cfe39f

File tree

6 files changed

+30
-4
lines changed

6 files changed

+30
-4
lines changed

ccds-help.json

+10-3
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,16 @@
166166
{
167167
"choice": "requirements.txt",
168168
"help": {
169-
"description": "Most general, least feature-rich format for use with `pip`.",
170-
"more_information": "[pip docs](https://pip.pypa.io/en/stable/reference/requirements-file-format/)"
171-
}
169+
"description": "Classic format for a list of packages to be installed by `pip`.",
170+
"more_information": "[Docs](https://pip.pypa.io/en/stable/reference/requirements-file-format/)"
171+
}
172+
},
173+
{
174+
"choice": "pyproject.toml",
175+
"help": {
176+
"description": "Modern configuration file for Python projects.",
177+
"more_information": "[Docs](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/)"
178+
}
172179
},
173180
{
174181
"choice": "environment.yml",

ccds.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
],
2121
"dependency_file": [
2222
"requirements.txt",
23+
"pyproject.toml",
2324
"environment.yml",
2425
"Pipfile"
2526
],

ccds/hook_utils/dependencies.py

+11
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import tomlkit
2+
13
packages = [
24
"pip",
35
"python-dotenv",
@@ -40,6 +42,15 @@ def write_dependencies(
4042
f.write("\n".join(lines))
4143
f.write("\n")
4244

45+
elif dependencies == "pyproject.toml":
46+
with open(dependencies, "r") as f:
47+
doc = tomlkit.parse(f.read())
48+
doc["project"].add("dependencies", sorted(packages))
49+
doc["project"]["dependencies"].multiline(True)
50+
51+
with open(dependencies, "w") as f:
52+
f.write(tomlkit.dumps(doc))
53+
4354
elif dependencies == "environment.yml":
4455
with open(dependencies, "w") as f:
4556
lines = [

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ requires-python = ">=3.9"
3232
dependencies = [
3333
"click",
3434
"cookiecutter",
35+
"tomlkit",
3536
]
3637

3738
[project.scripts]

tests/test_creation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def verify_files(root, config):
146146

147147
existing_files = [f.relative_to(root) for f in root.glob("**/*") if f.is_file()]
148148

149-
assert sorted(existing_files) == sorted(expected_files)
149+
assert sorted(existing_files) == sorted(set(expected_files))
150150

151151
for f in existing_files:
152152
assert no_curlies(root / f)

{{ cookiecutter.repo_name }}/Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ requirements:
2121
$(PYTHON_INTERPRETER) -m pip install -U pip
2222
$(PYTHON_INTERPRETER) -m pip install -r requirements.txt
2323
{% endif -%}
24+
{% elif "pyproject.toml" == cookiecutter.dependency_file -%}
25+
{% if "uv" == cookiecutter.environment_manager -%}
26+
uv sync
27+
{% else -%}
28+
pip install -e .
29+
{% endif -%}
2430
{% elif "environment.yml" == cookiecutter.dependency_file -%}
2531
conda env update --name $(PROJECT_NAME) --file environment.yml --prune
2632
{% elif "Pipfile" == cookiecutter.dependency_file -%}

0 commit comments

Comments
 (0)