From e493309b5fa184cb50f9835ab4f6982ffbbf9c9b Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Tue, 22 Oct 2024 10:33:15 +0200 Subject: [PATCH 1/7] feat: make use of dev platform optional --- copier.yml | 7 +++++++ template/pyproject.toml.jinja | 2 ++ 2 files changed, 9 insertions(+) diff --git a/copier.yml b/copier.yml index 791238a..b5ac6ce 100644 --- a/copier.yml +++ b/copier.yml @@ -30,7 +30,13 @@ package_description: multiline: true help: "Please provide a short description for the package." +use_git: + type: bool + default: yes + help: "Do you plan to use git with a development platform, like GitHub or GitLab?" + dev_platform: + when: "{{ use_git }}" type: str help: "Which development platform are you planning to use? Used to generate certain documentation and hyperlinks." choices: @@ -43,6 +49,7 @@ dev_platform_url: default: "https://{{ dev_platform|lower }}.com" username: + when: "{{ use_git }}" type: str help: "Your or your organization's username on {{ dev_platform }}. Used to generate certain documentation and hyperlinks." diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index f160c87..b18972b 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -49,8 +49,10 @@ dependencies = [] [project.urls] Homepage = "{{ dev_platform_url }}/{{ username }}/{{ project_slug }}" Documentation = "https://{{ project_slug }}.readthedocs.io" +{% if use_git -%} "Source Code" = "{{ dev_platform_url }}/{{ username }}/{{ project_slug }}" "Bug Tracker" = "{{ dev_platform_url }}/{{ username }}/{{ project_slug }}/issues" +{%- endif %} Download = "https://pypi.org/project/{{ project_slug }}/#files" [project.optional-dependencies] From 4a0a9db24ececf817e9c9b3b24e2c41852125ea7 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Tue, 22 Oct 2024 10:44:35 +0200 Subject: [PATCH 2/7] fix: handle white space --- template/.pre-commit-config.yaml.jinja | 6 +++--- template/pyproject.toml.jinja | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/template/.pre-commit-config.yaml.jinja b/template/.pre-commit-config.yaml.jinja index 9de1c44..cbda6b2 100644 --- a/template/.pre-commit-config.yaml.jinja +++ b/template/.pre-commit-config.yaml.jinja @@ -28,11 +28,11 @@ repos: - repo: https://github.com/python-jsonschema/check-jsonschema rev: 0.29.1 hooks: -{% if dev_platform == "GitHub" %} +{%- if dev_platform == "GitHub" %} - id: check-github-workflows -{% elif dev_platform == "GitLab" %} +{%- elif dev_platform == "GitLab" %} - id: check-gitlab-ci -{% endif %} +{%- endif %} - id: check-readthedocs - repo: https://github.com/executablebooks/mdformat rev: 0.7.17 diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index b18972b..a84fdbe 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -47,12 +47,12 @@ keywords = [] dependencies = [] [project.urls] +{%- if use_git %} Homepage = "{{ dev_platform_url }}/{{ username }}/{{ project_slug }}" -Documentation = "https://{{ project_slug }}.readthedocs.io" -{% if use_git -%} "Source Code" = "{{ dev_platform_url }}/{{ username }}/{{ project_slug }}" "Bug Tracker" = "{{ dev_platform_url }}/{{ username }}/{{ project_slug }}/issues" {%- endif %} +Documentation = "https://{{ project_slug }}.readthedocs.io" Download = "https://pypi.org/project/{{ project_slug }}/#files" [project.optional-dependencies] From 22e6fef7527baaf1044fb80a64339a4906d38ce5 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Tue, 22 Oct 2024 11:04:00 +0200 Subject: [PATCH 3/7] feat: make linting optional --- copier.yml | 7 ++++++- template/.pre-commit-config.yaml.jinja | 2 ++ template/pyproject.toml.jinja | 4 ++++ .../workflows/{test.yml => test.yml.jinja} | 6 ++++++ 4 files changed, 18 insertions(+), 1 deletion(-) rename template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/{test.yml => test.yml.jinja} (94%) diff --git a/copier.yml b/copier.yml index b5ac6ce..948dbdb 100644 --- a/copier.yml +++ b/copier.yml @@ -33,7 +33,7 @@ package_description: use_git: type: bool default: yes - help: "Do you plan to use git with a development platform, like GitHub or GitLab?" + help: "Do you want to use git with a development platform, like GitHub or GitLab?" dev_platform: when: "{{ use_git }}" @@ -53,6 +53,11 @@ username: type: str help: "Your or your organization's username on {{ dev_platform }}. Used to generate certain documentation and hyperlinks." +use_lint: + type: bool + default: yes + help: "Do you want to lint your code and generally check the formatting of your files?" + license: type: str help: "Which license do you want to use? Used in the license file." diff --git a/template/.pre-commit-config.yaml.jinja b/template/.pre-commit-config.yaml.jinja index cbda6b2..1ea2d64 100644 --- a/template/.pre-commit-config.yaml.jinja +++ b/template/.pre-commit-config.yaml.jinja @@ -1,4 +1,5 @@ repos: +{%- if use_lint %} - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.6.0 hooks: @@ -40,3 +41,4 @@ repos: - id: mdformat additional_dependencies: [mdformat-gfm, mdformat-frontmatter, mdformat-footnote] +{%- endif %} diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index a84fdbe..4f4c2f1 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -98,6 +98,7 @@ omit = [ exclude_lines = ["pragma: no cover"] precision = 2 +{%- if use_lint %} [tool.ruff] line-length = 88 @@ -141,6 +142,7 @@ arg-type-hints-in-docstring = false check-return-types = false check-yield-types = false exclude = "_version.py" +{%- endif %} # TODO: Adjust mypy configuration. #[tool.mypy] @@ -164,6 +166,7 @@ exclude = "_version.py" # Hatch Environments ################################################################################ +{%- if use_lint %} [tool.hatch.envs.style] description = """Check the style of the codebase.""" dependencies = [ @@ -177,6 +180,7 @@ docstrings = "pydoclint" code = "ruff check {args}" format = "ruff format {args}" check = ["docstrings", "code"] +{%- endif %} [tool.hatch.envs.audit] description = """Check dependencies for security vulnerabilities.""" diff --git a/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml b/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja similarity index 94% rename from template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml rename to template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja index dbd9692..f9027ce 100644 --- a/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml +++ b/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja @@ -5,6 +5,8 @@ on: workflow_call: {} jobs: +{%- if use_lint %} +{%- raw %} lint: runs-on: ${{ matrix.os }} strategy: @@ -32,7 +34,10 @@ jobs: - name: Build documentation run: hatch run docs:build +{%- endraw %} +{%- endif %} +{%- raw %} test: runs-on: ${{ matrix.os }} strategy: @@ -67,3 +72,4 @@ jobs: - name: Report coverage shell: bash run: bash <(curl -s https://codecov.io/bash) +{%- endraw %} From a597ef119b675dd55117ac8db72a93d7115e17ef Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Tue, 22 Oct 2024 11:14:32 +0200 Subject: [PATCH 4/7] refactor: make tests optional --- copier.yml | 5 +++++ template/pyproject.toml.jinja | 4 ++++ .../workflows/test.yml.jinja | 4 ++++ .../integration/.keep | 0 .../system/.keep | 0 .../system/test_import.py.jinja | 0 .../{tests => {% if use_test %}tests{% endif %}}/unit/.keep | 0 7 files changed, 13 insertions(+) rename template/{tests => {% if use_test %}tests{% endif %}}/integration/.keep (100%) rename template/{tests => {% if use_test %}tests{% endif %}}/system/.keep (100%) rename template/{tests => {% if use_test %}tests{% endif %}}/system/test_import.py.jinja (100%) rename template/{tests => {% if use_test %}tests{% endif %}}/unit/.keep (100%) diff --git a/copier.yml b/copier.yml index 948dbdb..0481d38 100644 --- a/copier.yml +++ b/copier.yml @@ -58,6 +58,11 @@ use_lint: default: yes help: "Do you want to lint your code and generally check the formatting of your files?" +use_test: + type: bool + default: yes + help: "Do you want to test your code? Generally, we strongly recommend that you do, but for a quick demo you may want to avoid this." + license: type: str help: "Which license do you want to use? Used in the license file." diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 4f4c2f1..5517758 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -77,6 +77,7 @@ version-file = "src/{{ package_name }}/_version.py" [tool.hatch.version] source = "vcs" +{%- if use_test %} [tool.pytest.ini_options] testpaths = ["tests"] markers = ["raises"] @@ -97,6 +98,7 @@ omit = [ [tool.coverage.report] exclude_lines = ["pragma: no cover"] precision = 2 +{%- endif %} {%- if use_lint %} [tool.ruff] @@ -227,6 +229,7 @@ check = [ "twine check dist/*", ] +{%- if use_test %} [tool.hatch.envs.test] description = """Run the test suite.""" extra-dependencies = [ @@ -242,3 +245,4 @@ python = ["3.9", "3.12"] [tool.hatch.envs.test.scripts] run = "pytest {args:--cov={{ package_name }} --cov-report=term-missing}" +{%- endif %} diff --git a/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja b/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja index f9027ce..931f68e 100644 --- a/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja +++ b/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja @@ -65,7 +65,10 @@ jobs: - name: Check types run: hatch run types:check +{%- endraw %} +{%- if use_test %} +{%- raw %} - name: Test suite run: hatch run +py=${{ matrix.python-version }} test:run @@ -73,3 +76,4 @@ jobs: shell: bash run: bash <(curl -s https://codecov.io/bash) {%- endraw %} +{%- endif %} diff --git a/template/tests/integration/.keep b/template/{% if use_test %}tests{% endif %}/integration/.keep similarity index 100% rename from template/tests/integration/.keep rename to template/{% if use_test %}tests{% endif %}/integration/.keep diff --git a/template/tests/system/.keep b/template/{% if use_test %}tests{% endif %}/system/.keep similarity index 100% rename from template/tests/system/.keep rename to template/{% if use_test %}tests{% endif %}/system/.keep diff --git a/template/tests/system/test_import.py.jinja b/template/{% if use_test %}tests{% endif %}/system/test_import.py.jinja similarity index 100% rename from template/tests/system/test_import.py.jinja rename to template/{% if use_test %}tests{% endif %}/system/test_import.py.jinja diff --git a/template/tests/unit/.keep b/template/{% if use_test %}tests{% endif %}/unit/.keep similarity index 100% rename from template/tests/unit/.keep rename to template/{% if use_test %}tests{% endif %}/unit/.keep From 2daa428d89fe5530c1c44aa88d32cf064ab65d79 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Tue, 22 Oct 2024 11:21:24 +0200 Subject: [PATCH 5/7] feat: make hatch environments optional --- copier.yml | 5 +++++ template/pyproject.toml.jinja | 2 ++ .../workflows/test.yml.jinja | 8 ++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/copier.yml b/copier.yml index 0481d38..8b83a0a 100644 --- a/copier.yml +++ b/copier.yml @@ -53,6 +53,11 @@ username: type: str help: "Your or your organization's username on {{ dev_platform }}. Used to generate certain documentation and hyperlinks." +use_hatch_envs: + type: bool + default: yes + help: "Do you want to use hatch environments for running isolated commands like linting, building docs, or testing?" + use_lint: type: bool default: yes diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 5517758..ec9ecb1 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -164,6 +164,7 @@ exclude = "_version.py" #init_typed = true #warn_required_dynamic_aliases = true +{%- if use_hatch_envs %} ################################################################################ # Hatch Environments ################################################################################ @@ -246,3 +247,4 @@ python = ["3.9", "3.12"] [tool.hatch.envs.test.scripts] run = "pytest {args:--cov={{ package_name }} --cov-report=term-missing}" {%- endif %} +{%- endif %} diff --git a/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja b/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja index 931f68e..9de0abc 100644 --- a/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja +++ b/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja @@ -22,7 +22,9 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} +{%- endraw %} +{%- if use_hatch_envs %} - name: Install hatch uses: pypa/hatch@install @@ -34,7 +36,7 @@ jobs: - name: Build documentation run: hatch run docs:build -{%- endraw %} +{%- endif %} {%- endif %} {%- raw %} @@ -53,7 +55,9 @@ jobs: uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} +{%- endraw %} +{%- if use_hatch_envs %} - name: Install hatch uses: pypa/hatch@install @@ -65,7 +69,6 @@ jobs: - name: Check types run: hatch run types:check -{%- endraw %} {%- if use_test %} {%- raw %} @@ -77,3 +80,4 @@ jobs: run: bash <(curl -s https://codecov.io/bash) {%- endraw %} {%- endif %} +{%- endif %} From c07bb792bfd76b2fb2042580a19316b8626165b8 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Tue, 22 Oct 2024 11:28:07 +0200 Subject: [PATCH 6/7] feat: make type checks optional --- copier.yml | 5 +++++ template/pyproject.toml.jinja | 6 ++++++ .../{py.typed => {% if use_types %}py.typed{% endif %}} | 0 .../workflows/test.yml.jinja | 2 ++ 4 files changed, 13 insertions(+) rename template/src/{{ package_name }}/{py.typed => {% if use_types %}py.typed{% endif %}} (100%) diff --git a/copier.yml b/copier.yml index 8b83a0a..8da290c 100644 --- a/copier.yml +++ b/copier.yml @@ -63,6 +63,11 @@ use_lint: default: yes help: "Do you want to lint your code and generally check the formatting of your files?" +use_types: + type: bool + default: yes + help: "Do you want to use typing annotations and type check your code?" + use_test: type: bool default: yes diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index ec9ecb1..39cde16 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -39,7 +39,9 @@ classifiers = [ "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Topic :: Scientific/Engineering", + {%- if use_types %} "Typing :: Typed", + {%- endif %} ] # TODO: add keywords keywords = [] @@ -146,6 +148,7 @@ check-yield-types = false exclude = "_version.py" {%- endif %} +{%- if use_types %} # TODO: Adjust mypy configuration. #[tool.mypy] #plugins = [ @@ -163,6 +166,7 @@ exclude = "_version.py" #init_forbid_extra = true #init_typed = true #warn_required_dynamic_aliases = true +{%- endif %} {%- if use_hatch_envs %} ################################################################################ @@ -194,6 +198,7 @@ extra-dependencies = [ [tool.hatch.envs.audit.scripts] check = ["pip-audit"] +{%- if use_types %} [tool.hatch.envs.types] description = """Check the static types of the codebase.""" dependencies = [ @@ -202,6 +207,7 @@ dependencies = [ [tool.hatch.envs.types.scripts] check = "mypy src/{{ package_name }}" +{%- endif %} [tool.hatch.envs.docs] description = """Build or serve the documentation.""" diff --git a/template/src/{{ package_name }}/py.typed b/template/src/{{ package_name }}/{% if use_types %}py.typed{% endif %} similarity index 100% rename from template/src/{{ package_name }}/py.typed rename to template/src/{{ package_name }}/{% if use_types %}py.typed{% endif %} diff --git a/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja b/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja index 9de0abc..2daf345 100644 --- a/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja +++ b/template/{% if dev_platform == 'GitHub' %}.github{% endif %}/workflows/test.yml.jinja @@ -67,8 +67,10 @@ jobs: - name: Check dependencies run: hatch run audit:check +{%- if use_types %} - name: Check types run: hatch run types:check +{%- endif %} {%- if use_test %} {%- raw %} From d7eab3abbdaa2485a3086e3e723adeb180acb068 Mon Sep 17 00:00:00 2001 From: "Moritz E. Beber" Date: Wed, 23 Oct 2024 12:55:27 +0200 Subject: [PATCH 7/7] feat: allow choice between dynamic or static version --- copier.yml | 5 +++++ template/pyproject.toml.jinja | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/copier.yml b/copier.yml index 8da290c..4541d77 100644 --- a/copier.yml +++ b/copier.yml @@ -30,6 +30,11 @@ package_description: multiline: true help: "Please provide a short description for the package." +use_vcs_version: + type: bool + default: yes + help: "Do you want to use dynamic versioning of your package or static? Dynamic means that versions use your version control system (VCS), such as git tags, for creating versions." + use_git: type: bool default: yes diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 39cde16..a2f41aa 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -4,7 +4,7 @@ [build-system] build-backend = "hatchling.build" -requires = ["hatchling", "hatch-vcs"] +requires = ["hatchling"{% if use_vcs_version %}, "hatch-vcs"{% endif %}] ################################################################################ # Project Configuration @@ -12,7 +12,11 @@ requires = ["hatchling", "hatch-vcs"] [project] name = "{{ package_name }}" +{% if use_vcs_version %} dynamic = ["version"] +{% else %} +version = "0.1.0" +{% endif %} description = "{{ package_description }}" authors = [ { name = "{{ author_name }}", email = "{{ author_email }}" }, @@ -73,11 +77,13 @@ only-packages = true [tool.hatch.build.targets.wheel] packages = ["src/{{ package_name }}"] +{%- if use_vcs_version %} [tool.hatch.build.hooks.vcs] version-file = "src/{{ package_name }}/_version.py" [tool.hatch.version] source = "vcs" +{%- endif %} {%- if use_test %} [tool.pytest.ini_options] @@ -93,9 +99,11 @@ source = [ [tool.coverage.run] branch = true parallel = true +{%- if use_vcs_version %} omit = [ "src/{{ package_name }}/_version.py", ] +{%- endif %} [tool.coverage.report] exclude_lines = ["pragma: no cover"] @@ -118,9 +126,11 @@ ignore = [ "ANN101", # 'Missing type annotation for {self} in method'. "ANN102", # 'Missing type annotation for {cls} in classmethod'. ] +{%- if use_vcs_version %} exclude = [ "src/{{ package_name }}/_version.py", ] +{%- endif %} [tool.ruff.lint.extend-per-file-ignores] "__init__.py" = [ @@ -145,8 +155,10 @@ style = "google" # TODO: Other styles are possible here, like 'numpy' arg-type-hints-in-docstring = false check-return-types = false check-yield-types = false +{%- if use_vcs_version %} exclude = "_version.py" {%- endif %} +{%- endif %} {%- if use_types %} # TODO: Adjust mypy configuration.