Improve mypy execution and less dependencies and manual/hard-coded Bash commands.

This commit is contained in:
Patrick Lehmann
2025-09-13 18:35:32 +02:00
parent f79a63bf8e
commit 15c9a23136
8 changed files with 65 additions and 99 deletions

View File

@@ -196,10 +196,7 @@ jobs:
- UnitTestingParams - UnitTestingParams
with: with:
python_version: ${{ needs.UnitTestingParams.outputs.python_version }} python_version: ${{ needs.UnitTestingParams.outputs.python_version }}
commands: | html_report: ${{ needs.ConfigParams.outputs.typing_report_html_directory }}
${{ needs.ConfigParams.outputs.mypy_prepare_command }}
mypy --html-report report/typing -p ${{ needs.ConfigParams.outputs.package_fullname }}
html_report: 'report/typing'
html_artifact: ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).statictyping_html }} html_artifact: ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).statictyping_html }}
DocCoverage: DocCoverage:

View File

@@ -98,6 +98,10 @@ on:
coverage_report_json: coverage_report_json:
description: "" description: ""
value: ${{ jobs.Extract.outputs.coverage_report_json }} value: ${{ jobs.Extract.outputs.coverage_report_json }}
typing_report_html_directory:
description: ""
value: ${{ jobs.Extract.outputs.typing_report_html_directory }}
jobs: jobs:
Extract: Extract:
@@ -120,6 +124,7 @@ jobs:
coverage_report_json_directory: ${{ steps.getVariables.outputs.coverage_report_json_directory }} coverage_report_json_directory: ${{ steps.getVariables.outputs.coverage_report_json_directory }}
coverage_report_json_filename: ${{ steps.getVariables.outputs.coverage_report_json_filename }} coverage_report_json_filename: ${{ steps.getVariables.outputs.coverage_report_json_filename }}
coverage_report_json: ${{ steps.getVariables.outputs.coverage_report_json }} coverage_report_json: ${{ steps.getVariables.outputs.coverage_report_json }}
typing_report_html_directory: ${{ steps.getVariables.outputs.typing_report_html_directory }}
steps: steps:
- name: ⏬ Checkout repository - name: ⏬ Checkout repository
@@ -194,6 +199,7 @@ jobs:
coverageXMLFile = Path("./coverage.xml") coverageXMLFile = Path("./coverage.xml")
coverageJSONFile = Path("./coverage.json") coverageJSONFile = Path("./coverage.json")
coverageRC = "${{ inputs.coverage_config }}".strip() coverageRC = "${{ inputs.coverage_config }}".strip()
typingHTMLDirectory = Path("htmlmypy")
# Read output paths from 'pyproject.toml' file # Read output paths from 'pyproject.toml' file
if coverageRC == "pyproject.toml": if coverageRC == "pyproject.toml":
@@ -207,6 +213,7 @@ jobs:
coverageHTMLDirectory = Path(pyProjectSettings["tool"]["coverage"]["html"]["directory"]) coverageHTMLDirectory = Path(pyProjectSettings["tool"]["coverage"]["html"]["directory"])
coverageXMLFile = Path(pyProjectSettings["tool"]["coverage"]["xml"]["output"]) coverageXMLFile = Path(pyProjectSettings["tool"]["coverage"]["xml"]["output"])
coverageJSONFile= Path(pyProjectSettings["tool"]["coverage"]["json"]["output"]) coverageJSONFile= Path(pyProjectSettings["tool"]["coverage"]["json"]["output"])
typingHTMLDirectory = Path(pyProjectSettings["tool"]["mypy"]["html_report"])
else: else:
print(f"File '{pyProjectFile}' not found.") print(f"File '{pyProjectFile}' not found.")
print(f"::error title=FileNotFoundError::File '{pyProjectFile}' not found.") print(f"::error title=FileNotFoundError::File '{pyProjectFile}' not found.")
@@ -245,6 +252,7 @@ jobs:
coverage_report_json_directory={coverageJSONFile.parent.as_posix()} coverage_report_json_directory={coverageJSONFile.parent.as_posix()}
coverage_report_json_filename={coverageJSONFile.name} coverage_report_json_filename={coverageJSONFile.name}
coverage_report_json={coverageJSONFile.as_posix()} coverage_report_json={coverageJSONFile.as_posix()}
typing_report_html_directory={typingHTMLDirectory.as_posix()}
""")) """))
print(dedent(f"""\ print(dedent(f"""\
@@ -254,4 +262,5 @@ jobs:
coverage html: {coverageHTMLDirectory} coverage html: {coverageHTMLDirectory}
coverage xml: {coverageXMLFile} coverage xml: {coverageXMLFile}
coverage json: {coverageJSONFile} coverage json: {coverageJSONFile}
typing html: {typingHTMLDirectory}
""")) """))

View File

@@ -57,7 +57,7 @@ jobs:
PDFDocumentation: PDFDocumentation:
name: 📓 Converting LaTeX Documentation to PDF name: 📓 Converting LaTeX Documentation to PDF
runs-on: "ubuntu-${{ inputs.ubuntu_image_version }}" runs-on: "ubuntu-${{ inputs.ubuntu_image_version }}"
continue-on-error: ${{ inputs.can-fail }} continue-on-error: ${{ inputs.can-fail == 'true' }}
steps: steps:
- name: 📥 Download artifacts '${{ inputs.latex_artifact }}' from 'SphinxDocumentation' job - name: 📥 Download artifacts '${{ inputs.latex_artifact }}' from 'SphinxDocumentation' job
uses: pyTooling/download-artifact@v5 uses: pyTooling/download-artifact@v5

View File

@@ -255,6 +255,9 @@ jobs:
version=${version} version=${version}
EOF EOF
# TODO: why not is_release_commit?
# TODO: how to support version branches and hotfix releases on version branches?
- name: 🔁 Find merged PullRequest from second parent of current SHA (${{ github.sha }}) - name: 🔁 Find merged PullRequest from second parent of current SHA (${{ github.sha }})
id: FindPullRequest id: FindPullRequest
if: steps.Classify.outputs.is_merge_commit == 'true' if: steps.Classify.outputs.is_merge_commit == 'true'

View File

@@ -40,14 +40,10 @@ on:
required: false required: false
default: '-r tests/requirements.txt' default: '-r tests/requirements.txt'
type: string type: string
commands:
description: 'Commands to run the static type checks.'
required: true
type: string
html_report: html_report:
description: 'Directory to upload as an artifact.' description: 'Directory to upload as an artifact.'
required: false required: false
default: 'htmlmypy' default: 'report/typing'
type: string type: string
junit_report: junit_report:
description: 'junit file to upload as an artifact.' description: 'junit file to upload as an artifact.'

View File

@@ -84,10 +84,7 @@ jobs:
- UnitTestingParams - UnitTestingParams
with: with:
python_version: ${{ needs.UnitTestingParams.outputs.python_version }} python_version: ${{ needs.UnitTestingParams.outputs.python_version }}
commands: | html_report: ${{ needs.ConfigParams.outputs.typing_report_html_directory }}
${{ needs.ConfigParams.outputs.mypy_prepare_command }}
mypy --html-report report/typing -p ${{ needs.ConfigParams.outputs.package_fullname }}
html_report: 'report/typing'
html_artifact: ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).statictyping_html }} html_artifact: ${{ fromJson(needs.UnitTestingParams.outputs.artifact_names).statictyping_html }}
DocCoverage: DocCoverage:

View File

@@ -55,6 +55,7 @@ jobs:
version=4.2.0 version=4.2.0
tool=myTool tool=myTool
prog=program prog=program
tag: 4.2.0
title: "Nightly Test Release" title: "Nightly Test Release"
description: | description: |
This *nightly* release contains all latest and important artifacts created by %tool%'s CI pipeline. This *nightly* release contains all latest and important artifacts created by %tool%'s CI pipeline.

View File

@@ -40,52 +40,60 @@ results can be converted to a HTML report and uploaded as an artifact.
Instantiation Instantiation
************* *************
Simple Example
==============
This example runs mypy for the Python package ``myPackage`` according to the configuration stored in
:file:`pyproject.toml`. It prints a report into the job's log. In addition is generates a report in HTML format into the
directory ``report/typing``.
.. grid:: 2 .. grid:: 2
.. grid-item:: .. grid-item::
:columns: 6 :columns: 6
.. card:: Simple Example
This example runs mypy for the Python package ``myPackage``. It renders a report into the job's log. In
addition is generates a report in HTML format into the directory ``htmlmypy``.
.. code-block:: yaml .. code-block:: yaml
jobs: jobs:
StaticTypeCheck: StaticTypeCheck:
uses: pyTooling/Actions/.github/workflows/StaticTypeCheck.yml@r5 uses: pyTooling/Actions/.github/workflows/StaticTypeCheck.yml@r5
with: with:
commands: | html_report: 'htmlmpyp'
mypy --html-report htmlmypy -p myPackage artifact: 'TypeChecking'
report: 'htmlmypy'
artifact: TypeChecking
.. grid-item:: .. grid-item::
:columns: 6 :columns: 6
.. card:: Complex Example .. code-block:: toml
.. code-block:: yaml [tool.mypy]
packages = ["myPackage"]
strict = true
pretty = true
html_report = "htmlmpyp"
Complex Example
===============
To ease the handling of mypy parameters stored in :file:`pyproject.toml`, the :ref:`JOBTMPL/ExtractConfiguration` is
used to extract the set configuration parameters for later usage. Similarly, :ref:`JOBTMPL/Parameters` is used to
precompute the artifact's name.
.. code-block:: yaml
jobs: jobs:
StaticTypeCheck: ConfigParams:
uses: pyTooling/Actions/.github/workflows/StaticTypeCheck.yml@r5 uses: pyTooling/Actions/.github/workflows/ExtractConfiguration.yml@r5
needs:
- Params
with: with:
python_version: ${{ needs.Params.outputs.python_version }} package_name: myPackage
commands: |
touch myFramework/__init__.py
mypy --html-report htmlmypy -p myFramework.Extension
report: 'htmlmypy'
artifact: ${{ fromJson(needs.Params.outputs.artifact_names).statictyping_html }}
.. card:: Complex Example Params:
uses: pyTooling/Actions/.github/workflows/Parameters.yml@r5
with:
package_name: myPackage
.. code-block:: yaml
jobs:
StaticTypeCheck: StaticTypeCheck:
uses: pyTooling/Actions/.github/workflows/StaticTypeCheck.yml@r5 uses: pyTooling/Actions/.github/workflows/StaticTypeCheck.yml@r5
needs: needs:
@@ -93,40 +101,9 @@ Instantiation
- Params - Params
with: with:
python_version: ${{ needs.Params.outputs.python_version }} python_version: ${{ needs.Params.outputs.python_version }}
commands: | report: ${{ needs.ConfigParams.outputs.typing_report_html_directory }}
${{ needs.ConfigParams.outputs.mypy_prepare_command }}
mypy --html-report htmlmypy -p ${{ needs.ConfigParams.outputs.package_fullname }}
report: 'htmlmypy'
artifact: ${{ fromJson(needs.Params.outputs.artifact_names).statictyping_html }} artifact: ${{ fromJson(needs.Params.outputs.artifact_names).statictyping_html }}
Commands
********
Example ``commands``:
1. Regular package
.. code-block:: yaml
commands: mypy --html-report htmlmypy -p ToolName
2. Parent namespace package
.. code-block:: yaml
commands: |
touch Parent/__init__.py
mypy --html-report htmlmypy -p ToolName
3. Child namespace package
.. code-block:: yaml
commands: |
cd Parent
mypy --html-report ../htmlmypy -p ToolName
.. _JOBTMPL/StaticTypeCheck/Parameters: .. _JOBTMPL/StaticTypeCheck/Parameters:
@@ -144,9 +121,7 @@ Parameter Summary
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+ +---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
| :ref:`JOBTMPL/StaticTypeCheck/Input/requirements` | no | string | ``'-r tests/requirements.txt'`` | | :ref:`JOBTMPL/StaticTypeCheck/Input/requirements` | no | string | ``'-r tests/requirements.txt'`` |
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+ +---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
| :ref:`JOBTMPL/StaticTypeCheck/Input/commands` | yes | string | — — — — | | :ref:`JOBTMPL/StaticTypeCheck/Input/html_report` | no | string | ``'report/typing'`` |
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
| :ref:`JOBTMPL/StaticTypeCheck/Input/html_report` | no | string | ``'htmlmypy'`` |
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+ +---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
| :ref:`JOBTMPL/StaticTypeCheck/Input/junit_report` | no | string | ``'StaticTypingSummary.xml'`` | | :ref:`JOBTMPL/StaticTypeCheck/Input/junit_report` | no | string | ``'StaticTypingSummary.xml'`` |
+---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+ +---------------------------------------------------------------------+----------+----------+-------------------------------------------------------------------+
@@ -193,18 +168,6 @@ requirements
:Description: Python dependencies to be installed through *pip*. :Description: Python dependencies to be installed through *pip*.
.. _JOBTMPL/StaticTypeCheck/Input/commands:
commands
========
:Type: string
:Required: yes
:Default Value: — — — —
:Possible Values: tbd
:Description: tbd
.. _JOBTMPL/StaticTypeCheck/Input/html_report: .. _JOBTMPL/StaticTypeCheck/Input/html_report:
html_report html_report
@@ -212,7 +175,7 @@ html_report
:Type: string :Type: string
:Required: no :Required: no
:Default Value: ``'htmlmypy'`` :Default Value: ``'report/typing'``
:Possible Values: Any valid directory or subdirectory path. :Possible Values: Any valid directory or subdirectory path.
:Description: The directory containing the generated HTML report. :Description: The directory containing the generated HTML report.