Skip to content

Commit 6beeb1b

Browse files
committed
Generate project_name from destination path
1 parent f0d9453 commit 6beeb1b

File tree

5 files changed

+36
-75
lines changed

5 files changed

+36
-75
lines changed

copier-helper.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ uvx copier copy --defaults --force --trust \
1212
--data author="Switchbox" \
1313
--data email="hello@switch.box" \
1414
--data author_github_handle="switchbox-data" \
15-
--data project_name="example-project" \
1615
--data project_description="Example" \
1716
--data project_features="[python_data_science, python_package]" \
1817
--data use_github=true \

copier.yml

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ author_github_handle:
2020
default: "switchbox-data"
2121
help: Your GitHub handle (without @)
2222

23-
project_name:
24-
type: str
25-
default: "example-project"
26-
help: Project name (also used for repo name)
27-
28-
project_slug:
29-
type: str
30-
default: "{{ project_name|lower|replace('-', '_') }}"
31-
when: false
32-
3323
project_description:
3424
type: str
3525
default: "This is a repository for modern data science projects."
@@ -47,7 +37,7 @@ project_features:
4737
- python_data_science
4838
- python_package
4939
- r_data_science
50-
default: [python_data_science, python_package]
40+
default: [python_data_science ]
5141
help: "Select project features (use space to select/deselect, enter to confirm)"
5242

5343
use_github:
@@ -92,6 +82,17 @@ r_data_science:
9282
default: "{{ 'r_data_science' in project_features }}"
9383
when: false
9484

85+
# Directory name computed from destination path
86+
project_name:
87+
type: str
88+
default: "{{ _copier_conf.dst_path.name }}"
89+
when: false
90+
91+
project_slug:
92+
type: str
93+
default: "{{ project_name|lower|replace('-', '_') }}"
94+
when: false
95+
9596
# Post-generation tasks
9697
_tasks:
9798
- command: git init

docs/usage.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ copier copy --defaults --force \
77
--data author="Your Name" \
88
--data email="you@example.com" \
99
--data author_github_handle="your-gh" \
10-
--data project_name="awesome" \
11-
--data project_slug="awesome" \
1210
--data project_description="Awesome project" \
1311
--data python_data_science="y" --data python_package="y" \
1412
. /path/to/awesome

template/CONTRIBUTING.md.jinja

Lines changed: 0 additions & 61 deletions
This file was deleted.

tests/test_template.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,3 +191,27 @@ def test_python_data_science_notebooks(tmp_path: Path) -> None:
191191
# Ensure template condition is not present in final output
192192
content = (dest / "notebooks/py_example.qmd").read_text()
193193
assert "{% if cookiecutter.pydata == \"y\" %}" not in content, "Template condition should be resolved"
194+
195+
196+
def test_directory_name_in_devcontainer(tmp_path: Path) -> None:
197+
dest = tmp_path / "my_custom_dir"
198+
res = run_copier(
199+
Path(__file__).parents[1],
200+
dest,
201+
{
202+
"author": "Test",
203+
"email": "test@example.com",
204+
"author_github_handle": "test",
205+
"project_name": "different-name", # This is different from directory name
206+
"project_features": "[python_package]",
207+
"use_github": True,
208+
"open_source_license": "MIT license",
209+
"aws": False,
210+
},
211+
)
212+
assert res.returncode == 0, res.stderr
213+
# Check that devcontainer uses actual directory name, not project_name
214+
assert_file_contains(dest, ".devcontainer/devcontainer.json", "/workspaces/my_custom_dir/.venv/bin/python")
215+
# Should NOT contain the project_name in paths
216+
content = (dest / ".devcontainer/devcontainer.json").read_text()
217+
assert "/workspaces/different-name/" not in content

0 commit comments

Comments
 (0)