-
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
Open
34j
wants to merge
92
commits into
browniebroke:main
Choose a base branch
from
34j:refine-copier
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
92 commits
Select commit
Hold shift + click to select a range
05b1efd
feat: update copier.yml
34j 6acb969
fix(copier.yml): revoke unnecessary changes
34j 7b9ccb5
chore(poerty): add deps
34j a0b45e3
chore(poetry): add arrow for jinja2-time
34j ca01b71
fix(copier): suppress error if vscode not found
34j 70ab8c3
test: use same venv version
34j 11c3b24
ci: specify venv version
34j 7b5b111
fix(copier): fix replace command
34j b6ccbb3
chore(deps): remove unused jinja2-shell
34j f748aaa
fix(setup-github.bash): remove PYPI_TOKEN setting
34j 28e1082
fix(copier.yml): change the order of project name questions
34j fbe947f
revert(copier.yml): revert "change the order of project name questions"
34j f3b80f0
fix(copier): do not run autoupdate
34j c26c356
fix(copier): add after update
34j e058cda
fix(copier): always use git bash instead of wsl in windows to avoid c…
34j 89d9205
fix(copier): replace sed command with python
34j 0b96fd4
fix(copier): run poetry as an executable instead of a module
34j 021b162
fix(setup-github.bash): no newlines
34j 4a4a874
fix(setup-github.bash): enclose short desc with double quotes
34j 547eae2
fix(copier): fix poetry creating another venv
34j 8fe09ea
fix(copier): do not activate venv in mac or linux
34j e997b5c
ci(ci): setup git user
34j bdf12d9
Merge branch 'main' of https://github.com/34j/pypackage-template into…
34j eb77837
chore: update lockfile
34j f15262d
style: run pre-commit
34j f87ec48
fix: fix jinja2 extensions
34j 24f418c
fix(copier.yml): rearrange questions
34j 40ff221
fix(copier): do not open with vscode by default
34j 158a9d8
docs: update docs
34j 9d76ea2
chore: update script
34j 038b922
fix: use `PYPACKAGE_TEMPLATE_GITHUB_TOKEN` instead of `GITHUB_TOKEN`
34j 2d56b11
ci: install jinja2 packages
34j 7edbd47
fix(copier.yml): do not use sed
34j 5cf2390
fix(copier.yml): fix syntax
34j b4fdfed
ci: git config globally
34j 16c0812
fix(copier.yml): always run `git add --all`
34j 0dfa65e
docs: update docs
34j 640223b
ci: do not setup github
34j 90b4fb7
fix(copier.yml): fix naming convention
34j 1a69df9
fix: fix syntax
34j 05f6b02
fix: fix syntax
34j f276626
fix: fix naming convention
34j fe7e7c9
fix: warn if `PYPACKAGE_TEMPLATE_GITHUB_TOKEN` is not set
34j f7ce024
fix(copier.yml): do not stop if pre-commit raises
34j 1951f5f
fix: update script
34j d6980d7
fix: make `PYPACKAGE_TEMPLATE_INSTALLATION_IDS` optional
34j 68b9dc6
fix: fix setup script
34j 9619080
fix: multiple fixes
34j a177939
fix: multiple fixes
34j f1f6d23
docs: update readme
34j 731d566
fix: fix python not found error
34j 700e3c3
fix: fix re.sub
34j 36c6ca6
fix(copier.yml): fix python not found error
34j 93f1b05
fix: fix command
34j eb7503a
docs: update docs
34j 91a227f
fix: support GITHUB_TOKEN as well
34j 7618e1b
docs: update readme
34j ec16f0f
docs: update readme
34j e0f94f9
docs: update readme
34j 9232ad5
docs: update readme
34j 462f462
fix: fix command
34j 22955ca
docs: update readme
34j 83fd54b
docs: lower
34j 28f58e5
fix: remove space
34j 08ceaab
fix: replace copier.yml only if initial commit
34j a424a75
fix(copier.yml): use $VISUAL env variable
34j 875a69f
fix(copier): do not raise if gh is not found
34j ce0b5f0
fix(copier.yml): fix commands
34j 9f333f6
fix(copier.yml): fix commands
34j ece0696
fix(copier.yml): set text to True
34j e8e3b1d
fix(copier.yml): do not use shell and use suppress
34j 2bc6e15
fix(copier.yml): do not use shell and use suppress
34j 034e135
fix(copier.yml): do not use shell and use suppress
34j d7665ee
fix(copier.yml): do not use shell and use suppress
34j 252f1fc
fix(copier.yml): do not use shell and use suppress
34j be29467
Merge branch 'main' into refine-copier
34j d368c96
chore(deps): update lockfile
34j 886b486
fix(bash): fix wrong secret name
34j 53418fc
feat(copier): move setup-github.bash to /tmp
34j 383e238
Merge branch 'main' into refine-copier
34j c14ca00
docs: update docs
34j c7ab932
fix: use poetry to create venv
34j 300c058
fix(copier.yml): use poetry run python
34j 01e9e93
feat(copier.yml): add --yes flag to automatically install all-contrib…
34j d3d75d1
feat(copier.yml): detect $visual
34j dbabf22
fix(copier.yml): supress all errors when running commands
34j 808c429
fix(copier.yml): add_me_as_contributor requires npx
34j 56fa27c
fix: remove poetry.toml
34j f83d4ee
docs: add notes about virtualenv directory
34j 130739c
chore: merge branch 'main' of https://github.com/34j/pypackage-templa…
34j c072a09
fix: remove venv_version option
34j 85694ff
ci: install poetry beforehand
34j File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; from collections import defaultdict; from contextlib import suppress; j = defaultdict(str)\\nwith suppress(Exception): 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; from contextlib import suppress; s = \"\"\\nwith suppress(Exception): s = run([\"gh\",\"api\",\"user/emails\"], capture_output=True).stdout'') or ([k for k in json.loads(s) if k[''primary'']][0][''email''] if s else s)" | eval) | env("PYPACKAGE_TEMPLATE_EMAIL") }}' | ||
|
||
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; from contextlib import suppress; s = \"\"\\nwith suppress(Exception): s = run([\"gh\",\"api\",\"user\"], capture_output=True).stdout'') or (json.loads(s)[''login''] if s else s)" | eval) | env("PYPACKAGE_TEMPLATE_GITHUB_USER") }}' | ||
|
||
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,75 @@ 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: | ||
type: bool | ||
help: "Does the project have a CLI?" | ||
default: no | ||
|
||
cli_name: | ||
type: str | ||
help: "The name of the CLI" | ||
default: "{{ project_slug }}" | ||
when: "{{ has_cli }}" | ||
|
||
run_poetry_install: | ||
type: bool | ||
help: "Run poetry install after {{ package_name }} generation?" | ||
default: no | ||
default: yes | ||
|
||
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 | ||
|
||
add_me_as_contributor: | ||
type: bool | ||
help: "Add me as a contributor?" | ||
default: no | ||
help: "Add me as a contributor (requires npx)?" | ||
default: yes | ||
when: "{{ initial_commit }}" | ||
|
||
open_with_editor: | ||
type: bool | ||
help: 'Open with $VISUAL={{ "" | env("VISUAL") }}' | ||
default: '{% env "VISUAL", "" != "" %}' | ||
|
||
# Copier metadata | ||
_min_copier_version: "9.0.0" | ||
_subdirectory: "project" | ||
_tasks: | ||
# In Windows, command prompt | ||
# Move setup script .github/setup-github.bash to /tmp | ||
- "mv ./.github/setup-github.bash /tmp" | ||
# 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 %}" | ||
# 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 run_poetry_install %}poetry install --with dev{% endif %}" | ||
# git init | ||
- "git init && git add --all" | ||
# Setup pre-commit | ||
- "{% if setup_pre_commit %}pre-commit install{% endif %}" | ||
- "{% if setup_pre_commit %}pre-commit autoupdate && pre-commit install && 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 initial_commit %}poetry run 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 %}" | ||
- "{% if add_me_as_contributor %}npx --yes all-contributors-cli add {{ github_username }} code,ideas,doc{% endif %}" | ||
# Setup GitHub | ||
- '{% if setup_github %}bash /tmp/setup-github.bash {{ github_username }} {{ project_slug }} "{{ project_short_description }}"{% endif %}' | ||
# Open with editor | ||
- "{% if open_with_editor %}$VISUAL .{% endif %}" | ||
_jinja_extensions: | ||
- jinja2_time.TimeExtension | ||
- jinja2_eval.EvalExtension | ||
- jinja2_env.EnvExtension |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.