From 50da395abcef6d783b74520e0c617099f30ee627 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Prchl=C3=ADk?= Date: Sat, 27 May 2023 13:15:52 +0200 Subject: [PATCH] Add pyright as a pre-commit check Another pair of eyes, pyright is a type check plus a bit more, and will inspect the code from slightyl different point of view. As a result, it will report issues mypy cannot spot, or cannot spot *yet* because the set of implemented checks is simply different. The slow, gradual approach is the key here, like the one we know from mypy introduction, and slowly files and packages will get covered. --- .pre-commit-config.yaml | 19 ++++++++++++ pyproject.toml | 69 +++++++++++++++++++++++++++++++++++++++++ setup.py | 8 +++++ tmt/result.py | 1 + 4 files changed, 97 insertions(+) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 371d0a3b4c..462739d8ac 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -32,6 +32,25 @@ repos: pass_filenames: false args: [--config-file=pyproject.toml] + - repo: https://github.com/RobertCraigie/pyright-python + rev: v1.1.310 + hooks: + - id: pyright + # TODO: find out how to amend pyright, pre-commit and package requirements. + # Apparently, there is no easy way to avoid some level of duplication of + # information when the package is *not* installed, which is the case of tmt + # & pre-commit in our setup. + additional_dependencies: + - 'fmf>=1.2.1' + - 'click' + - 'requests' + - 'urllib3' + - 'ruamel.yaml' + - 'jinja2' + - 'setuptools' + - 'typing-extensions>=3.7.4.3' + - importlib_metadata + - repo: https://github.com/python-jsonschema/check-jsonschema rev: "0.23.1" hooks: diff --git a/pyproject.toml b/pyproject.toml index f281c15e13..617bfe99cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -32,6 +32,75 @@ module = [ ] ignore_missing_imports = true +[tool.pyright] +include = [ +# "bin/tmt", + "tmt/__init__.py", + "tmt/result.py", +# "tmt/__main__.py", +# "tmt/queue.py", +# "tmt/base.py", +# "tmt/log.py", +# "tmt/lint.py", +# "tmt/identifier.py", +# "tmt/utils.py", +# "tmt/options.py", +# "tmt/libraries/__init__.py", +# "tmt/libraries/beakerlib.py", +# "tmt/libraries/file.py", +# "tmt/convert.py", +# "tmt/cli.py", +# "tmt/plugins/__init__.py", +# "tmt/steps/__init__.py", +# "tmt/steps/discover/__init__.py", +# "tmt/steps/discover/shell.py", +# "tmt/steps/discover/fmf.py", +# "tmt/steps/finish/__init__.py", +# "tmt/steps/finish/ansible.py", +# "tmt/steps/finish/shell.py", +# "tmt/steps/prepare/__init__.py", +# "tmt/steps/prepare/ansible.py", +# "tmt/steps/prepare/shell.py", +# "tmt/steps/prepare/install.py", +# "tmt/steps/provision/__init__.py", +# "tmt/steps/provision/connect.py", +# "tmt/steps/provision/artemis.py", +# "tmt/steps/provision/local.py", +# "tmt/steps/provision/mrack.py", +# "tmt/steps/provision/testcloud.py", +# "tmt/steps/provision/podman.py", +# "tmt/steps/execute/__init__.py", +# "tmt/steps/execute/upgrade.py", +# "tmt/steps/execute/internal.py", +# "tmt/steps/report/__init__.py", +# "tmt/steps/report/html.py", +# "tmt/steps/report/display.py", +# "tmt/steps/report/junit.py", +# "tmt/steps/report/reportportal.py", +# "tmt/steps/report/polarion.py", +# "tmt/export/__init__.py", +# "tmt/export/template.py", +# "tmt/export/_dict.py", +# "tmt/export/nitrate.py", +# "tmt/export/_json.py", +# "tmt/export/yaml.py", +# "tmt/export/rst.py", +# "tmt/export/polarion.py", +# "tmt/templates.py", + "setup.py" +] +ignore = [ + "docs/**", + "examples/**", + "tests/**", +# "tmt/**" +] + +pythonVersion = "3.6" +pythonPlatform = "Linux" + +typeCheckingMode = "strict" + [tool.autopep8] max_line_length = 99 in-place = true diff --git a/setup.py b/setup.py index 4c9e12615c..c90d641893 100755 --- a/setup.py +++ b/setup.py @@ -45,6 +45,14 @@ __desc__ = 'Test Management Tool' __scripts__ = ['bin/tmt'] +# TODO: find out how to amend pyright, pre-commit and package requirements. +# Apparently, there is no easy way to avoid some level of duplication of +# information when the package is *not* installed, which is the case of tmt +# & pre-commit in our setup. +# +# For now, requirements are also listed in `.pre-commit-config.yaml` which +# is just ugly... + # Prepare install requires and extra requires install_requires = [ 'fmf>=1.2.1', diff --git a/tmt/result.py b/tmt/result.py index 77a5691d29..f2d82e82e7 100644 --- a/tmt/result.py +++ b/tmt/result.py @@ -5,6 +5,7 @@ import click import fmf +import fmf.utils import tmt.utils from tmt.utils import Path, field