From 8f0712e89b7a82cd8e5a59504b8e4516c4cc3f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20Br=C3=BCckmann?= <64bit+git@posteo.de> Date: Fri, 12 Mar 2021 08:49:40 +0100 Subject: [PATCH] Add a mypy run to the pipeline --- .gitlab-ci.yml | 7 +++++++ fdroidserver/common.py | 8 ++++---- fdroidserver/scanner.py | 2 +- mypy.ini | 15 +++++++++++++++ 4 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 mypy.ini diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ebd4cff1..48a82833 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -188,6 +188,13 @@ lint_format_safety_bandit_checks: - pybabel compile --domain=fdroidserver --directory locale 2>&1 | (grep -F "error:" && exit 1) || true - exit $EXITVALUE +lint_mypy: + image: python:3.9-buster + script: + - pip install mypy + - pip install -e .[test] + - mypy + fedora_latest: image: fedora:latest only: diff --git a/fdroidserver/common.py b/fdroidserver/common.py index 00d91c36..1eecbbdc 100644 --- a/fdroidserver/common.py +++ b/fdroidserver/common.py @@ -148,11 +148,11 @@ default_config = { 'repo_url': "https://MyFirstFDroidRepo.org/fdroid/repo", 'repo_name': "My First F-Droid Repo Demo", 'repo_icon': "icon.png", - 'repo_description': _("""This is a repository of apps to be used with F-Droid. Applications in this repository are either official binaries built by the original application developers, or are binaries built from source by the admin of f-droid.org using the tools on https://gitlab.com/fdroid."""), + 'repo_description': _("""This is a repository of apps to be used with F-Droid. Applications in this repository are either official binaries built by the original application developers, or are binaries built from source by the admin of f-droid.org using the tools on https://gitlab.com/fdroid."""), # type: ignore 'archive_name': 'My First F-Droid Archive Demo', - 'archive_description': _('These are the apps that have been archived from the main repo.'), + 'archive_description': _('These are the apps that have been archived from the main repo.'), # type: ignore 'archive_older': 0, - 'lint_licenses': fdroidserver.lint.APPROVED_LICENSES, + 'lint_licenses': fdroidserver.lint.APPROVED_LICENSES, # type: ignore 'git_mirror_size_limit': 10000000000, } @@ -2389,7 +2389,7 @@ def use_androguard(): return False -use_androguard.show_path = True +use_androguard.show_path = True # type: ignore def _get_androguard_APK(apkfile): diff --git a/fdroidserver/scanner.py b/fdroidserver/scanner.py index 436abf1e..24438340 100644 --- a/fdroidserver/scanner.py +++ b/fdroidserver/scanner.py @@ -34,7 +34,7 @@ from .exception import BuildException, VCSException config = None options = None -DEFAULT_JSON_PER_BUILD = {'errors': [], 'warnings': [], 'infos': []} +DEFAULT_JSON_PER_BUILD = {'errors': [], 'warnings': [], 'infos': []} # type: ignore json_per_build = DEFAULT_JSON_PER_BUILD MAVEN_URL_REGEX = re.compile(r"""\smaven\s*{.*?(?:setUrl|url)\s*=?\s*(?:uri)?\(?\s*["']?([^\s"']+)["']?[^}]*}""", diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 00000000..0e5df9cf --- /dev/null +++ b/mypy.ini @@ -0,0 +1,15 @@ +[mypy] +files = fdroidserver + +# this is de-facto the linter setting for this file +warn_unused_configs = True + +# TODO: we should either upgrade the used packages to a version which includes type hints OR install/write stub packages for these libraries. +# Further details here: https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-type-hints-for-third-party-library +ignore_missing_imports = True + +# ignore the [no-redef] errors, as they collide with the bandit "# nosec" exclusion (common.py) +# unfortunately both tools expect their ignore flag as a comment in the same line +# [misc] is ignored for the "incompatible import" +# [arg-type] is ignored because when there are missing envs, everything will crash, not just the types +disable_error_code = no-redef, misc, arg-type \ No newline at end of file