-
Notifications
You must be signed in to change notification settings - Fork 18
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
feat(copier): enhance copier.yml #681
base: main
Are you sure you want to change the base?
Changes from 65 commits
05b1efd
6acb969
7b9ccb5
a0b45e3
ca01b71
70ab8c3
11c3b24
7b5b111
b6ccbb3
f748aaa
28e1082
fbe947f
f3b80f0
c26c356
e058cda
89d9205
0b96fd4
021b162
4a4a874
547eae2
8fe09ea
e997b5c
bdf12d9
eb77837
f15262d
f87ec48
24f418c
40ff221
158a9d8
9d76ea2
038b922
2d56b11
7edbd47
5cf2390
b4fdfed
16c0812
0dfa65e
640223b
90b4fb7
1a69df9
05f6b02
f276626
fe7e7c9
f7ce024
1951f5f
d6980d7
68b9dc6
9619080
a177939
f1f6d23
731d566
700e3c3
36c6ca6
93f1b05
eb7503a
91a227f
7618e1b
ec16f0f
e0f94f9
9232ad5
462f462
22955ca
83fd54b
28f58e5
08ceaab
a424a75
875a69f
ce0b5f0
9f333f6
ece0696
e8e3b1d
2bc6e15
034e135
d7665ee
252f1fc
be29467
d368c96
886b486
53418fc
383e238
c14ca00
c7ab932
300c058
01e9e93
d3d75d1
dbabf22
808c429
56fa27c
f83d4ee
130739c
c072a09
85694ff
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 |
---|---|---|
@@ -1,26 +1,38 @@ | ||
# questions | ||
project_short_description: | ||
type: str | ||
help: "A short description of the project" | ||
default: "Python package for " | ||
|
||
has_cli: | ||
type: bool | ||
help: "Does the project have a CLI?" | ||
default: no | ||
|
||
is_django_package: | ||
type: bool | ||
help: "Is the project a Django package?" | ||
default: no | ||
|
||
full_name: | ||
type: str | ||
help: "What's your name?" | ||
default: '{{ ("exec(''from subprocess import run; import json; j = json.loads(run([\"gh\",\"api\",\"user\"], capture_output=True).stdout)'') or j[''name''] or j[''login'']" | eval) | env("PYPACKAGE_TEMPLATE_NAME") }}' | ||
|
||
email: | ||
type: str | ||
help: "Email address" | ||
placeholder: "[email protected]" | ||
default: '{{ ("exec(''from subprocess import run; import json; j = json.loads(run([\"gh\",\"api\",\"user/emails\"], capture_output=True).stdout)'') or [k for k in j if k[''primary'']][0][''email'']" | eval) | env("PYPACKAGE_TEMPLATE_EMAIL") }}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What happens if the person doesn't have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed to work even if gh is not installed using contextlib.suppress, confirmed that it works |
||
|
||
github_username: | ||
type: str | ||
help: "GitHub Username" | ||
|
||
is_django_package: | ||
type: bool | ||
help: "Is the project a Django package?" | ||
default: no | ||
default: '{{ ("exec(''from subprocess import run; import json; j = json.loads(run([\"gh\",\"api\",\"user\"], capture_output=True).stdout)'') or j[''login'']" | eval) | env("PYPACKAGE_TEMPLATE_GITHUB_USER") }}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Again, adding a hard dependency to save a few keystrokes |
||
|
||
project_name: | ||
type: str | ||
help: "Project Name (human readable version){% if is_django_package %}, should start by 'Django'{% endif %}." | ||
placeholder: "Python Package" | ||
default: '{{ "exec(''import sys; s = sys.argv[-1]; u = \" \".join([t.capitalize() for t in s.replace(\".\", \" \").replace(\"_\", \" \").replace(\"-\", \" \").split()])'') or u" | eval }}' | ||
|
||
project_slug: | ||
type: str | ||
|
@@ -32,17 +44,18 @@ package_name: | |
help: "The name of the main Python package (should be a valid Python identifier{% if is_django_package %} and start by 'django_'{% endif %})" | ||
default: "{{ project_slug.replace('-', '_') }}" | ||
|
||
cli_name: | ||
type: str | ||
help: "The name of the CLI" | ||
default: "{{ project_slug }}" | ||
when: "{{ has_cli }}" | ||
|
||
django_app_shorthand: | ||
type: str | ||
help: "The Django app shorthand, typically the package name without the 'django_' prefix." | ||
default: "{{ package_name.removeprefix('django_') }}" | ||
when: "{{ is_django_package }}" | ||
|
||
project_short_description: | ||
type: str | ||
help: "A short description of the project" | ||
placeholder: "A super helpful small Python package." | ||
|
||
open_source_license: | ||
type: str | ||
help: "The open source license to use" | ||
|
@@ -55,69 +68,91 @@ open_source_license: | |
copyright_year: | ||
type: str | ||
help: "Copyright year(s)" | ||
default: "2022" | ||
default: "{% now 'utc', '%Y' %}" | ||
|
||
documentation: | ||
type: bool | ||
help: "Generate documentation?" | ||
default: yes | ||
|
||
has_cli: | ||
setup_venv: | ||
type: bool | ||
help: "Does the project have a CLI?" | ||
default: no | ||
help: "Setup a virtual environment?" | ||
default: yes | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why bother with venv creation? Thsi template uses Poetry, which manages venv automatically. Would be similar if/when it's moved to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm starting to think that for advanced users like you, this should rather be considered a temporal virtual environment just to support all operations up to pushing to GitHub, in case pre-commit and poetry are not installed globally, rather than used to develop projects. No matter which tool is used, I believe the virtual environment created would be equivalent if the setting corresponds to "poetry config virtualenvs.in-project true". Of course you can switch Python versions using |
||
|
||
cli_name: | ||
venv_version: | ||
type: str | ||
help: "The name of the CLI" | ||
default: "{{ project_slug }}" | ||
when: "{{ has_cli }}" | ||
help: "Python version for the virtual environment" | ||
default: "3.11" | ||
when: "{{ setup_venv }}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a hard block, but FWIW I personally see little value in this question... |
||
|
||
run_poetry_install: | ||
type: bool | ||
help: "Run poetry install after {{ package_name }} generation?" | ||
default: no | ||
default: yes | ||
when: "{{ setup_venv }}" | ||
|
||
initial_commit: | ||
type: bool | ||
help: "Create an initial commit with the generated {{ package_name }}?" | ||
default: no | ||
default: yes | ||
|
||
setup_github: | ||
type: bool | ||
help: "Setup GitHub repository (requires gh CLI)?" | ||
default: no | ||
default: yes | ||
when: "{{ initial_commit }}" | ||
|
||
setup_pre_commit: | ||
type: bool | ||
help: "Setup pre-commit hooks (requires pre-commit)?" | ||
default: no | ||
default: yes | ||
when: "{{ setup_venv }}" | ||
|
||
add_me_as_contributor: | ||
type: bool | ||
help: "Add me as a contributor?" | ||
default: yes | ||
when: "{{ initial_commit }}" | ||
|
||
open_with_vscode: | ||
type: bool | ||
help: "Open with VSCode?" | ||
default: no | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I don't use VSCode, so no. I'm not interested in making this question specific to a given IDE/editor either, but would be interesting if there is convention in env variable to open in the user's preferred editor: https://unix.stackexchange.com/q/4859 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to use $VISUAL |
||
|
||
# Copier metadata | ||
_min_copier_version: "9.0.0" | ||
_subdirectory: "project" | ||
_tasks: | ||
# In Windows, command prompt | ||
# Remove license file if no license | ||
- "{% if open_source_license == 'Not open source' %}rm LICENSE{% endif %}" | ||
# Cleanup docs | ||
- "{% if not documentation %}rm -rf docs .readthedocs.yml{% endif %}" | ||
# Setup venv | ||
- "{% if setup_venv %}{% if 'Windows' in ''|env('OS') %}py -{% else %}python{% endif %}{{ venv_version }} -m venv venv{% endif %}" | ||
# Run poetry install | ||
- "{% if run_poetry_install %}poetry install{% endif %}" | ||
# Initial commit | ||
- "{% if initial_commit %}git init{% endif %}" | ||
- "{% if initial_commit %}git add .{% endif %}" | ||
- "{% if initial_commit %}git commit -m 'chore: initial commit'{% endif %}" | ||
# Setup GitHub | ||
- "{% if setup_github %}gh repo create {{ github_username }}/{{ project_slug }} -d '{{ project_short_description }}' --public --remote=origin --source=. --push{% endif %}" | ||
- "{% if setup_github %}gh repo edit --delete-branch-on-merge --enable-projects=false --enable-wiki=false{% endif %}" | ||
- "{% if setup_github %}gh secret set GH_PAT -b 'changeme'{% endif %}" | ||
- "{% if setup_github %}gh secret set CODECOV_TOKEN -b 'changeme'{% endif %}" | ||
- "{% if 'Windows' in ''|env('OS') %}{% set venv_folder = 'venv\\\\scripts\\\\' %}{% else %}{% set venv_folder = 'venv/bin/' %}{% endif %} | ||
{% if run_poetry_install %}{{ venv_folder }}python -m pip install -U pip setuptools wheel && {{ venv_folder }}pip install -U poetry pre-commit && {{ venv_folder }}python -m poetry install --with dev{% endif %}" | ||
# git init | ||
- "git init && git add --all" | ||
# Setup pre-commit | ||
- "{% if setup_pre_commit %}pre-commit install{% endif %}" | ||
- "{% if 'Windows' in ''|env('OS') %}{% set venv_folder = 'venv\\\\scripts\\\\' %}{% else %}{% set venv_folder = 'venv/bin/' %}{% endif %} | ||
{% if setup_pre_commit %}{{ venv_folder }}pre-commit autoupdate && {{ venv_folder }}pre-commit install && {{ venv_folder }}pre-commit run -a || true{% endif %}" | ||
# Initial commit | ||
- '{% if initial_commit %}git add --all && git commit -m "chore: initial commit"{% endif %}' | ||
# Replace true with false in .copier-answers.yml except "documentation: true" for faster copier update | ||
# - "sed -i '/documentation: true/!s/true/false/g' .copier-answers.yml" | ||
- "{% if 'Windows' in ''|env('OS') %}{% set venv_folder = 'venv\\\\scripts\\\\' %}{% else %}{% set venv_folder = 'venv/bin/' %}{% endif %} | ||
{% if initial_commit %}{{ venv_folder }}python -c \"from pathlib import Path; import re; p = Path('.copier-answers.yml'); p.write_text(re.sub(r'((?:setup_venv|run_poetry_install|initial_commit|setup_github|setup_pre_commit|add_me_as_contributor): )true', r'\\g<1>false', p.read_text()))\"{% endif %}" | ||
- '{% if initial_commit %}git add --all && git commit -m "chore: update .copier-answers.yml to avoid running commands again"{% endif %}' | ||
# Add me as a contributor | ||
- "{% if add_me_as_contributor %}npx all-contributors-cli add {{ github_username }} code,ideas,doc{% endif %}" | ||
# Setup GitHub | ||
- '{% if setup_github %}bash .github/setup-github.bash {{ github_username }} {{ project_slug }} "{{ project_short_description }}"{% endif %}' | ||
# Open with vscode | ||
- "{% if open_with_vscode %}code .{% endif %}" | ||
_jinja_extensions: | ||
- jinja2_time.TimeExtension | ||
- jinja2_eval.EvalExtension | ||
- jinja2_env.EnvExtension |
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.
How does it work if folks don't have these installed? That seems like a significant change in workflow for users
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.
Copier raises an error if not installed. There is no workaround. I suppose that if you are interested in jinja2-time, injecting is inevitable anyway. Of course, these are only necessary when using copier.