From c89db106cf1f6a256277f08aeaef91755b71dd4b Mon Sep 17 00:00:00 2001 From: sverhoeven Date: Tue, 16 Sep 2025 16:24:33 +0200 Subject: [PATCH 1/6] Use --keep-copied-projects --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 849988cd..0065accf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -33,7 +33,7 @@ in line with what is recommended there. If not, please [contribute to the guide] 1. (**important**) wait until some kind of consensus is reached about your idea being a good idea; 1. if needed, fork the repository to your own Github profile and create your own feature branch off of the latest main commit. While working on your feature branch, make sure to stay up to date with the main branch by pulling in changes, possibly from the 'upstream' repository (follow the instructions [here](https://help.github.com/articles/configuring-a-remote-for-a-fork/) and [here](https://help.github.com/articles/syncing-a-fork/)); 1. install dependencies (see the [development documentation](README.dev.md#create-a-virtual-environment)); -1. make sure the existing tests still work by running ``pytest``. If project tests fail use ``pytest --keep-baked-projects`` to keep generated project files in `/tmp/pytest-*` and investigate; +1. make sure the existing tests still work by running ``pytest``. If project tests fail use ``pytest --keep-copied-projects`` to keep generated project files in `/tmp/pytest-*` and investigate; 1. add your own tests (if necessary); 1. update or expand the documentation; 1. update the `CHANGELOG.md` file with your change; From 8a8083db2d789d3c14c965d727188563a4af5f31 Mon Sep 17 00:00:00 2001 From: sverhoeven Date: Tue, 16 Sep 2025 16:25:16 +0200 Subject: [PATCH 2/6] Typing questiones for py.typed + mypy or pyright + ci + docs Fixes #230 --- copier.yml | 4 ++ copier/global_flags.yml | 3 +- copier/questions/features_typing.yml | 57 +++++++++++++++++++ template/README.md.jinja | 6 ++ template/pyproject.toml.jinja | 18 ++++++ .../src/{{package_name}}/my_module.py.jinja | 4 +- .../{% if AddPyTyped %}py.typed{% endif %} | 0 ...AddDevDoc %}README.dev.md{% endif %}.jinja | 21 +++++++ .../conf.py.jinja | 3 + .../pre-commit | 2 + ...ubActionBuild %}build.yml{% endif %}.jinja | 26 +++++++++ 11 files changed, 141 insertions(+), 3 deletions(-) create mode 100644 copier/questions/features_typing.yml create mode 100644 template/src/{{package_name}}/{% if AddPyTyped %}py.typed{% endif %} diff --git a/copier.yml b/copier.yml index b9ef5ab7..652907a5 100644 --- a/copier.yml +++ b/copier.yml @@ -30,6 +30,10 @@ # community features !include copier/questions/features_community.yml +--- +# typing features +!include copier/questions/features_typing.yml + --- # global flags !include copier/global_flags.yml diff --git a/copier/global_flags.yml b/copier/global_flags.yml index 11702aeb..730136ff 100644 --- a/copier/global_flags.yml +++ b/copier/global_flags.yml @@ -12,5 +12,6 @@ HasWorkflows: or AddOnlineDocumentation or AddSonarCloud or AddZenodo - or AddLinting }}" + or AddLinting + or AddGithubActionTypeCheck }}" when: false diff --git a/copier/questions/features_typing.yml b/copier/questions/features_typing.yml new file mode 100644 index 00000000..14aca562 --- /dev/null +++ b/copier/questions/features_typing.yml @@ -0,0 +1,57 @@ +--- +# Questions for typing features + +# the main menu +SelectTypingFeatures: + when: "{{ template_profile != 'minimum' }}" + type: yaml + default: |- + {% if template_profile == 'recommended' %} + [AddTyping_flag, AddTypingInDocs_flag, AddGitHubActionTypeCheck_flag] + {%- else -%} + [] + {%- endif %} + help: Select typing features + multiselect: true + choices: + Support Typing (add py.typed file): + value: AddTyping_flag + GitHub Action to type check: + value: AddGitHubActionTypeCheck_flag + Typing in API documentation: + value: AddTypingInDocs_flag + +# TODO add runtime type checking (using pydantic or typeguard) + +SelectTypeChecker: + when: "{{ template_profile != 'minimum' and 'AddTyping_flag' in SelectTypingFeatures }}" + type: str + default: |- + {%- if template_profile == 'recommended' -%} + pyright + {%- endif %} + help: Select a type checker + choices: + Mypy: + value: mypy + Pyright: + value: pyright + # TODO add pyrefly https://pyrefly.org/ + # TODO add ty https://github.com/astral-sh/ty + +AddPyTyped: + type: bool + default: "{{ 'AddTyping_flag' in SelectTypingFeatures }}" + when: false + +AddGithubActionTypeCheck: + type: bool + default: "{{ 'AddGitHubActionTypeCheck_flag' in SelectTypingFeatures and SelectTypeChecker != '' }}" + when: false + +AddTypingInDocs: + type: bool + default: "{{ 'AddTypingInDocs_flag' in SelectTypingFeatures }}" + when: false + +# TODO ask how strict to typecheck \ No newline at end of file diff --git a/template/README.md.jinja b/template/README.md.jinja index 8523375a..c6a473dc 100644 --- a/template/README.md.jinja +++ b/template/README.md.jinja @@ -29,6 +29,12 @@ {% if AddLinkCheck -%} | Link checker | [![link-check]({{repository_url}}/actions/workflows/link-check.yml/badge.svg)]({{repository_url}}/actions/workflows/link-check.yml) | {%- endif -%} +{% if SelectTypeChecker == 'pyright' -%} +| Type checker | [![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/) | +{%- endif -%} +{% if SelectTypeChecker == 'mypy' -%} +| Type checker | [![Checked with mypy](https://mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/) | +{%- endif -%} ## How to use {{ package_name }} diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index 821cfc14..b57e1cf3 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -58,6 +58,12 @@ dev = [ {%- endif %} "tox", "myst_parser", + {% if SelectTypeChecker -%} + "{{ SelectTypeChecker }}", + {%- endif %} + {%- if 'AddTypingInDocs_flag' in SelectTypingFeatures %} + "sphinx-autodoc-typehints", + {%- endif %} ] {%- if AddLocalDocumentation %} docs = [ @@ -65,6 +71,9 @@ docs = [ "sphinx_rtd_theme", "sphinx-autoapi", "myst_parser", + {%- if 'AddTypingInDocs_flag' in SelectTypingFeatures %} + "sphinx-autodoc-typehints", + {%- endif %} ] {%- endif %} publishing = [ @@ -147,6 +156,15 @@ known-first-party = ["{{ package_name }}"] force-single-line = true no-lines-before = ["future","standard-library","third-party","first-party","local-folder"] +{% if SelectTypeChecker == 'pyright' -%} +[tool.pyright] +include = ["src"] +{%- endif %} +{% if SelectTypeChecker == 'mypy' -%} +[tool.mypy] +files = ["src"] +{%- endif %} + [tool.bumpversion] current_version = "{{ version }}" diff --git a/template/src/{{package_name}}/my_module.py.jinja b/template/src/{{package_name}}/my_module.py.jinja index 7248f258..4a9143eb 100644 --- a/template/src/{{package_name}}/my_module.py.jinja +++ b/template/src/{{package_name}}/my_module.py.jinja @@ -8,10 +8,10 @@ def hello(name: str) -> str: Function docstring using Google docstring style. Args: - name (str): Name to say hello to + name{% if not AddTypingInDocs %} (str){% endif %}: Name to say hello to Returns: - str: Hello message + {% if not AddTypingInDocs %}str: {% endif %}Hello message Raises: ValueError: If `name` is equal to `nobody` diff --git a/template/src/{{package_name}}/{% if AddPyTyped %}py.typed{% endif %} b/template/src/{{package_name}}/{% if AddPyTyped %}py.typed{% endif %} new file mode 100644 index 00000000..e69de29b diff --git a/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja b/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja index a12eafcb..2821ca87 100644 --- a/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja +++ b/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja @@ -87,6 +87,27 @@ git config --local core.hooksPath .githooks ``` {%- endif -%} +{%- if SelectTypeChecker -%} +## Type checking + +{% if SelectTypeChecker == 'pyright' -%} +We use [pyright](https://microsoft.github.io/pyright/) for type checking. + +```shell +pyright +``` + +{% endif -%} +{% if SelectTypeChecker == 'mypy' -%} +We use [mypy](http://mypy-lang.org/) for type checking. + +```shell +mypy . +``` + +{% endif -%} +{% endif -%} + ## Generating the API docs ```shell diff --git a/template/{% if AddLocalDocumentation %}docs{% endif %}/conf.py.jinja b/template/{% if AddLocalDocumentation %}docs{% endif %}/conf.py.jinja index ea6ff9a8..102df1e7 100644 --- a/template/{% if AddLocalDocumentation %}docs{% endif %}/conf.py.jinja +++ b/template/{% if AddLocalDocumentation %}docs{% endif %}/conf.py.jinja @@ -46,6 +46,9 @@ extensions = [ "sphinx.ext.viewcode", "autoapi.extension", "myst_parser", + {%- if AddTypingInDocs %} + "sphinx_autodoc_typehints", + {%- endif %} ] # Add any paths that contain templates here, relative to this directory. diff --git a/template/{% if AddPreCommit %}.githooks{% endif %}/pre-commit b/template/{% if AddPreCommit %}.githooks{% endif %}/pre-commit index c4bc8dd3..f4e6e322 100755 --- a/template/{% if AddPreCommit %}.githooks{% endif %}/pre-commit +++ b/template/{% if AddPreCommit %}.githooks{% endif %}/pre-commit @@ -9,6 +9,8 @@ echo "Starting ruff analysis..." ruff check --fix ruff format +# TODO add type checker + # use return code to abort commit if necessary if [ $? != "0" ]; then echo "Commit aborted. Fix linter issues found by ruff before committing." diff --git a/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja b/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja index 264f69bf..2c368f9c 100644 --- a/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja +++ b/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja @@ -64,3 +64,29 @@ jobs: ruff check ruff format --check {%- endif %} + +{%- if AddGitHubActionTypeCheck %} + typecheck: + name: Type checking + runs-on: ubuntu-latest + strategy: + fail-fast: false + steps: + - uses: actions/checkout@v5 + - name: Set up Python 3.12 + uses: actions/setup-python@v6 + with: + python-version: 3.12 + - name: Upgrade pip and install dependencies + run: | + python -m pip install --upgrade pip setuptools + python -m pip install .[dev] + - name: Run {{ SelectTypeChecker }} + run: | + {% if SelectTypeChecker == 'pyright' %} + pyright + {% endif %} + {% if SelectTypeChecker == 'mypy' %} + mypy + {% endif %} +{%- endif %} \ No newline at end of file From dd6c368a36b29793d8223ae0ec5df1cbae1a5fd8 Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Wed, 17 Sep 2025 09:13:48 +0200 Subject: [PATCH 3/6] Move typing into code quality multi select + less questions --- copier.yml | 4 -- copier/global_flags.yml | 3 +- copier/questions/features_code_quality.yml | 9 +++- copier/questions/features_documentation.yml | 4 ++ copier/questions/features_typing.yml | 49 +++---------------- template/README.md.jinja | 2 + template/pyproject.toml.jinja | 8 +-- ... => {% if AddTyping %}py.typed{% endif %}} | 0 ...AddDevDoc %}README.dev.md{% endif %}.jinja | 3 +- .../pre-commit | 2 +- ...ubActionBuild %}build.yml{% endif %}.jinja | 8 ++- 11 files changed, 32 insertions(+), 60 deletions(-) rename template/src/{{package_name}}/{{% if AddPyTyped %}py.typed{% endif %} => {% if AddTyping %}py.typed{% endif %}} (100%) diff --git a/copier.yml b/copier.yml index 652907a5..b9ef5ab7 100644 --- a/copier.yml +++ b/copier.yml @@ -30,10 +30,6 @@ # community features !include copier/questions/features_community.yml ---- -# typing features -!include copier/questions/features_typing.yml - --- # global flags !include copier/global_flags.yml diff --git a/copier/global_flags.yml b/copier/global_flags.yml index 730136ff..11702aeb 100644 --- a/copier/global_flags.yml +++ b/copier/global_flags.yml @@ -12,6 +12,5 @@ HasWorkflows: or AddOnlineDocumentation or AddSonarCloud or AddZenodo - or AddLinting - or AddGithubActionTypeCheck }}" + or AddLinting }}" when: false diff --git a/copier/questions/features_code_quality.yml b/copier/questions/features_code_quality.yml index 82a0afc7..c636adcb 100644 --- a/copier/questions/features_code_quality.yml +++ b/copier/questions/features_code_quality.yml @@ -7,7 +7,7 @@ SelectCodeQualityFeatures: type: yaml default: |- {% if template_profile == 'recommended' %} - [AddLocalTests_flag, SelectGitHubActions_flag, AddLinting_flag, AddSonarCloud_flag, AddEditorConfig_flag] + [AddLocalTests_flag, SelectGitHubActions_flag, AddLinting_flag, AddSonarCloud_flag, AddEditorConfig_flag, AddTyping_flag] {%- else -%} [] {%- endif %} @@ -32,7 +32,8 @@ SelectCodeQualityFeatures: Editorconfig: value: AddEditorConfig_flag # validator: "{% if something != 'AnotherThing' %}BlaBla{% endif %}" - + Typing (select type checker later): + value: AddTyping_flag # Sub-menus SelectGitHubActions: @@ -54,6 +55,10 @@ SelectGitHubActions: value: AddLinkCheck_flag # validator: "{% if something != 'AnotherThing' %}BlaBla{% endif %}" +--- +# typing features +!include copier/questions/features_typing.yml +--- # computed features AddLocalTests: diff --git a/copier/questions/features_documentation.yml b/copier/questions/features_documentation.yml index cc4098d3..bee43b1a 100644 --- a/copier/questions/features_documentation.yml +++ b/copier/questions/features_documentation.yml @@ -44,3 +44,7 @@ AddGitHubActionDocumentation: type: bool default: "{{ 'AddGitHubActionDocumentation_flag' in SelectDocumentationFeatures }}" when: false +AddTypingInDocs: + type: bool + default: "{{ AddTyping and AddLocalDocumentation }}" + when: false diff --git a/copier/questions/features_typing.yml b/copier/questions/features_typing.yml index 14aca562..db5b4a6d 100644 --- a/copier/questions/features_typing.yml +++ b/copier/questions/features_typing.yml @@ -1,35 +1,15 @@ --- # Questions for typing features -# the main menu -SelectTypingFeatures: - when: "{{ template_profile != 'minimum' }}" - type: yaml - default: |- - {% if template_profile == 'recommended' %} - [AddTyping_flag, AddTypingInDocs_flag, AddGitHubActionTypeCheck_flag] - {%- else -%} - [] - {%- endif %} - help: Select typing features - multiselect: true - choices: - Support Typing (add py.typed file): - value: AddTyping_flag - GitHub Action to type check: - value: AddGitHubActionTypeCheck_flag - Typing in API documentation: - value: AddTypingInDocs_flag - -# TODO add runtime type checking (using pydantic or typeguard) +AddTyping: + type: bool + default: "{{ 'AddTyping_flag' in SelectCodeQualityFeatures }}" + when: false SelectTypeChecker: - when: "{{ template_profile != 'minimum' and 'AddTyping_flag' in SelectTypingFeatures }}" + when: "{{ template_profile != 'minimum' and AddTyping }}" type: str - default: |- - {%- if template_profile == 'recommended' -%} - pyright - {%- endif %} + default: pyright help: Select a type checker choices: Mypy: @@ -39,19 +19,6 @@ SelectTypeChecker: # TODO add pyrefly https://pyrefly.org/ # TODO add ty https://github.com/astral-sh/ty -AddPyTyped: - type: bool - default: "{{ 'AddTyping_flag' in SelectTypingFeatures }}" - when: false - -AddGithubActionTypeCheck: - type: bool - default: "{{ 'AddGitHubActionTypeCheck_flag' in SelectTypingFeatures and SelectTypeChecker != '' }}" - when: false - -AddTypingInDocs: - type: bool - default: "{{ 'AddTypingInDocs_flag' in SelectTypingFeatures }}" - when: false +# TODO add runtime type checking (using pydantic or typeguard) -# TODO ask how strict to typecheck \ No newline at end of file +# TODO ask how strict to typecheck diff --git a/template/README.md.jinja b/template/README.md.jinja index c6a473dc..4d32610e 100644 --- a/template/README.md.jinja +++ b/template/README.md.jinja @@ -29,12 +29,14 @@ {% if AddLinkCheck -%} | Link checker | [![link-check]({{repository_url}}/actions/workflows/link-check.yml/badge.svg)]({{repository_url}}/actions/workflows/link-check.yml) | {%- endif -%} +{% if AddTyping -%} {% if SelectTypeChecker == 'pyright' -%} | Type checker | [![Checked with pyright](https://microsoft.github.io/pyright/img/pyright_badge.svg)](https://microsoft.github.io/pyright/) | {%- endif -%} {% if SelectTypeChecker == 'mypy' -%} | Type checker | [![Checked with mypy](https://mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/) | {%- endif -%} +{%- endif %} ## How to use {{ package_name }} diff --git a/template/pyproject.toml.jinja b/template/pyproject.toml.jinja index b57e1cf3..7c8e23ab 100644 --- a/template/pyproject.toml.jinja +++ b/template/pyproject.toml.jinja @@ -58,10 +58,10 @@ dev = [ {%- endif %} "tox", "myst_parser", - {% if SelectTypeChecker -%} + {% if AddTyping and SelectTypeChecker -%} "{{ SelectTypeChecker }}", {%- endif %} - {%- if 'AddTypingInDocs_flag' in SelectTypingFeatures %} + {%- if AddTypingInDocs %} "sphinx-autodoc-typehints", {%- endif %} ] @@ -71,7 +71,7 @@ docs = [ "sphinx_rtd_theme", "sphinx-autoapi", "myst_parser", - {%- if 'AddTypingInDocs_flag' in SelectTypingFeatures %} + {%- if AddTypingInDocs %} "sphinx-autodoc-typehints", {%- endif %} ] @@ -156,6 +156,7 @@ known-first-party = ["{{ package_name }}"] force-single-line = true no-lines-before = ["future","standard-library","third-party","first-party","local-folder"] +{% if AddTyping -%} {% if SelectTypeChecker == 'pyright' -%} [tool.pyright] include = ["src"] @@ -164,6 +165,7 @@ include = ["src"] [tool.mypy] files = ["src"] {%- endif %} +{%- endif %} [tool.bumpversion] current_version = "{{ version }}" diff --git a/template/src/{{package_name}}/{% if AddPyTyped %}py.typed{% endif %} b/template/src/{{package_name}}/{% if AddTyping %}py.typed{% endif %} similarity index 100% rename from template/src/{{package_name}}/{% if AddPyTyped %}py.typed{% endif %} rename to template/src/{{package_name}}/{% if AddTyping %}py.typed{% endif %} diff --git a/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja b/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja index 2821ca87..745914f1 100644 --- a/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja +++ b/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja @@ -87,7 +87,7 @@ git config --local core.hooksPath .githooks ``` {%- endif -%} -{%- if SelectTypeChecker -%} +{% if AddTyping %} ## Type checking {% if SelectTypeChecker == 'pyright' -%} @@ -104,7 +104,6 @@ We use [mypy](http://mypy-lang.org/) for type checking. ```shell mypy . ``` - {% endif -%} {% endif -%} diff --git a/template/{% if AddPreCommit %}.githooks{% endif %}/pre-commit b/template/{% if AddPreCommit %}.githooks{% endif %}/pre-commit index f4e6e322..3f9fdf74 100755 --- a/template/{% if AddPreCommit %}.githooks{% endif %}/pre-commit +++ b/template/{% if AddPreCommit %}.githooks{% endif %}/pre-commit @@ -9,7 +9,7 @@ echo "Starting ruff analysis..." ruff check --fix ruff format -# TODO add type checker +# TODO add type checker? # use return code to abort commit if necessary if [ $? != "0" ]; then diff --git a/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja b/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja index 2c368f9c..43e338b5 100644 --- a/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja +++ b/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja @@ -65,12 +65,10 @@ jobs: ruff format --check {%- endif %} -{%- if AddGitHubActionTypeCheck %} +{%- if AddTyping %} typecheck: name: Type checking runs-on: ubuntu-latest - strategy: - fail-fast: false steps: - uses: actions/checkout@v5 - name: Set up Python 3.12 @@ -85,8 +83,8 @@ jobs: run: | {% if SelectTypeChecker == 'pyright' %} pyright - {% endif %} + {% endif -%} {% if SelectTypeChecker == 'mypy' %} mypy - {% endif %} + {% endif -%} {%- endif %} \ No newline at end of file From 602ab8fb6f01db108310927003237dd1ef0d97d3 Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Wed, 17 Sep 2025 09:30:15 +0200 Subject: [PATCH 4/6] pytest does not like include so embed it --- CHANGELOG.md | 2 ++ copier/questions/features_code_quality.yml | 25 ++++++++++++++++++---- copier/questions/features_typing.yml | 24 --------------------- 3 files changed, 23 insertions(+), 28 deletions(-) delete mode 100644 copier/questions/features_typing.yml diff --git a/CHANGELOG.md b/CHANGELOG.md index 19e06afa..d260b95b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ ### Added +- Typing support. [#698](https://github.com/NLeSC/python-template/pull/698) + ### Changed ### Removed diff --git a/copier/questions/features_code_quality.yml b/copier/questions/features_code_quality.yml index c636adcb..b6bc377d 100644 --- a/copier/questions/features_code_quality.yml +++ b/copier/questions/features_code_quality.yml @@ -55,10 +55,27 @@ SelectGitHubActions: value: AddLinkCheck_flag # validator: "{% if something != 'AnotherThing' %}BlaBla{% endif %}" ---- -# typing features -!include copier/questions/features_typing.yml ---- +AddTyping: + type: bool + default: "{{ 'AddTyping_flag' in SelectCodeQualityFeatures }}" + when: false + +SelectTypeChecker: + when: "{{ template_profile != 'minimum' and AddTyping }}" + type: str + default: pyright + help: Select a type checker + choices: + Mypy: + value: mypy + Pyright: + value: pyright + # TODO add pyrefly https://pyrefly.org/ + # TODO add ty https://github.com/astral-sh/ty + +# TODO add runtime type checking (using pydantic or typeguard) + +# TODO ask how strict to typecheck # computed features AddLocalTests: diff --git a/copier/questions/features_typing.yml b/copier/questions/features_typing.yml deleted file mode 100644 index db5b4a6d..00000000 --- a/copier/questions/features_typing.yml +++ /dev/null @@ -1,24 +0,0 @@ ---- -# Questions for typing features - -AddTyping: - type: bool - default: "{{ 'AddTyping_flag' in SelectCodeQualityFeatures }}" - when: false - -SelectTypeChecker: - when: "{{ template_profile != 'minimum' and AddTyping }}" - type: str - default: pyright - help: Select a type checker - choices: - Mypy: - value: mypy - Pyright: - value: pyright - # TODO add pyrefly https://pyrefly.org/ - # TODO add ty https://github.com/astral-sh/ty - -# TODO add runtime type checking (using pydantic or typeguard) - -# TODO ask how strict to typecheck From 1b57e03db8c3f8b180c2622b1be2d46b57ccf354 Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Thu, 2 Oct 2025 15:46:54 +0200 Subject: [PATCH 5/6] No args are needed for type linter in ci Co-authored-by: Sander van Rijn --- ...{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja b/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja index 43e338b5..c0e451fc 100644 --- a/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja +++ b/template/{% if HasWorkflows %}.github{% endif %}/workflows/{% if AddGitHubActionBuild %}build.yml{% endif %}.jinja @@ -81,10 +81,5 @@ jobs: python -m pip install .[dev] - name: Run {{ SelectTypeChecker }} run: | - {% if SelectTypeChecker == 'pyright' %} - pyright - {% endif -%} - {% if SelectTypeChecker == 'mypy' %} - mypy - {% endif -%} + {{ SelectTypeChecker }} {%- endif %} \ No newline at end of file From 4390b9e9d7835d51a326ae90fe60ac763de3c6ae Mon Sep 17 00:00:00 2001 From: Stefan Verhoeven Date: Tue, 7 Oct 2025 08:56:38 +0200 Subject: [PATCH 6/6] Apply review suggestions --- template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja | 2 +- template/{% if AddPreCommit %}.githooks{% endif %}/pre-commit | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja b/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja index 745914f1..11cb34a5 100644 --- a/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja +++ b/template/{% if AddDevDoc %}README.dev.md{% endif %}.jinja @@ -102,7 +102,7 @@ pyright We use [mypy](http://mypy-lang.org/) for type checking. ```shell -mypy . +mypy ``` {% endif -%} {% endif -%} diff --git a/template/{% if AddPreCommit %}.githooks{% endif %}/pre-commit b/template/{% if AddPreCommit %}.githooks{% endif %}/pre-commit index 3f9fdf74..c4bc8dd3 100755 --- a/template/{% if AddPreCommit %}.githooks{% endif %}/pre-commit +++ b/template/{% if AddPreCommit %}.githooks{% endif %}/pre-commit @@ -9,8 +9,6 @@ echo "Starting ruff analysis..." ruff check --fix ruff format -# TODO add type checker? - # use return code to abort commit if necessary if [ $? != "0" ]; then echo "Commit aborted. Fix linter issues found by ruff before committing."