-
-
Notifications
You must be signed in to change notification settings - Fork 890
Add CLI support for user-provided project scaffold templates #5406
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,6 +17,7 @@ | |||||||||||
|
|
||||||||||||
| import json | ||||||||||||
| import os | ||||||||||||
| import shutil | ||||||||||||
|
|
||||||||||||
| import click | ||||||||||||
|
|
||||||||||||
|
|
@@ -45,13 +46,28 @@ def validate_boards(ctx, param, value): # pylint: disable=unused-argument | |||||||||||
| return value | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| def validate_template_dir(ctx, param, value): # pylint: disable=unused-argument | ||||||||||||
| if not value: | ||||||||||||
| return value | ||||||||||||
| value = os.path.abspath(os.path.normpath(value)) | ||||||||||||
| if not os.access(value, os.R_OK): | ||||||||||||
| raise click.BadParameter("`%s` is not readable" % value) | ||||||||||||
| return value | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| @click.command("init", short_help="Initialize a project or update existing") | ||||||||||||
| @click.option( | ||||||||||||
| "--project-dir", | ||||||||||||
| "-d", | ||||||||||||
| default=os.getcwd, | ||||||||||||
| type=click.Path(exists=True, file_okay=False, dir_okay=True, writable=True), | ||||||||||||
| ) | ||||||||||||
| @click.option( | ||||||||||||
| "--template-dir", | ||||||||||||
| type=click.Path(exists=True, file_okay=False, dir_okay=True, readable=True), | ||||||||||||
| callback=validate_template_dir, | ||||||||||||
| help="Copy files from this directory into a new project", | ||||||||||||
|
||||||||||||
| help="Copy files from this directory into a new project", | |
| help=( | |
| "Copy files from this directory into a new project only; " | |
| "existing files are not overwritten" | |
| ), |
Copilot
AI
Mar 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are existing CLI tests for project_init_cmd (see tests/commands/test_init.py), but this new --template-dir behavior isn’t covered. Please add tests that verify template files are copied into a new project and that existing scaffold files aren’t overwritten (or whatever the intended overwrite policy is).
Copilot
AI
Mar 26, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shutil.copy2() follows symlinks by default, so a template containing symlinked files will copy the target contents into the project (and will not preserve the symlink). That’s surprising behavior for a “template copy”, and it can also end up copying special/unexpected files. Consider explicitly choosing a symlink policy (skip symlinks, preserve them with follow_symlinks=False, and/or validate file types before copying).
| shutil.copy2(src_file, dst_file) | |
| shutil.copy2(src_file, dst_file, follow_symlinks=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
validate_template_dir()only checksos.R_OK. For directories on POSIX, read permission alone isn’t sufficient to traverse/copy contents (needs execute/search permission too), soos.walk()/copy2()can still fail withPermissionErrorafter validation passes. Consider validatingos.X_OKas well (and/or handleos.walk(..., onerror=...)to surface a clear Click error).