diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 69090c5b..8fa448d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -60,7 +60,9 @@ jobs: - name: Generate the project with the default value run: | rm -rf src/serious_scaffold - copier copy -x '!src/serious_scaffold' -r HEAD -f . . + rm -rf .github + rm -rf .gitlab-ci.yml + copier copy -x '!src/serious_scaffold' -d ci=both -r HEAD -f . . - run: git diff - run: git status --porcelain - run: | diff --git a/.gitignore.jinja b/.gitignore.jinja index b1b96cb2..489ea814 100644 --- a/.gitignore.jinja +++ b/.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/.vscode/settings.json b/.vscode/settings.json index 42bd69fd..aebf53aa 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -72,6 +72,7 @@ "sortJSONValuesReverse": false }, "vscode-yaml-sort.customSortKeywords_2": [ + "_envops", "_exclude", "project_name", "project_description", @@ -86,6 +87,7 @@ "min_py", "max_py", "default_py", + "ci", "choices", "stages", "default", diff --git a/Makefile.jinja b/Makefile.jinja index fb980f19..15e6f22f 100644 --- a/Makefile.jinja +++ b/Makefile.jinja @@ -18,9 +18,9 @@ PUBLIC_DIR := $(if $(shell [ "$$READTHEDOCS" = "True" ] && echo 1),$$READTHEDOCS clean: -rm -rf \ ${PUBLIC_DIR} \ -{%- if project_name == "Serious Scaffold Python" %} +[%- if project_name == "Serious Scaffold Python" %] .copier-answers.yml \ -{%- endif %} +[%- endif %] .coverage \ .mypy_cache \ .pytest_cache \ diff --git a/.gitlab-ci.yml.jinja b/[% if ci == 'gitlab' or ci == 'both' %].gitlab-ci.yml[% endif %].jinja similarity index 76% rename from .gitlab-ci.yml.jinja rename to [% if ci == 'gitlab' or ci == 'both' %].gitlab-ci.yml[% endif %].jinja index 11ed9823..515ee7b6 100644 --- a/.gitlab-ci.yml.jinja +++ b/[% if ci == 'gitlab' or ci == 'both' %].gitlab-ci.yml[% endif %].jinja @@ -1,4 +1,4 @@ -{% from pathjoin("includes", "version_compare.jinja") import version_between -%} +[% from pathjoin("includes", "version_compare.jinja") import version_between -%] stages: - lint_test - build_release @@ -14,18 +14,18 @@ lint: parallel: matrix: - PYTHON_VERSION: -{%- if version_between("3.8", min_py, max_py) %} +[%- if version_between("3.8", min_py, max_py) %] - '3.8' -{%- endif %} -{%- if version_between("3.9", min_py, max_py) %} +[%- endif %] +[%- 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 %} +[%- endif %] script: - env | sort - make dev-lint @@ -47,18 +47,18 @@ test: parallel: matrix: - PYTHON_VERSION: -{%- if version_between("3.8", min_py, max_py) %} +[%- if version_between("3.8", min_py, max_py) %] - '3.8' -{%- endif %} -{%- if version_between("3.9", min_py, max_py) %} +[%- endif %] +[%- 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 %} +[%- endif %] script: - env | sort - make dev-test diff --git a/.github/FUNDING.yml.jinja b/[% if ci=='github' or ci == 'both' %].github[% endif %]/FUNDING.yml.jinja similarity index 100% rename from .github/FUNDING.yml.jinja rename to [% if ci=='github' or ci == 'both' %].github[% endif %]/FUNDING.yml.jinja diff --git a/.github/workflows/ci.yml.jinja b/[% if ci=='github' or ci == 'both' %].github[% endif %]/workflows/ci.yml.jinja similarity index 68% rename from .github/workflows/ci.yml.jinja rename to [% if ci=='github' or ci == 'both' %].github[% endif %]/workflows/ci.yml.jinja index 1f59a361..21838659 100644 --- a/.github/workflows/ci.yml.jinja +++ b/[% if ci=='github' or ci == 'both' %].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 -%] jobs: lint: runs-on: ubuntu-latest @@ -15,18 +15,18 @@ jobs: strategy: matrix: python-version: -{%- if version_between("3.8", min_py, max_py) %} +[%- if version_between("3.8", min_py, max_py) %] - '3.8' -{%- endif %} -{%- if version_between("3.9", min_py, max_py) %} +[%- endif %] +[%- 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 %} +[%- endif %] test: runs-on: ubuntu-latest steps: @@ -46,19 +46,19 @@ jobs: strategy: matrix: python-version: -{%- if version_between("3.8", min_py, max_py) %} +[%- if version_between("3.8", min_py, max_py) %] - '3.8' -{%- endif %} -{%- if version_between("3.9", min_py, max_py) %} +[%- endif %] +[%- 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 project_name == "Serious Scaffold Python" %} +[%- endif %] +[%- if project_name == "Serious Scaffold Python" %] consistency: runs-on: ubuntu-latest steps: @@ -78,7 +78,9 @@ jobs: - name: Generate the project with the default value run: | rm -rf src/serious_scaffold - copier copy -x '!src/serious_scaffold' -r HEAD -f . . + rm -rf .github + rm -rf .gitlab-ci.yml + copier copy -x '!src/serious_scaffold' -d ci=both -r HEAD -f . . - run: git diff - run: git status --porcelain - run: | @@ -88,19 +90,19 @@ jobs: strategy: matrix: python-version: -{%- if version_between("3.8", min_py, max_py) %} +[%- if version_between("3.8", min_py, max_py) %] - '3.8' -{%- endif %} -{%- if version_between("3.9", min_py, max_py) %} +[%- endif %] +[%- 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 %} -{%- endif %} +[%- endif %] +[%- endif %] name: CI on: pull_request: diff --git a/.github/workflows/readthedocs-preview.yml.jinja b/[% if ci=='github' or ci == 'both' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja similarity index 100% rename from .github/workflows/readthedocs-preview.yml.jinja rename to [% if ci=='github' or ci == 'both' %].github[% endif %]/workflows/readthedocs-preview.yml.jinja diff --git a/.github/workflows/release.yml.jinja b/[% if ci=='github' or ci == 'both' %].github[% endif %]/workflows/release.yml.jinja similarity index 100% rename from .github/workflows/release.yml.jinja rename to [% if ci=='github' or ci == 'both' %].github[% endif %]/workflows/release.yml.jinja diff --git a/copier.yaml b/copier.yaml index e0043155..ac319ec0 100644 --- a/copier.yaml +++ b/copier.yaml @@ -1,3 +1,6 @@ +_envops: + block_end_string: '%]' + block_start_string: '[%' _exclude: - '*.py[co]' - .DS_Store @@ -27,11 +30,11 @@ organization_name: type: str author_email: default: |- - {% if author_name == 'huxuan' and organization_name == 'Serious Scaffold' -%} + [% if author_name == 'huxuan' and organization_name == 'Serious Scaffold' -%] i@huxuan.org - {%- else -%} + [%- else -%] {{ author_name }}@{{ organization_name|lower|replace(" ", "-") }}.com - {%- endif %} + [%- endif %] help: 'Specify the email address of the author:' type: str repo_namespace: @@ -54,7 +57,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 %]' min_py: choices: - '3.8' @@ -67,13 +70,13 @@ min_py: max_py: choices: '3.8': - validator: '{% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %}{{ version_higher_than_validator("3.8", min_py) }}' + validator: '[% from pathjoin("includes", "version_compare.jinja") import version_higher_than_validator %]{{ version_higher_than_validator("3.8", min_py) }}' value: '3.8' '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': value: '3.11' @@ -83,17 +86,25 @@ max_py: default_py: choices: '3.8': - validator: '{% from pathjoin("includes", "version_compare.jinja") import version_between_validator %}{{ version_between_validator("3.8", min_py, max_py) }}' + validator: '[% from pathjoin("includes", "version_compare.jinja") import version_between_validator %]{{ version_between_validator("3.8", min_py, max_py) }}' value: '3.8' '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' default: '{{ max_py }}' help: 'Choose the default Python version for development, documentation generation, and package build:' type: str +ci: + choices: + Both (for test only): both + GitHub Actions: github + GitLab CI: gitlab + default: github + help: 'Choose the Continuous Integration service to use:' + type: str diff --git a/includes/version_compare.jinja b/includes/version_compare.jinja index 0f45c83f..0fc94c36 100644 --- a/includes/version_compare.jinja +++ b/includes/version_compare.jinja @@ -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 %] diff --git a/pyproject.toml.jinja b/pyproject.toml.jinja index e1903fe5..a39a047c 100644 --- a/pyproject.toml.jinja +++ b/pyproject.toml.jinja @@ -1,4 +1,4 @@ -{% from pathjoin("includes", "version_compare.jinja") import version_between -%} +[% from pathjoin("includes", "version_compare.jinja") import version_between -%] [build-system] build-backend = "setuptools.build_meta" requires = [ @@ -14,18 +14,18 @@ classifiers = [ "Development Status :: 4 - Beta", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", -{%- if version_between("3.10", min_py, max_py) %} +[%- 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.8", min_py, max_py) %} +[%- endif %] +[%- if version_between("3.8", min_py, max_py) %] "Programming Language :: Python :: 3.8", -{%- endif %} -{%- if version_between("3.9", min_py, max_py) %} +[%- endif %] +[%- if version_between("3.9", min_py, max_py) %] "Programming Language :: Python :: 3.9", -{%- endif %} +[%- endif %] ] description = "{{ project_description }}" dynamic = [ @@ -53,9 +53,9 @@ fail_under = {{ coverage_threshold }} [tool.coverage.run] omit = [ -{%- if project_name == "Serious Scaffold Python" %} +[%- if project_name == "Serious Scaffold Python" %] "src/{{ '{{ module_name }}' }}/**", -{%- endif %} +[%- endif %] ] source = [ "{{ module_name }}", @@ -73,9 +73,9 @@ enable_error_code = [ "ignore-without-code", ] exclude = [ -{%- if project_name == "Serious Scaffold Python" %} +[%- if project_name == "Serious Scaffold Python" %] "src/{{ '{{ module_name }}' }}", -{%- endif %} +[%- endif %] ] no_implicit_optional = true show_error_codes = true diff --git a/src/{{ module_name }}/settings.py.jinja b/src/{{ module_name }}/settings.py.jinja index b13e2b72..4cc53518 100644 --- a/src/{{ module_name }}/settings.py.jinja +++ b/src/{{ module_name }}/settings.py.jinja @@ -1,10 +1,10 @@ -{% 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 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 @@ -18,17 +18,17 @@ 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") %] # NOTE(huxuan): Pydantic cannot leverage future annotations at runtime prior to # Python 3.10, so `from __future__ import annotations` cannot be used here, and the # lint error need to be ignored unless the minimal Python version >= 3.10. # Reference: https://github.com/pydantic/pydantic/issues/3300#issuecomment-1034007897 logging_level: Optional[str] = getLevelName(logging.INFO) # noqa: FA100 -{%- else %} +[%- else %] logging_level: str | None = getLevelName(logging.INFO) -{%- endif %} +[%- endif %] """Default logging level for the project.""" model_config = SettingsConfigDict(