Skip to content
Merged
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
13 changes: 10 additions & 3 deletions ccds-help.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,16 @@
{
"choice": "requirements.txt",
"help": {
"description": "Most general, least feature-rich format for use with `pip`.",
"more_information": "[pip docs](https://pip.pypa.io/en/stable/reference/requirements-file-format/)"
}
"description": "Classic format for a list of packages to be installed by `pip`.",
"more_information": "[Docs](https://pip.pypa.io/en/stable/reference/requirements-file-format/)"
}
},
{
"choice": "pyproject.toml",
"help": {
"description": "Modern configuration file for Python projects.",
"more_information": "[Docs](https://packaging.python.org/en/latest/guides/writing-pyproject-toml/)"
}
},
{
"choice": "environment.yml",
Expand Down
1 change: 1 addition & 0 deletions ccds.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
],
"dependency_file": [
"requirements.txt",
"pyproject.toml",
"environment.yml",
"Pipfile"
],
Expand Down
11 changes: 11 additions & 0 deletions ccds/hook_utils/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import tomlkit

packages = [
"pip",
"python-dotenv",
Expand Down Expand Up @@ -40,6 +42,15 @@ def write_dependencies(
f.write("\n".join(lines))
f.write("\n")

elif dependencies == "pyproject.toml":
with open(dependencies, "r") as f:
doc = tomlkit.parse(f.read())
doc["project"].add("dependencies", sorted(packages))
doc["project"]["dependencies"].multiline(True)

with open(dependencies, "w") as f:
f.write(tomlkit.dumps(doc))

Comment on lines +45 to +53
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only thing worth noting here is that folks using 2.1.0 with -c master will get a silent failure populating the pyproject.toml with dependencies. This code block won't exist for them and they won't get a warning about upgrading to 2.2.

elif dependencies == "environment.yml":
with open(dependencies, "w") as f:
lines = [
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ requires-python = ">=3.9"
dependencies = [
"click",
"cookiecutter",
"tomlkit",
]

[project.scripts]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def verify_files(root, config):

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

assert sorted(existing_files) == sorted(expected_files)
assert sorted(existing_files) == sorted(set(expected_files))

for f in existing_files:
assert no_curlies(root / f)
Expand Down
6 changes: 6 additions & 0 deletions {{ cookiecutter.repo_name }}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ requirements:
$(PYTHON_INTERPRETER) -m pip install -U pip
$(PYTHON_INTERPRETER) -m pip install -r requirements.txt
{% endif -%}
{% elif "pyproject.toml" == cookiecutter.dependency_file -%}
{% if "uv" == cookiecutter.environment_manager -%}
uv sync
{% else -%}
pip install -e .
{% endif -%}
{% elif "environment.yml" == cookiecutter.dependency_file -%}
conda env update --name $(PROJECT_NAME) --file environment.yml --prune
{% elif "Pipfile" == cookiecutter.dependency_file -%}
Expand Down
Loading