Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

github: add mypy workflow #3356

Closed
wants to merge 35 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/mypy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "mypy check"
on: [pull_request]

jobs:

static-type-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v3
with:
python-version: '3.x'
- run: pip install mypy
- name: Get Python changed files
id: changed-py-files
uses: tj-actions/changed-files@v23
with:
files: |
*.py
**/*.py

- name: Run if any of the listed files above is changed
if: steps.changed-py-files.outputs.any_changed == 'true'
run: mypy ${{ steps.changed-py-files.outputs.all_changed_files}} --install-types --non-interactive

- name: Set warning if previous step failed
if: failure()
# run: echo "::warning::The previous step failed but we are continuing."
run: echo "::warning file=app.py,line=10,col=5::Code formatting issues detected"
25 changes: 25 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x

- name: Fetch repository
run: git fetch origin

- uses: pre-commit/action@v3.0.1
with:
# extra_args: --from-ref origin/HEAD --to-ref HEAD
# extra_args: --from-ref main --to-ref HEAD
# extra_args: --from-ref main
extra_args: --from-ref origin/main --to-ref HEAD
1 change: 1 addition & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[mypy]
ignore_missing_imports = True
allow_untyped_globals = True
93 changes: 93 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# HOWTO: https://pre-commit.com/#usage
# pip3 install pre-commit
# pre-commit install -t pre-commit -t pre-push

repos:
# - repo: https://github.com/psf/black
# rev: 23.11.0
# hooks:
# - id: black
# - repo: https://github.com/pre-commit/mirrors-prettier
# rev: v3.1.0
# hooks:
# - id: prettier
# exclude: tests_recording/test_data/
# - repo: https://github.com/pre-commit/pre-commit-hooks
# rev: v4.5.0
# hooks:
# - id: check-added-large-files
# exclude: tests_recording/test_data/test_api/
# - id: check-ast
# - id: check-builtin-literals
# - id: check-docstring-first
# - id: check-executables-have-shebangs
# exclude: (files/bash-completion/packit|tests/data/)
# - id: check-merge-conflict
# - id: check-symlinks
# - id: check-yaml
# - id: detect-private-key
# exclude: tests/integration/conftest.py
# - id: end-of-file-fixer
# exclude: ^(tests/data/patches|tests/.+\.patch)
# - id: mixed-line-ending
# - id: trailing-whitespace
# exclude: ^(tests/data/patches|tests/.+\.patch)
# - repo: https://github.com/astral-sh/ruff-pre-commit
# rev: v0.1.6
# hooks:
# - id: ruff
# args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.7.1
hooks:
- id: mypy
args:
[
--no-strict-optional,
--ignore-missing-imports,
--explicit-package-bases,
]
additional_dependencies:
[
types-six,
types-requests,
types-setuptools,
types-mock,
types-decorator,
types-pytz,
# types-click,
# types-pkg_resources,
# types-requests,
# types-tabulate,
# types-Deprecated,
# types-PyYAML,
# types-cachetools,
]
# - repo: https://github.com/teemtee/tmt.git
# rev: 1.29.0
# hooks:
# - id: tmt-lint
# - repo: https://github.com/packit/pre-commit-hooks
# rev: v1.2.0
# hooks:
# - id: validate-config # passes when packit not installed (e.g. in CI)
# - id: check-rebase
# args:
# - https://github.com/packit/packit.git
# stages: [manual, push]
# - repo: https://github.com/python-jsonschema/check-jsonschema
# rev: 0.28.0
# hooks:
# - id: check-github-workflows
# args: ["--verbose"]
# - repo: https://github.com/Lucas-C/pre-commit-hooks
# rev: v1.5.5
# hooks:
# - id: insert-license
# files: \.py$
# exclude: (tests/data/|tests_recording/test_data/)
# args:
# - --license-filepath
# - LICENSE_HEADER.txt
# - --comment-style
# - "#"
9 changes: 2 additions & 7 deletions cli/copr_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
try:
import argcomplete
except ImportError:
argcomplete = None
pass

import copr.exceptions as copr_exceptions
from copr.v3 import (
Expand Down Expand Up @@ -62,11 +62,6 @@
None: "default",
}

try:
input = raw_input
except NameError:
pass


class FrontendOutdatedCliException(Exception):
"""
Expand Down Expand Up @@ -1900,7 +1895,7 @@ def __call__(self, parser, args, argument, option_string=None):
# package monitoring
cli_monitor_parser(subparsers)

if argcomplete:
if "argcomplete" in sys.modules:
argcomplete.autocomplete(parser)
return parser

Expand Down
4 changes: 2 additions & 2 deletions frontend/coprs_frontend/coprs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from coprs.redis_session import RedisSessionInterface
from coprs.request import get_request_class

app = flask.Flask(__name__)
app : flask.Flask = flask.Flask(__name__)
if "COPRS_ENVIRON_PRODUCTION" in os.environ:
app.config.from_object("coprs.config.ProductionConfig")
elif "COPRS_ENVIRON_UNITTEST" in os.environ:
Expand All @@ -42,7 +42,7 @@
session = Session(app)

# Set `future=True` to ensure compatibility between SQLAlchemy 1.x and 2.0
db = SQLAlchemy(app, engine_options={"future": True})
db : SQLAlchemy = SQLAlchemy(app, engine_options={"future": True})

@contextmanager
def db_session_scope():
Expand Down
29 changes: 0 additions & 29 deletions keygen/run/dev_run.py

This file was deleted.

2 changes: 1 addition & 1 deletion python/copr/v3/auth/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse
from urlparse import urlparse # type: ignore [no-redef]


class BaseAuth(object):
Expand Down
2 changes: 1 addition & 1 deletion python/copr/v3/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

try:
import urlparse
from urllib import urlencode
from urllib import urlencode # type: ignore [attr-defined]
except ImportError:
import urllib.parse as urlparse
from urllib.parse import urlencode
Expand Down
4 changes: 0 additions & 4 deletions rpmbuild/copr_rpmbuild/providers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
from .distgit import DistGitProvider


__all__ = [RubyGemsProvider, PyPIProvider,
UrlProvider, ScmProvider]


def factory(source_type):
try:
return {
Expand Down
2 changes: 1 addition & 1 deletion rpmbuild/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
builtins = 'builtins'
except ImportError:
# Python 2 version depends on mock
import mock
import mock # type: ignore [no-redef]
builtins = '__builtin__'

class TestProvider(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion rpmbuild/tests/test_distgit.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from unittest import mock
except ImportError:
# Python 2 version depends on mock
import mock
import mock # type: ignore [no-redef]

from tests import TestCase

Expand Down
2 changes: 1 addition & 1 deletion rpmbuild/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from unittest import mock
except ImportError:
# Python 2 version depends on mock
import mock
import mock # type: ignore [no-redef]


class TestTmpCleanup(TestCase):
Expand Down
2 changes: 1 addition & 1 deletion rpmbuild/tests/test_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
builtins = 'builtins'
except ImportError:
# Python 2 version depends on mock
import mock
import mock # type: ignore [no-redef]
builtins = '__builtin__'

@pytest.yield_fixture
Expand Down
2 changes: 1 addition & 1 deletion rpmbuild/tests/test_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
builtins = 'builtins'
except ImportError:
# Python 2 version depends on mock
import mock
import mock # type: ignore [no-redef]
builtins = '__builtin__'


Expand Down
2 changes: 1 addition & 1 deletion rpmbuild/tests/test_rubygems.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
builtins = 'builtins'
except ImportError:
# Python 2 version depends on mock
import mock
import mock # type: ignore [no-redef]
builtins = '__builtin__'


Expand Down
2 changes: 1 addition & 1 deletion rpmbuild/tests/test_scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
builtins = 'builtins'
except ImportError:
# Python 2 version depends on mock
import mock
import mock # type: ignore [no-redef]
builtins = '__builtin__'

RPKG_CONF_JINJA = """
Expand Down
2 changes: 1 addition & 1 deletion rpmbuild/tests/test_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def example_com_match(url, request):
builtins = 'builtins'
except ImportError:
# Python 2 version depends on mock
import mock
import mock # type: ignore [no-redef]
builtins = '__builtin__'


Expand Down
Loading