|
8 | 8 |
|
9 | 9 | from jinja2 import Environment |
10 | 10 | from jinja2.ext import Extension |
11 | | -from rich.text import Text |
12 | 11 |
|
13 | | -from sprout import GitDefaultsExtension, Question, Style, validate_repository_url |
14 | | -from sprout.cli import render_templates |
15 | | -from sprout.prompt import console |
| 12 | +from sprout import GitDefaultsExtension, Question, validate_repository_url |
16 | 13 |
|
17 | 14 |
|
18 | 15 | class PythonVersionExtension(Extension): |
@@ -42,27 +39,6 @@ def __init__(self, environment: Environment): |
42 | 39 | environment.globals["current_year"] = date.today().year |
43 | 40 |
|
44 | 41 |
|
45 | | -def should_skip(relative_path: Path, answers: dict[str, Any]) -> bool: |
46 | | - as_posix = relative_path.as_posix() |
47 | | - github_actions = answers.get("github_actions", []) |
48 | | - |
49 | | - if as_posix == "LICENSE.jinja" and answers.get("copyright_license") == "None": |
50 | | - return True |
51 | | - if ( |
52 | | - as_posix == ".github/workflows/tests.yml.jinja" |
53 | | - and "tests" not in github_actions |
54 | | - ): |
55 | | - return True |
56 | | - if as_posix == ".github/workflows/lint.yml.jinja" and "lint" not in github_actions: |
57 | | - return True |
58 | | - if ( |
59 | | - as_posix == ".github/workflows/publish.yml.jinja" |
60 | | - and "publish" not in github_actions |
61 | | - ): |
62 | | - return True |
63 | | - return False |
64 | | - |
65 | | - |
66 | 42 | def validate_package_name( |
67 | 43 | value: str, answers: dict[str, Any] |
68 | 44 | ) -> tuple[bool, str | None]: |
@@ -179,6 +155,29 @@ def _python_identifier(name: str) -> str: |
179 | 155 | ] |
180 | 156 |
|
181 | 157 |
|
| 158 | +def should_skip_file(relative_path: str, answers: dict[str, Any]) -> bool: |
| 159 | + github_actions = answers.get("github_actions", []) |
| 160 | + |
| 161 | + if relative_path == "LICENSE.jinja" and answers.get("copyright_license") == "None": |
| 162 | + return True |
| 163 | + if ( |
| 164 | + relative_path == ".github/workflows/tests.yml.jinja" |
| 165 | + and "tests" not in github_actions |
| 166 | + ): |
| 167 | + return True |
| 168 | + if ( |
| 169 | + relative_path == ".github/workflows/lint.yml.jinja" |
| 170 | + and "lint" not in github_actions |
| 171 | + ): |
| 172 | + return True |
| 173 | + if ( |
| 174 | + relative_path == ".github/workflows/publish.yml.jinja" |
| 175 | + and "publish" not in github_actions |
| 176 | + ): |
| 177 | + return True |
| 178 | + return False |
| 179 | + |
| 180 | + |
182 | 181 | def questions(env: Environment, destination: Path) -> list[Question]: |
183 | 182 | git_user_name = env.globals.get("git_user_name", "") |
184 | 183 | git_user_email = env.globals.get("git_user_email", "") |
@@ -320,7 +319,6 @@ def default_python_default_version(answers: dict[str, Any]) -> str: |
320 | 319 | Question( |
321 | 320 | key="copyright_license", |
322 | 321 | prompt="Project license", |
323 | | - help="Select 'None' to skip generating a license file.", |
324 | 322 | choices=license_choices, |
325 | 323 | default="None", |
326 | 324 | ), |
@@ -349,28 +347,4 @@ def default_python_default_version(answers: dict[str, Any]) -> str: |
349 | 347 | ) |
350 | 348 |
|
351 | 349 |
|
352 | | -def apply( |
353 | | - *, |
354 | | - env: Environment, |
355 | | - template_dir: Path, |
356 | | - destination: Path, |
357 | | - answers: dict[str, Any], |
358 | | - style: Style, |
359 | | -) -> Sequence[Path]: |
360 | | - """Render the `template/` directory into the destination using answers. |
361 | | -
|
362 | | - Also renders Jinja expressions in path names (folders/files). |
363 | | - Returns the list of created paths for Sprout to summarize. |
364 | | - """ |
365 | | - template_root = template_dir / "template" |
366 | | - |
367 | | - created = render_templates( |
368 | | - None, |
369 | | - template_root, |
370 | | - destination, |
371 | | - answers, |
372 | | - skip=should_skip, |
373 | | - render_paths=True, |
374 | | - extensions=extensions, |
375 | | - ) |
376 | | - return list(created) |
| 350 | +template_dir = "template" |
0 commit comments