Skip to content

Commit 2202dfb

Browse files
committed
feat: Add support for optional LICENSE file in project generation
1 parent 68f0a2f commit 2202dfb

4 files changed

Lines changed: 55 additions & 0 deletions

File tree

.github/instructions/copier.instructions.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ Quick reference for the `copier` project templating tool.
1515
- **Settings:** https://copier.readthedocs.io/en/stable/settings/
1616
- **FAQ:** https://copier.readthedocs.io/en/stable/faq/
1717

18+
# LICENSE file
19+
- The type of LICENSEs supported can be found here: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository#choosing-the-right-license
20+
1821
## Key Concepts
1922
- Use `copier copy` to generate projects from templates
2023
- Use `copier update` to sync existing projects with template changes

copier.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ dev_deps:
3434
help: "Enter development dependencies as a JSON array"
3535
default: ["pytest", "pytest-cov", "ruff"]
3636

37+
include_license:
38+
type: bool
39+
help: "Include a LICENSE file in the project?"
40+
default: false
41+
3742
_templates_suffix: .jinja
3843
_envops:
3944
block_start_string: "{%"

my_tests/test_optional_license.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Test LICENSE file is optional and excluded by default."""
2+
3+
from __future__ import annotations
4+
5+
from pathlib import Path
6+
7+
import pytest
8+
from conftest import _make_data, _run_copy
9+
10+
11+
@pytest.fixture(scope="module")
12+
def generated_without_license() -> Path:
13+
"""Generate project without LICENSE file (default behavior)."""
14+
data = _make_data({"project_name": "no_license_proj", "include_license": False})
15+
return _run_copy(data, dst_name="no_license")
16+
17+
18+
@pytest.fixture(scope="module")
19+
def generated_with_license() -> Path:
20+
"""Generate project with LICENSE file explicitly requested."""
21+
data = _make_data(
22+
{
23+
"project_name": "with_license_proj",
24+
"include_license": True,
25+
}
26+
)
27+
return _run_copy(data, dst_name="with_license")
28+
29+
30+
def test_license_excluded_by_default(generated_without_license: Path):
31+
"""Test that LICENSE file is NOT included when include_license=false (default)."""
32+
license_path = generated_without_license / "LICENSE"
33+
assert not license_path.exists(), "LICENSE should not exist when include_license=false (default)"
34+
35+
36+
def test_license_included_when_requested(generated_with_license: Path):
37+
"""Test that LICENSE file IS included when include_license=true."""
38+
license_path = generated_with_license / "LICENSE"
39+
assert license_path.is_file(), "LICENSE should exist when include_license=true"
40+
41+
42+
def test_license_content_matches_template(generated_with_license: Path):
43+
"""Test that generated LICENSE file contains expected content."""
44+
license_path = generated_with_license / "LICENSE"
45+
content = license_path.read_text()
46+
assert "MIT License" in content, "LICENSE should contain MIT License header"
47+
assert "Copyright" in content, "LICENSE should contain copyright notice"

LICENSE renamed to {% if include_license %}LICENSE{% endif %}.jinja

File renamed without changes.

0 commit comments

Comments
 (0)