From 291503a8198276c61d98eb2d01b349ce497efab6 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Wed, 27 Nov 2024 01:28:39 +0000 Subject: [PATCH 1/7] refactor: use trim blocks for more elegant template --- copier.yaml | 1 + includes/sample.jinja | 5 +- template/.gitignore.jinja | 4 +- template/.pre-commit-config.yaml.jinja | 4 +- template/.releaserc.json.jinja | 8 +-- template/.renovaterc.json.jinja | 29 +++++----- template/Makefile.jinja | 12 ++-- template/README.md.jinja | 6 +- .../workflows/ci.yml.jinja | 36 ++++++------ .../workflows/devcontainer.yml.jinja | 20 +++---- .../workflows/release.yml.jinja | 20 +++---- .../workflows/renovate.yml.jinja | 6 +- .../workflows/ci.yml.jinja | 24 ++++---- .../workflows/devcontainer.yml.jinja | 20 +++---- .../workflows/release.yml.jinja | 20 +++---- template/docs/advanced/cicd.md.jinja | 10 ++-- template/docs/conf.py.jinja | 6 +- template/pyproject.toml.jinja | 56 +++++++++---------- .../src/{{ module_name }}/settings.py.jinja | 13 ++--- 19 files changed, 148 insertions(+), 152 deletions(-) diff --git a/copier.yaml b/copier.yaml index b696ba20..e7d9454f 100644 --- a/copier.yaml +++ b/copier.yaml @@ -1,6 +1,7 @@ _envops: block_end_string: '%]' block_start_string: '[%' + trim_blocks: true _subdirectory: template _message_before_copy: | Thanks for generating a project using our template. diff --git a/includes/sample.jinja b/includes/sample.jinja index cb72c6b8..adbfb27d 100644 --- a/includes/sample.jinja +++ b/includes/sample.jinja @@ -5,10 +5,9 @@ Serious Scaffold Python is crafted for long-term, maintainable Python projects. It includes GitHub Actions and GitLab CI/CD, automated dependency updates via Renovate, and comprehensive linting, testing, and documentation. Key integrations like pdm for environment and dependency management, click for CLI development, and pydantic for configuration enhance project robustness. With copier’s easy project setup and continuous updating, your project stays aligned with best practices for sustainable development. Pre-configured dev containers and cross-platform CI support ensure maintainability from the start. -[% if repo_platform == 'github' -%] +[% if repo_platform == 'github' %] If you find this helpful, please consider [sponsorship](https://github.com/sponsors/{{ author_name }}). - -[% endif -%] +[% endif %] ## 🛠️ Features diff --git a/template/.gitignore.jinja b/template/.gitignore.jinja index 8f0885cc..42e61687 100644 --- a/template/.gitignore.jinja +++ b/template/.gitignore.jinja @@ -1,9 +1,9 @@ # Custom *.swp .DS_Store -[%- if project_name == "Serious Scaffold Python" %] +[% if project_name == "Serious Scaffold Python" %] .copier-answers.yml -[%- endif %] +[% endif %] Pipfile public diff --git a/template/.pre-commit-config.yaml.jinja b/template/.pre-commit-config.yaml.jinja index 217f0cf9..48600f29 100644 --- a/template/.pre-commit-config.yaml.jinja +++ b/template/.pre-commit-config.yaml.jinja @@ -71,9 +71,9 @@ repos: name: mypy entry: pdm run python -m mypy language: system -[%- if project_name == 'Serious Scaffold Python' %] +[% if project_name == 'Serious Scaffold Python' %] exclude: ^template/.* -[%- endif %] +[% endif %] types_or: - python - pyi diff --git a/template/.releaserc.json.jinja b/template/.releaserc.json.jinja index b1fa5769..d1a60168 100644 --- a/template/.releaserc.json.jinja +++ b/template/.releaserc.json.jinja @@ -112,18 +112,18 @@ } } ], -[%- if repo_platform == 'github' %] +[% if repo_platform == 'github' %] "@semantic-release/github" -[%- elif repo_platform == 'gitlab' %] +[% elif repo_platform == 'gitlab' %] "@semantic-release/gitlab" -[%- elif repo_platform == 'gitlab-self-managed' %] +[% elif repo_platform == 'gitlab-self-managed' %] [ "@semantic-release/gitlab", { "gitlabUrl": "https://{{ repo_host }}" } ] -[%- endif %] +[% endif %] ], "preset": "conventionalcommits" } diff --git a/template/.renovaterc.json.jinja b/template/.renovaterc.json.jinja index 4567c3d2..0edcee8e 100644 --- a/template/.renovaterc.json.jinja +++ b/template/.renovaterc.json.jinja @@ -28,7 +28,7 @@ "^template/\\.readthedocs\\.yaml\\.jinja$", "^template/\\.renovaterc\\.json\\.jinja$", "^template/docs/.+\\.md(\\.jinja)?$" -[%- endif %] +[% endif %] ], "matchStrings": [ "pip install.* (?.*?)(\\[.*?\\])?==(?.*?)[\"\n]", @@ -44,7 +44,7 @@ "^\\.devcontainer\\/Dockerfile$" [%- if project_name == "Serious Scaffold Python" %], "^template\\/\\.devcontainer/Dockerfile\\.jinja$" -[%- endif %] +[% endif %] ], "matchStrings": [ "# renovate: depName=(?.*?)\nARG .*?_VERSION=\"(?.*)\"\n" @@ -60,7 +60,7 @@ "^\\.github/workflows/.+\\.yml$" [%- if project_name == "Serious Scaffold Python" %], "^template/.*\\.github.*/workflows/.+\\.yml(\\.jinja)?$" -[%- endif %] +[% endif %] ], "matchStrings": [ "uses: pdm-project/setup-pdm[\\s\\S]+?\\sversion: (?.*)\n" @@ -75,7 +75,7 @@ "^\\.renovaterc\\.json$" [%- if project_name == "Serious Scaffold Python" %], "^template/\\.renovaterc\\.json\\.jinja$" -[%- endif %] +[% endif %] ], "matchStrings": [ "\"pdm\": \"(?.*)\"" @@ -100,12 +100,11 @@ "datasourceTemplate": "npm", "description": "Match npm packages used with npx", "fileMatch": [ - "^\\.github/workflows/.+\\.yml$", "^\\.gitlab/workflows/.+\\.yml$" -[%- if project_name == "Serious Scaffold Python" %], +[% if project_name == "Serious Scaffold Python" %], "^template/.*\\.github.*/workflows/.+\\.yml(\\.jinja)?$", "^template/.*\\.gitlab.*/workflows/.+\\.yml(\\.jinja)?$" -[%- endif %] +[% endif %] ], "matchStrings": [ "--package (?.+?)@(?.+?)\\s" @@ -133,15 +132,15 @@ ":maintainLockFilesWeekly", ":semanticCommitTypeAll(build)" ], -[%- if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' or project_name == 'Serious Scaffold Python' %] +[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' or project_name == 'Serious Scaffold Python' %] "gitlabci": { "fileMatch": [ "^.gitlab/workflows/.*\\.yml$" ] }, -[%- endif %] +[% endif %] "packageRules": [ -[%- if project_name == "Serious Scaffold Python" %] +[% if project_name == "Serious Scaffold Python" %] { "description": "Update GitHub Action in template", "matchDepTypes": [ @@ -203,7 +202,7 @@ ] } }, -[%- endif %] +[% endif %] { "commitMessageTopic": "serious-scaffold-python", "description": "Update template with copier when a new version is released", @@ -238,12 +237,12 @@ "github-tags" ], "matchDepNames": [ -[%- if repo_platform == "github" %] +[% if repo_platform == "github" %] "ghcr.io/renovatebot/renovate", -[%- endif %] -[%- if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' or project_name == 'Serious Scaffold Python' %] +[% endif %] +[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' or project_name == 'Serious Scaffold Python' %] "renovate/renovate", -[%- endif %] +[% endif %] "renovatebot/pre-commit-hooks" ] }, diff --git a/template/Makefile.jinja b/template/Makefile.jinja index 70d7c56e..722b5a4d 100644 --- a/template/Makefile.jinja +++ b/template/Makefile.jinja @@ -1,6 +1,8 @@ [% from pathjoin("includes", "variable.jinja") import page_url with context -%] .PHONY: clean deepclean install dev prerequisites mypy ruff ruff-format pyproject-fmt codespell lint pre-commit test-run test build publish doc-watch doc-build doc-coverage doc -[%- if project_name == "Serious Scaffold Python" %] template-watch template-build[% endif %] +[%- if project_name == "Serious Scaffold Python" %] + template-watch template-build +[% endif %] ######################################################################################## # Variables @@ -97,12 +99,12 @@ codespell: # Check jsonschema with check-jsonschema. check-jsonschema: -[%- if repo_platform == "github" %] +[% if repo_platform == "github" %] check-jsonschema --builtin-schema vendor.github-workflows .github/workflows/*.yml -[%- endif %] -[%- if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' or project_name == "Serious Scaffold Python" %] +[% endif %] +[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' or project_name == "Serious Scaffold Python" %] check-jsonschema --builtin-schema vendor.gitlab-ci --data-transform gitlab-ci .gitlab-ci.yml .gitlab/workflows/*.yml -[%- endif %] +[% endif %] check-jsonschema --builtin-schema vendor.readthedocs .readthedocs.yaml check-jsonschema --builtin-schema vendor.renovate .renovaterc.json diff --git a/template/README.md.jinja b/template/README.md.jinja index fc36e16e..e33813e9 100644 --- a/template/README.md.jinja +++ b/template/README.md.jinja @@ -35,11 +35,11 @@ > [!NOTE] [% endif -%] > _{{ project_name }}_ is in the **{{ development_status }}** phase. -[%- if development_status == "Alpha" %] +[% if development_status == "Alpha" %] > Frequent changes and instability should be anticipated. -[%- elif development_status == "Beta" %] +[% elif development_status == "Beta" %] > Changes and potential instability should be anticipated. -[%- endif %] +[% endif %] > Any feedback, comments, suggestions and contributions are welcome! {{ readme_content }} diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja index 0e71400a..25ce5e94 100644 --- a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja @@ -36,35 +36,35 @@ jobs: strategy: matrix: os: -[%- if "macos" in platforms %] +[% if "macos" in platforms %] # renovate: github-runner - macos-14 -[%- endif %] -[%- if "ubuntu" in platforms %] +[% endif %] +[% if "ubuntu" in platforms %] # renovate: github-runner - ubuntu-24.04 -[%- endif %] -[%- if "windows" in platforms %] +[% endif %] +[% if "windows" in platforms %] # renovate: github-runner - windows-2022 -[%- endif %] +[% endif %] python-version: -[%- if version_between("3.9", min_py, max_py) %] +[% if version_between("3.9", min_py, max_py) %] - '3.9' -[%- endif %] -[%- if version_between("3.10", min_py, max_py) %] +[% endif %] +[% if version_between("3.10", min_py, max_py) %] - '3.10' -[%- endif %] -[%- if version_between("3.11", min_py, max_py) %] +[% endif %] +[% if version_between("3.11", min_py, max_py) %] - '3.11' -[%- endif %] -[%- if version_between("3.12", min_py, max_py) %] +[% endif %] +[% if version_between("3.12", min_py, max_py) %] - '3.12' -[%- endif %] -[%- if version_between("3.13", min_py, max_py) %] +[% endif %] +[% if version_between("3.13", min_py, max_py) %] - '3.13' -[%- endif %] -[%- if project_name == "Serious Scaffold Python" %] +[% endif %] +[% if project_name == "Serious Scaffold Python" %] consistency: if: {{ '${{ !cancelled() && ! failure() }}' }} runs-on: ubuntu-24.04 @@ -81,4 +81,4 @@ jobs: - run: git diff - run: git status --porcelain - run: test -z "$(git status --porcelain)" -[%- endif %] +[% endif %] diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/devcontainer.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/devcontainer.yml.jinja index ce6835fe..963610bc 100644 --- a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/devcontainer.yml.jinja +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/devcontainer.yml.jinja @@ -77,18 +77,18 @@ jobs: strategy: matrix: python-version: -[%- if version_between("3.9", min_py, max_py) %] +[% if version_between("3.9", min_py, max_py) %] - '3.9' -[%- endif %] -[%- if version_between("3.10", min_py, max_py) %] +[% endif %] +[% if version_between("3.10", min_py, max_py) %] - '3.10' -[%- endif %] -[%- if version_between("3.11", min_py, max_py) %] +[% endif %] +[% if version_between("3.11", min_py, max_py) %] - '3.11' -[%- endif %] -[%- if version_between("3.12", min_py, max_py) %] +[% endif %] +[% if version_between("3.12", min_py, max_py) %] - '3.12' -[%- endif %] -[%- if version_between("3.13", min_py, max_py) %] +[% endif %] +[% if version_between("3.13", min_py, max_py) %] - '3.13' -[%- endif %] +[% endif %] diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/release.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/release.yml.jinja index abde406e..d3543c28 100644 --- a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/release.yml.jinja +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/release.yml.jinja @@ -112,21 +112,21 @@ jobs: strategy: matrix: python-version: -[%- if version_between("3.9", min_py, max_py) %] +[% if version_between("3.9", min_py, max_py) %] - '3.9' -[%- endif %] -[%- if version_between("3.10", min_py, max_py) %] +[% endif %] +[% if version_between("3.10", min_py, max_py) %] - '3.10' -[%- endif %] -[%- if version_between("3.11", min_py, max_py) %] +[% endif %] +[% if version_between("3.11", min_py, max_py) %] - '3.11' -[%- endif %] -[%- if version_between("3.12", min_py, max_py) %] +[% endif %] +[% if version_between("3.12", min_py, max_py) %] - '3.12' -[%- endif %] -[%- if version_between("3.13", min_py, max_py) %] +[% endif %] +[% if version_between("3.13", min_py, max_py) %] - '3.13' -[%- endif %] +[% endif %] package-publish: runs-on: ubuntu-24.04 steps: diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/renovate.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/renovate.yml.jinja index aa938e9a..f0bbfdf9 100644 --- a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/renovate.yml.jinja +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/renovate.yml.jinja @@ -7,11 +7,11 @@ jobs: RENOVATE_ALLOWED_POST_UPGRADE_COMMANDS: '["^git", "^pip", "^copier", "^find"]' RENOVATE_BRANCH_PREFIX: renovate-github/ RENOVATE_ENABLED: {{ '${{ vars.RENOVATE_ENABLED || true }}' }} -[%- if project_name == "Serious Scaffold Python" %] +[% if project_name == "Serious Scaffold Python" %] RENOVATE_ENABLED_MANAGERS: '["pep621", "github-actions", "gitlabci", "regex", "pre-commit"]' -[%- else %] +[% else %] RENOVATE_ENABLED_MANAGERS: '["pep621", "github-actions", "regex", "pre-commit"]' -[%- endif %] +[% endif %] RENOVATE_OPTIMIZE_FOR_DISABLED: 'true' RENOVATE_PLATFORM: github RENOVATE_REPOSITORIES: '["{{ '${{ github.repository }}' }}"]' diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja index 661aad46..bbdf7640 100644 --- a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja @@ -19,21 +19,21 @@ ci: parallel: matrix: - PYTHON_VERSION: -[%- if version_between("3.9", min_py, max_py) %] +[% if version_between("3.9", min_py, max_py) %] - '3.9' -[%- endif %] -[%- if version_between("3.10", min_py, max_py) %] +[% endif %] +[% if version_between("3.10", min_py, max_py) %] - '3.10' -[%- endif %] -[%- if version_between("3.11", min_py, max_py) %] +[% endif %] +[% if version_between("3.11", min_py, max_py) %] - '3.11' -[%- endif %] -[%- if version_between("3.12", min_py, max_py) %] +[% endif %] +[% if version_between("3.12", min_py, max_py) %] - '3.12' -[%- endif %] -[%- if version_between("3.13", min_py, max_py) %] +[% endif %] +[% if version_between("3.13", min_py, max_py) %] - '3.13' -[%- endif %] +[% endif %] rules: - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $CI_PIPELINE_SOURCE == "push" - if: $CI_PIPELINE_SOURCE == 'merge_request_event' @@ -42,7 +42,7 @@ ci: - make dev - make lint test doc build stage: ci -[%- if project_name == 'Serious Scaffold Python' %] +[% if project_name == 'Serious Scaffold Python' %] consistency: interruptible: true rules: @@ -57,4 +57,4 @@ consistency: - git status --porcelain - test -z "$(git status --porcelain)" stage: ci -[%- endif %] +[% endif %] diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/devcontainer.yml.jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/devcontainer.yml.jinja index 3a2e3427..323944e2 100644 --- a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/devcontainer.yml.jinja +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/devcontainer.yml.jinja @@ -4,21 +4,21 @@ dev-container-publish: parallel: matrix: - PYTHON_VERSION: -[%- if version_between("3.9", min_py, max_py) %] +[% if version_between("3.9", min_py, max_py) %] - '3.9' -[%- endif %] -[%- if version_between("3.10", min_py, max_py) %] +[% endif %] +[% if version_between("3.10", min_py, max_py) %] - '3.10' -[%- endif %] -[%- if version_between("3.11", min_py, max_py) %] +[% endif %] +[% if version_between("3.11", min_py, max_py) %] - '3.11' -[%- endif %] -[%- if version_between("3.12", min_py, max_py) %] +[% endif %] +[% if version_between("3.12", min_py, max_py) %] - '3.12' -[%- endif %] -[%- if version_between("3.13", min_py, max_py) %] +[% endif %] +[% if version_between("3.13", min_py, max_py) %] - '3.13' -[%- endif %] +[% endif %] rules: - changes: - .devcontainer/Dockerfile diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja index f1e3b5b1..83867037 100644 --- a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja @@ -36,21 +36,21 @@ container-publish: parallel: matrix: - PYTHON_VERSION: -[%- if version_between("3.9", min_py, max_py) %] +[% if version_between("3.9", min_py, max_py) %] - '3.9' -[%- endif %] -[%- if version_between("3.10", min_py, max_py) %] +[% endif %] +[% if version_between("3.10", min_py, max_py) %] - '3.10' -[%- endif %] -[%- if version_between("3.11", min_py, max_py) %] +[% endif %] +[% if version_between("3.11", min_py, max_py) %] - '3.11' -[%- endif %] -[%- if version_between("3.12", min_py, max_py) %] +[% endif %] +[% if version_between("3.12", min_py, max_py) %] - '3.12' -[%- endif %] -[%- if version_between("3.13", min_py, max_py) %] +[% endif %] +[% if version_between("3.13", min_py, max_py) %] - '3.13' -[%- endif %] +[% endif %] rules: - if: $CI_COMMIT_TAG =~ /^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-?(a|b|rc)(0|[1-9][0-9]*)?)?$/ script: diff --git a/template/docs/advanced/cicd.md.jinja b/template/docs/advanced/cicd.md.jinja index e2a8e84a..eec65cc2 100644 --- a/template/docs/advanced/cicd.md.jinja +++ b/template/docs/advanced/cicd.md.jinja @@ -10,23 +10,21 @@ The `ci` workflow is the most frequently used workflow, running on all pull/merg The `commitlint` workflow checks whether the pull/merge request title comply with the . This ensures consistent commit history and enable the possibility of automated release pipeline. -[% if repo_platform == 'github' -%] +[% if repo_platform == 'github' %] ## `delete-untagged-packages.yml` The `delete-untagged-packages` workflow removes untagged packages since GitHub will still keep the package when overridden with the same tag. It helps keep the GitHub Packages clean and tidy. - -[% endif -%] +[% endif %] ## `devcontainer.yml` The `devcontainer` workflow will be triggered by container related changes. It builds and tests the development and production containers and push the development container except during pull/merge requests, ensuring seamless containerized environments. -[% if repo_platform == 'github' -%] +[% if repo_platform == 'github' %] ## `readthedocs-preview.yml` The `readthedocs-preview` workflow leverage the [readthedocs/actions/preview](https://github.com/readthedocs/actions/tree/v1/preview) to add Read the Docs preview links to the related pull requests. These links make it easy to review documentation changes. - -[% endif -%] +[% endif %] ## `release.yml` diff --git a/template/docs/conf.py.jinja b/template/docs/conf.py.jinja index e6c51948..5c504533 100644 --- a/template/docs/conf.py.jinja +++ b/template/docs/conf.py.jinja @@ -38,11 +38,11 @@ html_theme_options = { "announcement": ( "{{ project_name }} " "is in the {{ development_status }} phase. " -[%- if development_status == "Alpha" %] +[% if development_status == "Alpha" %] "Frequent changes and instability should be anticipated. " -[%- elif development_status == "Beta" %] +[% elif development_status == "Beta" %] "Changes and potential instability should be anticipated. " -[%- endif %] +[% endif %] "Any feedback, comments, suggestions and contributions are welcome!" ), } diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index f2272aa5..63c090c4 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -18,53 +18,53 @@ keywords = [ "project-template", "serious-scaffold", ] -[%- if copyright_license == "Apache Software License" %] +[% if copyright_license == "Apache Software License" %] license = { text = "Apache-2.0" } -[%- elif copyright_license == "Boost Software License 1.0 (BSL-1.0)" %] +[% elif copyright_license == "Boost Software License 1.0 (BSL-1.0)" %] license = { text = "BSL-1.0" } -[%- elif copyright_license == "GNU Affero General Public License v3" %] +[% elif copyright_license == "GNU Affero General Public License v3" %] license = { text = "AGPLv3" } -[%- elif copyright_license == "GNU General Public License v3 (GPLv3)" %] +[% elif copyright_license == "GNU General Public License v3 (GPLv3)" %] license = { text = "GPLv3" } -[%- elif copyright_license == "GNU Lesser General Public License v3 (LGPLv3)" %] +[% elif copyright_license == "GNU Lesser General Public License v3 (LGPLv3)" %] license = { text = "LGPLv3" } -[%- elif copyright_license == "MIT License" %] +[% elif copyright_license == "MIT License" %] license = { text = "MIT" } -[%- elif copyright_license == "Mozilla Public License 2.0 (MPL 2.0)" %] +[% elif copyright_license == "Mozilla Public License 2.0 (MPL 2.0)" %] license = { text = "MPL-2.0" } -[%- elif copyright_license == "The Unlicense (Unlicense)" %] +[% elif copyright_license == "The Unlicense (Unlicense)" %] license = { text = "Unlicense" } -[%- endif %] +[% endif %] authors = [ { email = "{{ author_email }}", name = "{{ author_name }}" }, ] requires-python = ">={{ min_py }}" classifiers = [ -[%- if development_status == "Alpha" %] +[% if development_status == "Alpha" %] "Development Status :: 3 - Alpha", -[%- elif development_status == "Beta" %] +[% elif development_status == "Beta" %] "Development Status :: 4 - Beta", -[%- elif development_status == "Stable" %] +[% elif development_status == "Stable" %] "Development Status :: 5 - Production/Stable", -[%- endif %] +[% endif %] "License :: OSI Approved :: {{ copyright_license }}", "Operating System :: OS Independent", "Programming Language :: Python :: 3 :: Only", -[%- if version_between("3.9", min_py, max_py) %] +[% if version_between("3.9", min_py, max_py) %] "Programming Language :: Python :: 3.9", -[%- endif %] -[%- if version_between("3.10", min_py, max_py) %] +[% endif %] +[% if version_between("3.10", min_py, max_py) %] "Programming Language :: Python :: 3.10", -[%- endif %] -[%- if version_between("3.11", min_py, max_py) %] +[% endif %] +[% if version_between("3.11", min_py, max_py) %] "Programming Language :: Python :: 3.11", -[%- endif %] -[%- if version_between("3.12", min_py, max_py) %] +[% endif %] +[% if version_between("3.12", min_py, max_py) %] "Programming Language :: Python :: 3.12", -[%- endif %] -[%- if version_between("3.13", min_py, max_py) %] +[% endif %] +[% if version_between("3.13", min_py, max_py) %] "Programming Language :: Python :: 3.13", -[%- endif %] +[% endif %] ] dynamic = [ "version", @@ -76,9 +76,9 @@ dependencies = [ urls.documentation = "https://{{ page_url() }}" [% if repo_platform == 'github' -%] urls.issue = "https://{{ repo_url() }}/issues" -[%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] +[% elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] urls.issue = "https://{{ repo_url() }}/-/issues" -[%- endif %] +[% endif %] urls.repository = "https://{{ repo_url() }}" scripts.{{ package_name }}-cli = "{{ module_name }}.cli:cli" @@ -116,7 +116,7 @@ src = [ extend-exclude = [ "template", ] -[%- endif %] +[% endif %] fix = true lint.select = [ "B", # flake8-bugbear @@ -170,9 +170,9 @@ enable_error_code = [ exclude = [ "build", "doc", -[%- if project_name == "Serious Scaffold Python" %] +[% if project_name == "Serious Scaffold Python" %] "template", -[%- endif %] +[% endif %] ] no_implicit_optional = true show_error_codes = true diff --git a/template/src/{{ module_name }}/settings.py.jinja b/template/src/{{ module_name }}/settings.py.jinja index 68f6bd88..02137065 100644 --- a/template/src/{{ module_name }}/settings.py.jinja +++ b/template/src/{{ module_name }}/settings.py.jinja @@ -3,9 +3,9 @@ import logging from logging import getLevelName -[%- if not version_higher_than(min_py, "3.10") %] +[% if not version_higher_than(min_py, "3.10") %] from typing import Optional -[%- endif %] +[% endif %] from pydantic_settings import BaseSettings, SettingsConfigDict @@ -20,14 +20,11 @@ class GlobalSettings(BaseSettings): class Settings(BaseSettings): """Project specific settings.""" - [%- if not version_higher_than(min_py, "3.10") %] - +[% if not version_higher_than(min_py, "3.10") %] logging_level: Optional[str] = getLevelName(logging.INFO) - - [%- else %] - +[% else %] logging_level: str | None = getLevelName(logging.INFO) - [%- endif %] +[% endif %] """Default logging level for the project.""" model_config = SettingsConfigDict( From 94ba8bae554036ebc27518873417f1bdcc979881 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Wed, 27 Nov 2024 07:21:26 +0000 Subject: [PATCH 2/7] fix --- template/.renovaterc.json.jinja | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/template/.renovaterc.json.jinja b/template/.renovaterc.json.jinja index 0edcee8e..179e46d4 100644 --- a/template/.renovaterc.json.jinja +++ b/template/.renovaterc.json.jinja @@ -100,8 +100,9 @@ "datasourceTemplate": "npm", "description": "Match npm packages used with npx", "fileMatch": [ + "^\\.github/workflows/.+\\.yml$", "^\\.gitlab/workflows/.+\\.yml$" -[% if project_name == "Serious Scaffold Python" %], +[%- if project_name == "Serious Scaffold Python" %], "^template/.*\\.github.*/workflows/.+\\.yml(\\.jinja)?$", "^template/.*\\.gitlab.*/workflows/.+\\.yml(\\.jinja)?$" [% endif %] From c090c5c0cebe586c141b9823fe3a8f90693ec6df Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Wed, 27 Nov 2024 07:27:03 +0000 Subject: [PATCH 3/7] Simplify more template --- template/.pre-commit-config.yaml.jinja | 2 +- template/.renovaterc.json.jinja | 2 +- template/LICENSE.jinja | 4 +-- template/Makefile.jinja | 6 ++--- template/README.md.jinja | 26 +++++++++---------- .../workflows/ci.yml.jinja | 2 +- .../workflows/devcontainer.yml.jinja | 2 +- .../workflows/release.yml.jinja | 2 +- .../workflows/ci.yml.jinja | 2 +- .../workflows/devcontainer.yml.jinja | 2 +- .../workflows/release.yml.jinja | 2 +- .../docs/development/git-workflow.md.jinja | 2 +- template/docs/index.md.jinja | 2 +- template/docs/management/init.md.jinja | 2 +- template/pyproject.toml.jinja | 12 ++++----- .../src/{{ module_name }}/settings.py.jinja | 2 +- 16 files changed, 36 insertions(+), 36 deletions(-) diff --git a/template/.pre-commit-config.yaml.jinja b/template/.pre-commit-config.yaml.jinja index 48600f29..6270311e 100644 --- a/template/.pre-commit-config.yaml.jinja +++ b/template/.pre-commit-config.yaml.jinja @@ -1,4 +1,4 @@ -[% from pathjoin("includes", "version_compare.jinja") import version_between -%] +[% from pathjoin("includes", "version_compare.jinja") import version_between %] default_install_hook_types: - post-checkout - post-merge diff --git a/template/.renovaterc.json.jinja b/template/.renovaterc.json.jinja index 179e46d4..9a13bf2d 100644 --- a/template/.renovaterc.json.jinja +++ b/template/.renovaterc.json.jinja @@ -1,4 +1,4 @@ -[% from pathjoin("includes", "version_compare.jinja") import version_higher_than -%] +[% from pathjoin("includes", "version_compare.jinja") import version_higher_than %] { "$schema": "https://docs.renovatebot.com/renovate-schema.json", "constraints": { diff --git a/template/LICENSE.jinja b/template/LICENSE.jinja index a635cc09..95961d43 100644 --- a/template/LICENSE.jinja +++ b/template/LICENSE.jinja @@ -1,2 +1,2 @@ -[%- set license_template = 'includes/licenses/' + copyright_license + '.jinja' -%] -[%- include license_template -%] +[% set license_template = 'includes/licenses/' + copyright_license + '.jinja' %] +[% include license_template %] diff --git a/template/Makefile.jinja b/template/Makefile.jinja index 722b5a4d..47cce0a5 100644 --- a/template/Makefile.jinja +++ b/template/Makefile.jinja @@ -1,4 +1,4 @@ -[% from pathjoin("includes", "variable.jinja") import page_url with context -%] +[% from pathjoin("includes", "variable.jinja") import page_url with context %] .PHONY: clean deepclean install dev prerequisites mypy ruff ruff-format pyproject-fmt codespell lint pre-commit test-run test build publish doc-watch doc-build doc-coverage doc [%- if project_name == "Serious Scaffold Python" %] template-watch template-build @@ -162,7 +162,7 @@ doc-coverage: test-run # Generate all documentation with reports. doc: doc-build mypy doc-coverage -[% if project_name == "Serious Scaffold Python" -%] +[% if project_name == "Serious Scaffold Python" %] ######################################################################################## # Template ######################################################################################## @@ -177,7 +177,7 @@ template-build: copier copy -r HEAD --data-file includes/copier-answers-sample.yml -f . . rm -rf .copier-answers.yml -[% endif -%] +[% endif %] ######################################################################################## # End ######################################################################################## diff --git a/template/README.md.jinja b/template/README.md.jinja index e33813e9..20c7b364 100644 --- a/template/README.md.jinja +++ b/template/README.md.jinja @@ -1,12 +1,12 @@ -[% from pathjoin("includes", "variable.jinja") import coverage_badge with context -%] -[% from pathjoin("includes", "variable.jinja") import license_badge with context -%] -[% from pathjoin("includes", "variable.jinja") import license_url with context -%] -[% from pathjoin("includes", "variable.jinja") import logo_badge with context -%] -[% from pathjoin("includes", "variable.jinja") import logo_badge_url with context -%] -[% from pathjoin("includes", "variable.jinja") import page_url with context -%] -[% from pathjoin("includes", "variable.jinja") import pipeline_badge with context -%] -[% from pathjoin("includes", "variable.jinja") import release_badge with context -%] -[% from pathjoin("includes", "variable.jinja") import repo_url with context -%] +[% from pathjoin("includes", "variable.jinja") import coverage_badge with context %] +[% from pathjoin("includes", "variable.jinja") import license_badge with context %] +[% from pathjoin("includes", "variable.jinja") import license_url with context %] +[% from pathjoin("includes", "variable.jinja") import logo_badge with context %] +[% from pathjoin("includes", "variable.jinja") import logo_badge_url with context %] +[% from pathjoin("includes", "variable.jinja") import page_url with context %] +[% from pathjoin("includes", "variable.jinja") import pipeline_badge with context %] +[% from pathjoin("includes", "variable.jinja") import release_badge with context %] +[% from pathjoin("includes", "variable.jinja") import repo_url with context %] # {{ project_name }} {{ project_description }} @@ -27,13 +27,13 @@ {{ logo_badge() }} [![Open in Dev Containers](https://img.shields.io/static/v1?label=Dev%20Containers&message=Open&color=blue&logo=visualstudiocode)](https://vscode.dev/redirect?url=vscode://ms-vscode-remote.remote-containers/cloneInVolume?url=https://{{ repo_url() }}) -[% if development_status == "Alpha" -%] +[% if development_status == "Alpha" %] > [!WARNING] -[% elif development_status == "Beta" -%] +[% elif development_status == "Beta" %] > [!IMPORTANT] -[% elif development_status == "Stable" -%] +[% elif development_status == "Stable" %] > [!NOTE] -[% endif -%] +[% endif %] > _{{ project_name }}_ is in the **{{ development_status }}** phase. [% if development_status == "Alpha" %] > Frequent changes and instability should be anticipated. diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja index 25ce5e94..8007c885 100644 --- a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/ci.yml.jinja @@ -1,4 +1,4 @@ -[% from pathjoin("includes", "version_compare.jinja") import version_between -%] +[% from pathjoin("includes", "version_compare.jinja") import version_between %] name: CI on: diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/devcontainer.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/devcontainer.yml.jinja index 963610bc..07c5aa8d 100644 --- a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/devcontainer.yml.jinja +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/devcontainer.yml.jinja @@ -1,4 +1,4 @@ -[% from pathjoin("includes", "version_compare.jinja") import version_between -%] +[% from pathjoin("includes", "version_compare.jinja") import version_between %] name: DevContainer on: diff --git a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/release.yml.jinja b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/release.yml.jinja index d3543c28..a252d631 100644 --- a/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/release.yml.jinja +++ b/template/[% if repo_platform == 'github' %].github[% endif %]/workflows/release.yml.jinja @@ -1,4 +1,4 @@ -[% from pathjoin("includes", "version_compare.jinja") import version_between -%] +[% from pathjoin("includes", "version_compare.jinja") import version_between %] name: Release on: diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja index bbdf7640..58e14fcf 100644 --- a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/ci.yml.jinja @@ -1,4 +1,4 @@ -[% from pathjoin("includes", "version_compare.jinja") import version_between -%] +[% from pathjoin("includes", "version_compare.jinja") import version_between %] ci: artifacts: reports: diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/devcontainer.yml.jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/devcontainer.yml.jinja index 323944e2..abe36fb8 100644 --- a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/devcontainer.yml.jinja +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/devcontainer.yml.jinja @@ -1,4 +1,4 @@ -[% from pathjoin("includes", "version_compare.jinja") import version_between -%] +[% from pathjoin("includes", "version_compare.jinja") import version_between %] dev-container-publish: image: docker:27.3.1@sha256:bec82cb05983f12a14d8f169b00748f4ded8573f4da5f1d15d375b6a2470289f parallel: diff --git a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja index 83867037..f61e485f 100644 --- a/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja +++ b/template/[% if repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %].gitlab[% endif %]/workflows/release.yml.jinja @@ -1,4 +1,4 @@ -[% from pathjoin("includes", "version_compare.jinja") import version_between -%] +[% from pathjoin("includes", "version_compare.jinja") import version_between %] pages-build: artifacts: paths: diff --git a/template/docs/development/git-workflow.md.jinja b/template/docs/development/git-workflow.md.jinja index b509b581..3146b7f5 100644 --- a/template/docs/development/git-workflow.md.jinja +++ b/template/docs/development/git-workflow.md.jinja @@ -1,4 +1,4 @@ -[% from pathjoin("includes", "variable.jinja") import repo_url with context -%] +[% from pathjoin("includes", "variable.jinja") import repo_url with context %] # Git Workflow This pages shows the recommended Git workflow to keep the local repository clean and organized while ensuring smooth collaboration among team members. diff --git a/template/docs/index.md.jinja b/template/docs/index.md.jinja index c882388a..fc8a9197 100644 --- a/template/docs/index.md.jinja +++ b/template/docs/index.md.jinja @@ -1,4 +1,4 @@ -[% from pathjoin("includes", "variable.jinja") import releases_url with context -%] +[% from pathjoin("includes", "variable.jinja") import releases_url with context %] # Welcome to {{ project_name }}'s documentation ```{toctree} diff --git a/template/docs/management/init.md.jinja b/template/docs/management/init.md.jinja index eedcfa2e..225a8553 100644 --- a/template/docs/management/init.md.jinja +++ b/template/docs/management/init.md.jinja @@ -1,4 +1,4 @@ -[% from pathjoin("includes", "variable.jinja") import repo_url with context -%] +[% from pathjoin("includes", "variable.jinja") import repo_url with context %] # Project Initialization ## Prerequisites diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 63c090c4..a2a46486 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -1,6 +1,6 @@ -[% from pathjoin("includes", "variable.jinja") import page_url with context -%] -[% from pathjoin("includes", "variable.jinja") import repo_url with context -%] -[% from pathjoin("includes", "version_compare.jinja") import version_between -%] +[% from pathjoin("includes", "variable.jinja") import page_url with context %] +[% from pathjoin("includes", "variable.jinja") import repo_url with context %] +[% from pathjoin("includes", "version_compare.jinja") import version_between %] [build-system] build-backend = "setuptools.build_meta" requires = [ @@ -74,9 +74,9 @@ dependencies = [ "pydantic-settings", ] urls.documentation = "https://{{ page_url() }}" -[% if repo_platform == 'github' -%] +[% if repo_platform == 'github' %] urls.issue = "https://{{ repo_url() }}/issues" -[% elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] +[% elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %] urls.issue = "https://{{ repo_url() }}/-/issues" [% endif %] urls.repository = "https://{{ repo_url() }}" @@ -112,7 +112,7 @@ fallback_version = "0.0.0" src = [ "src", ] -[% if project_name == "Serious Scaffold Python" -%] +[% if project_name == "Serious Scaffold Python" %] extend-exclude = [ "template", ] diff --git a/template/src/{{ module_name }}/settings.py.jinja b/template/src/{{ module_name }}/settings.py.jinja index 02137065..68d38a3c 100644 --- a/template/src/{{ module_name }}/settings.py.jinja +++ b/template/src/{{ module_name }}/settings.py.jinja @@ -1,4 +1,4 @@ -[% from pathjoin("includes", "version_compare.jinja") import version_higher_than -%] +[% from pathjoin("includes", "version_compare.jinja") import version_higher_than %] """Settings Module.""" import logging From 9d6297529a11a7319f2110af79fbbbc2c789813b Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Wed, 27 Nov 2024 07:47:32 +0000 Subject: [PATCH 4/7] simplify include sample --- includes/sample.jinja | 9 ++++----- template/README.md.jinja | 1 - 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/includes/sample.jinja b/includes/sample.jinja index adbfb27d..413f9d38 100644 --- a/includes/sample.jinja +++ b/includes/sample.jinja @@ -1,6 +1,6 @@ -[% macro readme_content() -%] -[% from pathjoin("includes", "variable.jinja") import page_url with context -%] -[% from pathjoin("includes", "variable.jinja") import repo_url with context -%] +[% macro readme_content() %] +[% from pathjoin("includes", "variable.jinja") import page_url with context %] +[% from pathjoin("includes", "variable.jinja") import repo_url with context %] [![{{ project_name }}](https://{{ page_url() }}/_static/images/logo.svg)](https://{{ repo_url() }}) Serious Scaffold Python is crafted for long-term, maintainable Python projects. It includes GitHub Actions and GitLab CI/CD, automated dependency updates via Renovate, and comprehensive linting, testing, and documentation. Key integrations like pdm for environment and dependency management, click for CLI development, and pydantic for configuration enhance project robustness. With copier’s easy project setup and continuous updating, your project stays aligned with best practices for sustainable development. Pre-configured dev containers and cross-platform CI support ensure maintainability from the start. @@ -75,5 +75,4 @@ pipx install copier==9.4.1 ``` 1. That's it! Feel free to focus on the coding within `src` folder. - -[%- endmacro %] +[% endmacro %] diff --git a/template/README.md.jinja b/template/README.md.jinja index 20c7b364..9ba0aea4 100644 --- a/template/README.md.jinja +++ b/template/README.md.jinja @@ -43,7 +43,6 @@ > Any feedback, comments, suggestions and contributions are welcome! {{ readme_content }} - ## 📜 License {{ copyright_license }}, for more details, see the [LICENSE]({{ license_url() }}) file. From 2beebb23094da944c985ac97384c02f0ff55dc33 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Thu, 28 Nov 2024 00:12:29 +0000 Subject: [PATCH 5/7] simplify includes variable --- copier.yaml | 5 ++- includes/variable.jinja | 88 ++++++++++++++++++++--------------------- 2 files changed, 47 insertions(+), 46 deletions(-) diff --git a/copier.yaml b/copier.yaml index e7d9454f..d3979312 100644 --- a/copier.yaml +++ b/copier.yaml @@ -1,6 +1,7 @@ _envops: - block_end_string: '%]' - block_start_string: '[%' + block_end_string: "%]" + block_start_string: "[%" + lstrip_blocks: true trim_blocks: true _subdirectory: template _message_before_copy: | diff --git a/includes/variable.jinja b/includes/variable.jinja index 8b73ca7e..4ba87b5a 100644 --- a/includes/variable.jinja +++ b/includes/variable.jinja @@ -1,75 +1,75 @@ -[% macro coverage_badge() -%] - [% if repo_platform == 'github' -%] +[% macro coverage_badge() %] + [% if repo_platform == 'github' %] [![Coverage](https://img.shields.io/endpoint?url=https://{{ page_url() }}/_static/badges/coverage.json)](https://{{ page_url() }}/reports/coverage) - [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] + [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %] [![coverage report](https://{{ repo_url() }}/badges/main/coverage.svg)](https://{{ repo_url() }}/-/commits/main) [%- endif %] -[%- endmacro %] +[% endmacro %] -[% macro license_badge() -%] - [% if repo_platform == 'github' -%] +[% macro license_badge() %] + [% if repo_platform == 'github' %] [![GitHub](https://img.shields.io/github/license/{{ repo_namespace }}/{{ repo_name }})]({{ license_url() }}) - [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] + [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %] [![GitLab](https://img.shields.io/gitlab/license/{{ repo_namespace }}/{{ repo_name }}?gitlab_url=https%3A%2F%2F{{ repo_host }})]({{ license_url() }}) - [%- endif -%] -[%- endmacro %] + [%- endif %] +[% endmacro %] -[% macro license_url() -%] - [% if repo_platform == 'github' -%] - https://{{ repo_url() }}/blob/main/LICENSE - [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] - https://{{ repo_url() }}/-/blob/main/LICENSE - [%- endif -%] -[%- endmacro %] +[% macro license_url() %] + [% if repo_platform == 'github' %] +https://{{ repo_url() }}/blob/main/LICENSE + [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %] +https://{{ repo_url() }}/-/blob/main/LICENSE + [%- endif %] +[% endmacro %] -[% macro logo_badge() -%] - [![Serious Scaffold Python]({{ logo_badge_url() }})](https://serious-scaffold.github.io/ss-python) +[% macro logo_badge() %] +[![Serious Scaffold Python]({{ logo_badge_url() }})](https://serious-scaffold.github.io/ss-python) [%- endmacro %] -[% macro logo_badge_url() -%] - https://img.shields.io/endpoint?url=https://serious-scaffold.github.io/ss-python/_static/badges/logo.json +[% macro logo_badge_url() %] +https://img.shields.io/endpoint?url=https://serious-scaffold.github.io/ss-python/_static/badges/logo.json [%- endmacro %] -[% macro page_url() -%] - [% if repo_platform == 'github' -%] - {{ repo_namespace }}.github.io/{{ repo_name }} - [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] - [%- set repo_namespace_root = repo_namespace.split("/")[0] -%] - {{ repo_namespace_root }}.{{ page_host }}{{ repo_namespace | replace(repo_namespace_root, "", 1) }}/{{ repo_name }} +[% macro page_url() %] + [% if repo_platform == 'github' %] +{{ repo_namespace }}.github.io/{{ repo_name }} + [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %] +[% set repo_namespace_root = repo_namespace.split("/")[0] %] +{{ repo_namespace_root }}.{{ page_host }}{{ repo_namespace | replace(repo_namespace_root, "", 1) }}/{{ repo_name }} [%- endif %] -[%- endmacro %] +[% endmacro %] -[% macro pipeline_badge() -%] - [% if repo_platform == 'github' -%] +[% macro pipeline_badge() %] +[% if repo_platform == 'github' %] [![CI](https://{{ repo_url() }}/actions/workflows/ci.yml/badge.svg)](https://{{ repo_url() }}/actions/workflows/ci.yml) [![CommitLint](https://{{ repo_url() }}/actions/workflows/commitlint.yml/badge.svg)](https://{{ repo_url() }}/actions/workflows/commitlint.yml) [![DevContainer](https://{{ repo_url() }}/actions/workflows/devcontainer.yml/badge.svg)](https://{{ repo_url() }}/actions/workflows/devcontainer.yml) [![Release](https://{{ repo_url() }}/actions/workflows/release.yml/badge.svg)](https://{{ repo_url() }}/actions/workflows/release.yml) [![Renovate](https://{{ repo_url() }}/actions/workflows/renovate.yml/badge.svg)](https://{{ repo_url() }}/actions/workflows/renovate.yml) [![Semantic Release](https://{{ repo_url() }}/actions/workflows/semantic-release.yml/badge.svg)](https://{{ repo_url() }}/actions/workflows/semantic-release.yml) - [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] + [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %] [![pipeline status](https://{{ repo_url() }}/badges/main/pipeline.svg)](https://{{ repo_url() }}/-/commits/main) [%- endif %] -[%- endmacro %] +[% endmacro %] -[% macro releases_url() -%] - [% if repo_platform == 'github' -%] - https://{{ repo_url() }}/releases - [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] - https://{{ repo_url() }}/-/releases - [%- endif -%] -[%- endmacro %] +[% macro releases_url() %] + [% if repo_platform == 'github' %] +https://{{ repo_url() }}/releases + [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %] +https://{{ repo_url() }}/-/releases + [%- endif %] +[% endmacro %] -[% macro release_badge() -%] - [% if repo_platform == 'github' -%] +[% macro release_badge() %] + [% if repo_platform == 'github' %] [![Release](https://img.shields.io/github/v/release/{{ repo_namespace }}/{{ repo_name }})] - [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' -%] + [%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %] [![Latest Release](https://{{ repo_url() }}/-/badges/release.svg)] - [%- endif -%] + [%- endif %] ({{ releases_url()}}) [![PyPI](https://img.shields.io/pypi/v/{{ package_name }})](https://pypi.org/project/{{ package_name }}/) [%- endmacro %] -[% macro repo_url() -%] - {{ repo_host }}/{{ repo_namespace }}/{{ repo_name }} +[% macro repo_url() %] +{{ repo_host }}/{{ repo_namespace }}/{{ repo_name }} [%- endmacro %] From 605370537966e2ff55d9cc6782bbeb4c91685ce2 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Thu, 28 Nov 2024 00:40:08 +0000 Subject: [PATCH 6/7] simplify block trim in copier.yaml --- copier.yaml | 118 ++++++++++++++++++++++++++-------------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/copier.yaml b/copier.yaml index d3979312..c507272f 100644 --- a/copier.yaml +++ b/copier.yaml @@ -22,7 +22,7 @@ _message_after_update: | you're done. project_name: default: My Project - help: 'Enter the name of the project in CamelCase format:' + help: "Enter the name of the project in CamelCase format:" type: str project_description: default: Project brief description. @@ -34,7 +34,7 @@ development_status: - Alpha - Beta - Production/Stable - help: 'Choose the development status:' + help: "Choose the development status:" type: str copyright_license: default: MIT License @@ -55,19 +55,19 @@ copyright_year: type: str author_name: default: Your Name - help: 'Specify the name of the author:' + help: "Specify the name of the author:" type: str organization_name: default: Your Organization Name - help: 'Provide the name of the organization associated with the project:' + help: "Provide the name of the organization associated with the project:" type: str copyright_holder: - default: '{{ organization_name }}' + default: "{{ organization_name }}" help: Name(s) or organization(s) holding the copyright. type: str author_email: default: '{{ author_name|lower|replace(" ", ".") }}@{{ organization_name|lower|replace(" ", "-") }}.com' - help: 'Specify the email address of the author:' + help: "Specify the email address of the author:" type: str repo_platform: default: github @@ -75,45 +75,45 @@ repo_platform: GitHub: github GitLab: gitlab GitLab (self-managed): gitlab-self-managed - help: 'Choose the platform for the repository:' + help: "Choose the platform for the repository:" type: str repo_host: default: |- - [% if repo_platform == 'github' -%] - github.com - [%- elif repo_platform == 'gitlab' -%] - gitlab.com + [% if repo_platform == 'github' %] + github.com + [%- elif repo_platform == 'gitlab' %] + gitlab.com [%- endif %] - help: 'Specify the host of the self-managed GitLab:' + help: "Specify the host of the self-managed GitLab:" type: str when: '{{ repo_platform == "gitlab-self-managed" }}' page_host: default: |- - [% if repo_platform == 'github' -%] - github.io - [%- elif repo_platform == 'gitlab' -%] - gitlab.io + [% if repo_platform == 'github' %] + github.io + [%- elif repo_platform == 'gitlab' %] + gitlab.io [%- endif %] - help: 'Specify the host of the self-managed GitLab Pages:' + help: "Specify the host of the self-managed GitLab Pages:" type: str when: '{{ repo_platform == "gitlab-self-managed" }}' container_registry_host: default: |- - [% if repo_platform == 'github' -%] - ghcr.io - [%- elif repo_platform == 'gitlab' -%] - registry.gitlab.com + [% if repo_platform == 'github' %] + ghcr.io + [%- elif repo_platform == 'gitlab' %] + registry.gitlab.com [%- endif %] - help: 'Specify the host of the self-managed GitLab Container Registry:' + help: "Specify the host of the self-managed GitLab Container Registry:" type: str when: '{{ repo_platform == "gitlab-self-managed" }}' repo_namespace: default: '{{ organization_name|lower|replace(" ", "-") }}' - help: 'Indicate the GitHub Repository Owner or GitLab Namespace. This is typically the account name of the author or the organization:' + help: "Indicate the GitHub Repository Owner or GitLab Namespace. This is typically the account name of the author or the organization:" type: str repo_name: default: '{{ project_name|lower|replace(" ", "-") }}' - help: 'Provide a name for the repository:' + help: "Provide a name for the repository:" type: str package_name: default: '{{ repo_name|regex_replace("-python$", "") }}' @@ -125,7 +125,7 @@ module_name: type: str coverage_threshold: default: 100 - help: 'Set the threshold for test coverage, ranging from 0 to 100:' + help: "Set the threshold for test coverage, ranging from 0 to 100:" type: int validator: "[% if not 0 <= coverage_threshold <= 100 %]Test Coverage threshold should be between 0 and 100[% endif %]" platforms: @@ -138,59 +138,59 @@ platforms: multiselect: true type: str min_py: - default: '3.12' + default: "3.12" choices: - - '3.9' - - '3.10' - - '3.11' - - '3.12' - - '3.13' - help: 'Choose the minimal Python version the project should support:' + - "3.9" + - "3.10" + - "3.11" + - "3.12" + - "3.13" + help: "Choose the minimal Python version the project should support:" type: str max_py: - default: '3.12' + default: "3.12" choices: - '3.9': + "3.9": validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.9", min_py) }}' - value: '3.9' - '3.10': + value: "3.9" + "3.10": validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.10", min_py) }}' - value: '3.10' - '3.11': + value: "3.10" + "3.11": validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.11", min_py) }}' - value: '3.11' - '3.12': + value: "3.11" + "3.12": validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.12", min_py) }}' - value: '3.12' - '3.13': - value: '3.13' - help: 'Choose the maximal Python version the project should support:' + value: "3.12" + "3.13": + value: "3.13" + help: "Choose the maximal Python version the project should support:" type: str default_py: - default: '{{ max_py }}' + default: "{{ max_py }}" choices: - '3.9': + "3.9": validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.9", min_py, max_py) }}' - value: '3.9' - '3.10': + value: "3.9" + "3.10": validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.10", min_py, max_py) }}' - value: '3.10' - '3.11': + value: "3.10" + "3.11": validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.11", min_py, max_py) }}' - value: '3.11' - '3.12': + value: "3.11" + "3.12": validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.12", min_py, max_py) }}' - value: '3.12' - '3.13': + value: "3.12" + "3.13": validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.13", min_py, max_py) }}' - value: '3.13' - help: 'Choose the default Python version for development, documentation generation, and package build:' + value: "3.13" + help: "Choose the default Python version for development, documentation generation, and package build:" type: str readme_content: default: |- - [% if project_name == 'Serious Scaffold Python' -%] - [% from pathjoin("includes", "sample.jinja") import readme_content with context %]{{ readme_content() }} - [%- else -%] + [% if project_name == 'Serious Scaffold Python' %] + [% from pathjoin("includes", "sample.jinja") import readme_content with context %]{{ readme_content() }} + [%- else %] ## A multiline README content here [%- endif %] help: "Provide a multiline content to be used in the README and documentation's index page:" From a136393825ef2051ae8c89f0087682a02ebca574 Mon Sep 17 00:00:00 2001 From: Xuan Hu Date: Thu, 28 Nov 2024 00:43:11 +0000 Subject: [PATCH 7/7] simplify includes version compare --- includes/version_compare.jinja | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/includes/version_compare.jinja b/includes/version_compare.jinja index 0fc94c36..2842f550 100644 --- a/includes/version_compare.jinja +++ b/includes/version_compare.jinja @@ -1,23 +1,23 @@ -[% macro version_higher_than(version1, version2) -%] - {{ "1" if version1.split(".") | map("int") | list >= version2.split(".") | map("int") | list }} +[% macro version_higher_than(version1, version2) %] +{{ "1" if version1.split(".") | map("int") | list >= version2.split(".") | map("int") | list }} [%- endmacro %] -[% macro version_higher_than_validator(version1, version2) -%] - {{ - "Invalid version. The version '%s' is not higher than '%s'." % (version1, version2) - if not version_higher_than(version1, version2) - }} +[% macro version_higher_than_validator(version1, version2) %] +{{ + "Invalid version. The version '%s' is not higher than '%s'." % (version1, version2) + if not version_higher_than(version1, version2) +}} [%- endmacro %] -[% macro version_between(version, version_min, version_max) -%] - {{ - "1" if version_min.split(".") | map("int") | list <= version.split(".") | map("int") | list <= version_max.split(".") | map("int") | list - }} +[% macro version_between(version, version_min, version_max) %] +{{ + "1" if version_min.split(".") | map("int") | list <= version.split(".") | map("int") | list <= version_max.split(".") | map("int") | list +}} [%- endmacro %] -[% macro version_between_validator(version, version_min, version_max) -%] - {{ - "Invalid version. The version '%s' is not between '%s' and '%s'." % (version, version_min, version_max) - if not version_between(version, version_min, version_max) - }} +[% macro version_between_validator(version, version_min, version_max) %] +{{ + "Invalid version. The version '%s' is not between '%s' and '%s'." % (version, version_min, version_max) + if not version_between(version, version_min, version_max) +}} [%- endmacro %]