# Tasks The **`nmk-python`** plugin defines the tasks described below. --- ## Setup tasks All tasks in this chapter are dependencies of the base [**`setup`**](https://nmk-base.readthedocs.io/en/stable/tasks.html#setup-task) task. --- (py.version)= ### **`py.version`** -- Python version stamping This task creates/updates the **{ref}`${pythonVersionStamp}`** stamp file, only when [${gitVersion}](https://nmk-base.readthedocs.io/en/stable/config.html#gitversion-git-version) has changed. This allows incremental build depending on python version change (i.e. trigger rebuild if only version changed). | Property | Value/description | | -------- | ---------------------------------------------------------------------------------------------------------------------------------- | | builder | {py:class}`nmk_python.version.PythonVersionRefresh` | | input | [${gitVersionStamp}](https://nmk-base.readthedocs.io/en/stable/config.html#gitversionstamp-git-version-resolution-stamp-file) file | | output | {ref}`${pythonVersionStamp}` file | The builder is called with the following parameters mapping: | Name | Value | | ------- | ------------------------------------------ | | version | **{ref}`${pythonVersion}`** | ```{note} *Behavior changed in version 1.7.0*
In former versions, this task was only triggered if {ref}`${pythonSrcFiles}` were found. ``` --- (py.project)= ### **`py.project`** -- Python project file generation This task generates the **{ref}`${pythonProjectFile}`** project file. | Property | Value/description | | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------- | | builder | [nmk_base.common.TomlFileBuilder](https://nmk-base.readthedocs.io/en/stable/autoapi/nmk_base/common/index.html#nmk_base.common.TomlFileBuilder) | | input | {ref}`${pythonProjectFileFragments}` files | | output | {ref}`${pythonProjectFile}` file | The builder is called with the following parameters mapping: | Name | Value | | -------------- | -------------------------------------------------------------------- | | fragment_files | **{ref}`${pythonProjectFileFragments}`** | | items | **{ref}`${pythonProjectFileItems}`** | | plugin_name | "nmk-python" | ```{note} *Behavior changed in version 1.7.0*
In former versions, this task was only triggered if {ref}`${pythonSrcFiles}` were found. ``` --- ## Build tasks --- ### Preprocessing tasks All tasks in this chapter are dependencies of the base [**`build.preprocess`**](https://nmk-base.readthedocs.io/en/stable/tasks.html#build-preprocess-task) task. _Changed in version 1.10.2_ -- previous dependency was on main [**`build`**](https://nmk-base.readthedocs.io/en/stable/tasks.html#build-task) task. --- (py.format)= #### **`py.format`** -- Python code format This task calls **`ruff format`** command to format python code of this project. | Property | Value/description | | -------- | ----------------------------------------------------------------------------------------------- | | builder | {py:class}`nmk_python.ruff.RuffBuilder` | | input | {ref}`${pythonSrcFiles}` + {ref}`${pythonProjectFile}` files | | output | {ref}`${pythonRuffFormatStamp}` file | | if | {ref}`${pythonSrcFiles}` are found | The builder is called with the following parameters mapping: | Name | Value | | ----------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | src_folders | **{ref}`${pythonSrcFolders}`** | | command | format {ref}`${pythonRuffCommonExtraArgs}` {ref}`${pythonRuffFormatExtraArgs}`

_Changed in version 1.2_ -- Previous value was `"format"` | --- (py.fix)= #### **`py.fix`** -- Python code fix This task calls **`ruff check --fix-only`** command to fix python code of this project. See {ref}`${pythonAutoFixRules}` config item to define [rules categories](https://docs.astral.sh/ruff/rules/) to auto-fix. | Property | Value/description | | -------- | ----------------------------------------------------------------------------------------------- | | builder | {py:class}`nmk_python.ruff.RuffBuilder` | | input | {ref}`${pythonSrcFiles}` + {ref}`${pythonProjectFile}` files | | output | {ref}`${pythonRuffFixStamp}` file | | if | {ref}`${pythonSrcFiles}` are found | The builder is called with the following parameters mapping: | Name | Value | | ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | src_folders | **{ref}`${pythonSrcFolders}`** | | command | check --fix-only --select {ref}`${pythonAutoFixJoinedRules}` {ref}`${pythonRuffCommonExtraArgs}` {ref}`${pythonRuffFixExtraArgs}` | _Added in version 1.2_ --- (py.analyze)= #### **`py.analyze`** -- Python code analysis This task calls **`ruff check`** command to analyze python code of this project. | Property | Value/description | | -------- | ----------------------------------------------------------------------------------------------- | | builder | {py:class}`nmk_python.ruff.RuffBuilder` | | input | {ref}`${pythonSrcFiles}` + {ref}`${pythonProjectFile}` files | | output | {ref}`${pythonRuffCheckStamp}` file | | if | {ref}`${pythonSrcFiles}` are found | The builder is called with the following parameters mapping: | Name | Value | | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | src_folders | **{ref}`${pythonSrcFolders}`** | | command | check {ref}`${pythonRuffCommonExtraArgs}` {ref}`${pythonRuffCheckExtraArgs}`

_Changed in version 1.2_ -- Previous value was `"check"` | --- ### Compilation tasks All tasks in this chapter are dependencies of the base [**`build.compile`**](https://nmk-base.readthedocs.io/en/stable/tasks.html#build-compile-task) task. _Changed in version 1.10.2_ -- previous dependency was on main [**`build`**](https://nmk-base.readthedocs.io/en/stable/tasks.html#build-task) task. --- (py.editable)= #### **`py.editable`** -- Python project install in editable mode This task installs the project in editable mode in the venv. | Property | Value/description | | -------- | ------------------------------------------------------- | | builder | {py:class}`nmk_python.build.EditableBuilder` | | input | {ref}`${pythonProjectFile}` file | | output | {ref}`${pythonEditableStamp}` file | | if | {ref}`${pythonSrcFiles}` are found | --- (py.deps)= #### **`py.deps`** -- Generate Python dependencies metadata This task generates the {ref}`${pythonDepsMetadata}` metadata json file, containing all current project dependencies versions (indexed by name). Dependencies are splitted between **internal** and **external** ones: - **internal** dependencies are all ones matching with any pattern defined in {ref}`${pythonLocalDepsPatterns}` (if any) - **external** dependencies are all the other ones | Property | Value/description | | -------- | ----------------------------------------------------- | | builder | {py:class}`nmk_python.build.DepsMetadataBuilder` | | input | {ref}`${pythonProjectFile}` file | | output | {ref}`${pythonDepsMetadata}` file | | if | {ref}`${pythonSrcFiles}` are found | The builder is called with the following parameters mapping: | Name | Value | | ---------- | ---------------------------------------------------------- | | root_name | {ref}`${pythonPackage}` | | local_deps | {ref}`${pythonLocalDepsPatterns}` | _Added in version 1.8.0_ --- ## Tests tasks All tasks in this chapter are dependencies of the base [**`tests`**](https://nmk-base.readthedocs.io/en/stable/tasks.html#tests-task) task. --- (py.tests)= ### **`py.tests`** -- Run Python tests This task calls **`pytest`** command to execute python tests. | Property | Value/description | | -------- | ---------------------------------------------------------- | | builder | {py:class}`nmk_python.tests.PytestBuilder` | | if | {ref}`${pythonTestSrcFiles}` are found | The builder is called with the following parameters mapping: | Name | Value | | ----------- | ---------------------------------------------- | | pytest_args | **{ref}`${pytestExtraArgs}`** | --- ## Package tasks All tasks in this chapter are dependencies of the base [**`package`**](https://nmk-base.readthedocs.io/en/stable/tasks.html#package-task) task. --- (py.build)= ### **`py.build`** -- Build Python wheel This task use the python **`build`** module to handle the wheel build. | Property | Value/description | | -------- | ----------------------------------------------------------------------------------------------- | | builder | {py:class}`nmk_python.build.PackageBuilder` | | input | {ref}`${pythonSrcFiles}` + {ref}`${pythonProjectFile}` files | | output | {ref}`${pythonWheel}` file | | if | {ref}`${pythonSrcFiles}` are found | The builder is called with the following parameters mapping: | Name | Value | | --------------- | -------------------------------------------------------- | | project_file | **{ref}`${pythonProjectFile}`** | | version_file | **{ref}`${pythonVersionStamp}`** | | source_dirs | **{ref}`${pythonSrcFolders}`** | | artifacts_dir | **{ref}`${pythonArtifacts}`** | | build_dir | **{ref}`${pythonBuildDir}`** | | extra_resources | **{ref}`${pythonExtraResources}`** | --- ## Install tasks All tasks in this chapter are dependencies of the base [**`install`**](https://nmk-base.readthedocs.io/en/stable/tasks.html#install-task) task. --- (py.install)= ### **`py.install`** -- Install Python wheel This task installs the built python wheel in the project venv. | Property | Value/description | | -------- | ------------------------------------------------------------------------------------------------------------- | | builder | {py:class}`nmk_python.build.Installer` | | input | {ref}`${pythonWheel}` file | | output | [${venvState}](https://nmk-base.readthedocs.io/en/stable/config.html#venvstate-output-requirements-file-name) | | if | {ref}`${pythonSrcFiles}` are found | The builder is called with the following parameters mapping: | Name | Value | | --------- | ----------------------------------------------------------------------------------------------------------- | | name | **{ref}`${pythonPackage}`** | | wheel | **{ref}`${pythonWheel}`**

_Changed in version 1.7.0_ | | to_remove | **{ref}`${pythonEditableStamp}`** | The builder also removes the **{ref}`${pythonEditableStamp}`** stamp file, to force installing the project in editable mode again on the next build. --- ## Clean tasks All tasks in this chapter are dependencies of the base [**`clean`**](https://nmk-base.readthedocs.io/en/stable/tasks.html#clean-task) task. --- (py.uninstall)= ### **`py.uninstall`** -- Uninstall Python wheel and local dependencies This task uninstalls the built python wheel and its local dependencies from the project venv. | Property | Value/description | | -------- | -------------------------------------------------- | | builder | {py:class}`nmk_python.build.Uninstaller` | | if | {ref}`${pythonSrcFiles}` are found | The builder is called with the following parameters mapping: | Name | Value | | ---------- | -------------------------------------------------------------------------------------------------------------------------------- | | name | **{ref}`${pythonPackage}`** | | local_deps | **{ref}`${pythonLocalDepsPatterns}`**

_Added in version 1.8.0_ |