Skip to content

Commit

Permalink
refactor: revert to default block string in copier template (#886)
Browse files Browse the repository at this point in the history
  • Loading branch information
huxuan authored Jan 30, 2025
1 parent d217e25 commit 1919ef1
Show file tree
Hide file tree
Showing 35 changed files with 262 additions and 264 deletions.
48 changes: 23 additions & 25 deletions copier.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
_envops:
block_end_string: "%]"
block_start_string: "[%"
lstrip_blocks: true
trim_blocks: true
_subdirectory: template
Expand Down Expand Up @@ -79,31 +77,31 @@ repo_platform:
type: str
repo_host:
default: |-
[% if repo_platform == 'github' %]
{% if repo_platform == 'github' %}
github.com
[%- elif repo_platform == 'gitlab' %]
{%- elif repo_platform == 'gitlab' %}
gitlab.com
[%- endif %]
{%- endif %}
help: "Specify the host of the self-managed GitLab:"
type: str
when: '{{ repo_platform == "gitlab-self-managed" }}'
page_host:
default: |-
[% if repo_platform == 'github' %]
{% if repo_platform == 'github' %}
github.io
[%- elif repo_platform == 'gitlab' %]
{%- elif repo_platform == 'gitlab' %}
gitlab.io
[%- endif %]
{%- endif %}
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' %]
{% if repo_platform == 'github' %}
ghcr.io
[%- elif repo_platform == 'gitlab' %]
{%- elif repo_platform == 'gitlab' %}
registry.gitlab.com
[%- endif %]
{%- endif %}
help: "Specify the host of the self-managed GitLab Container Registry:"
type: str
when: '{{ repo_platform == "gitlab-self-managed" }}'
Expand All @@ -127,7 +125,7 @@ coverage_threshold:
default: 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 %]"
validator: "{% if not 0 <= coverage_threshold <= 100 %}Test Coverage threshold should be between 0 and 100{% endif %}"
platforms:
default: ["macos", "ubuntu", "windows"]
choices:
Expand All @@ -151,16 +149,16 @@ max_py:
default: "3.12"
choices:
"3.9":
validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.9", min_py) }}'
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":
validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.10", min_py) }}'
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":
validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.11", min_py) }}'
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":
validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.12", min_py) }}'
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"
Expand All @@ -170,29 +168,29 @@ default_py:
default: "{{ max_py }}"
choices:
"3.9":
validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.9", min_py, max_py) }}'
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":
validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.10", min_py, max_py) }}'
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":
validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.11", min_py, max_py) }}'
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":
validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.12", min_py, max_py) }}'
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":
validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.13", min_py, max_py) }}'
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:"
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 %]
{%- endif %}
help: "Provide a multiline content to be used in the README and documentation's index page:"
multiline: true
type: str
12 changes: 6 additions & 6 deletions includes/sample.jinja
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[% 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.

[% 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

Expand Down Expand Up @@ -76,4 +76,4 @@ pipx install copier==9.4.1
```

1. That's it! Feel free to focus on the coding within `src` folder.
[% endmacro %]
{% endmacro %}
84 changes: 42 additions & 42 deletions includes/variable.jinja
Original file line number Diff line number Diff line change
@@ -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 %]
{%- endif %}
{% 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' %]
{% macro license_url() %}
{% if repo_platform == 'github' %}
https://{{ repo_url() }}/blob/main/LICENSE
[%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %]
{%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %}
https://{{ repo_url() }}/-/blob/main/LICENSE
[%- endif %]
[% endmacro %]
{%- endif %}
{% endmacro %}

[% macro logo_badge() %]
{% macro logo_badge() %}
[![Serious Scaffold Python]({{ logo_badge_url() }})](https://serious-scaffold.github.io/ss-python)
[%- endmacro %]
{%- endmacro %}

[% macro logo_badge_url() %]
{% macro logo_badge_url() %}
https://img.shields.io/endpoint?url=https://serious-scaffold.github.io/ss-python/_static/badges/logo.json
[%- endmacro %]
{%- endmacro %}

[% macro page_url() %]
[% if repo_platform == 'github' %]
{% 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] %]
{%- 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 %]
{%- endif %}
{% 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 %]
{%- endif %}
{% endmacro %}

[% macro releases_url() %]
[% if repo_platform == 'github' %]
{% macro releases_url() %}
{% if repo_platform == 'github' %}
https://{{ repo_url() }}/releases
[%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %]
{%- elif repo_platform == 'gitlab' or repo_platform == 'gitlab-self-managed' %}
https://{{ repo_url() }}/-/releases
[%- endif %]
[% endmacro %]
{%- 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 %]
{%- endmacro %}

[% macro repo_url() %]
{% macro repo_url() %}
{{ repo_host }}/{{ repo_namespace }}/{{ repo_name }}
[%- endmacro %]
{%- endmacro %}
16 changes: 8 additions & 8 deletions includes/version_compare.jinja
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
[% macro version_higher_than(version1, version2) %]
{% macro version_higher_than(version1, version2) %}
{{ "1" if version1.split(".") | map("int") | list >= version2.split(".") | map("int") | list }}
[%- endmacro %]
{%- endmacro %}

[% macro version_higher_than_validator(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 %]
{%- endmacro %}

[% macro version_between(version, version_min, version_max) %]
{% 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 %]
{%- endmacro %}

[% macro version_between_validator(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 %]
{%- endmacro %}
4 changes: 2 additions & 2 deletions template/.gitignore.jinja
Original file line number Diff line number Diff line change
@@ -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

Expand Down
6 changes: 3 additions & 3 deletions template/.pre-commit-config.yaml.jinja
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions template/.releaserc.json.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Loading

0 comments on commit 1919ef1

Please sign in to comment.