1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-05 03:19:43 +00:00

pytype flake8 mypy

This commit is contained in:
deadc0de6
2024-01-17 15:28:00 +01:00
parent de05935ef1
commit 3639e92317
8 changed files with 56 additions and 21 deletions

1
.gitignore vendored
View File

@@ -7,6 +7,7 @@ build/
tags
env
venv
.pytype
# coverage stuff
.coverage

2
CONTRIBUTING.md vendored
View File

@@ -209,7 +209,7 @@ for a match with the ignore patterns.
Dotdrop is tested with the use of the [tests.sh](/tests.sh) script.
* Test for PEP8 compliance with `pylint`, `pycodestyle` and `pyflakes` (see [check-syntax.sh](/scripts/test-syntax.sh))
* Test for PEP8 compliance with linters (see [check-syntax.sh](/scripts/test-syntax.sh))
* Test the documentation and links (see [check-doc.sh](/scripts/check-doc.sh))
* Run the unittests in [tests directory](/tests) with pytest (see [check-unittest.sh](/scripts/check-unittests.sh))
* Run the blackbox bash script tests in [tests-ng directory](/tests-ng) (see [check-tests-ng.sh](/scripts/check-tests-ng.sh))

View File

@@ -8,6 +8,7 @@ in dotdrop
import subprocess
import os
from typing import List
# local imports
from dotdrop.dictparser import DictParser
@@ -17,7 +18,7 @@ from dotdrop.exceptions import UndefinedException
class Cmd(DictParser):
"""A command to execute"""
args = []
args: List[str] = []
eq_ignore = ('log',)
descr = 'command'
@@ -32,13 +33,13 @@ class Cmd(DictParser):
self.silent = key.startswith('_')
def _get_action(self, templater, debug):
action = None
action = ''
try:
action = templater.generate_string(self.action)
except UndefinedException as exc:
err = f'undefined variable for {self.descr}: \"{exc}\"'
self.log.warn(err)
return False
return action
if debug:
self.log.dbg(f'{self.descr}:')
self.log.dbg(f' - raw \"{self.action}\"')

View File

@@ -29,7 +29,7 @@ from ruamel.yaml import YAML as yaml
try:
import tomllib
except ImportError:
import tomli as tomllib
import tomli as tomllib # type: ignore
import tomli_w
# local imports

View File

@@ -27,9 +27,9 @@ class DictParser:
except AttributeError:
pass
newv = cls._adjust_yaml_keys(tmp)
if not key:
return cls(**newv)
return cls(key=key, **newv)
if key:
newv[key] = key
return cls(**newv)
@classmethod
def parse_dict(cls, items):

View File

@@ -473,7 +473,11 @@ def get_module_from_path(path):
importlib.machinery.SOURCE_SUFFIXES.append('')
# import module
spec = importlib.util.spec_from_file_location(module_name, path)
if not spec:
return None
mod = importlib.util.module_from_spec(spec)
if not mod:
return None
spec.loader.exec_module(mod)
return mod
@@ -507,8 +511,7 @@ def dependencies_met():
name = 'docopt'
err = f'missing python module \"{name}\"'
try:
from docopt import docopt
assert docopt
from docopt import docopt # noqa # pylint: disable=W0611
except ImportError as exc:
raise UnmetDependency(err) from exc
@@ -525,8 +528,7 @@ def dependencies_met():
name = 'ruamel.yaml'
err = f'missing python module \"{name}\"'
try:
from ruamel.yaml import YAML
assert YAML
from ruamel.yaml import YAML # noqa # pylint: disable=W0611
except ImportError as exc:
raise UnmetDependency(err) from exc

View File

@@ -28,12 +28,26 @@ fi
echo "=> pycodestyle version:"
pycodestyle --version
if ! which pyflakes >/dev/null 2>&1; then
echo "Install pyflakes"
if ! which flake8 >/dev/null 2>&1; then
echo "Install flake8"
exit 1
fi
echo "=> pyflakes version:"
pyflakes --version
echo "=> flake8 version:"
flake8 --version
if ! which pytype >/dev/null 2>&1; then
echo "Install pytype"
exit 1
fi
echo "=> pytype version:"
pytype --version
if ! which mypy >/dev/null 2>&1; then
echo "Install mypy"
exit 1
fi
echo "=> mypy version:"
mypy --version
# checking for TODO/FIXME
echo "--------------------------------------"
@@ -62,10 +76,10 @@ echo "checking dotdrop with pycodestyle"
pycodestyle --ignore=W503,W504 dotdrop/
pycodestyle scripts/
# pyflakes tests
# flake8 tests
echo "------------------------------"
echo "checking dotdrop with pyflakes"
pyflakes dotdrop/
echo "checking dotdrop with flake8"
flake8 dotdrop/
# pylint
echo "----------------------------"
@@ -90,6 +104,20 @@ pylint \
--disable=R0904 \
dotdrop/
# pytype
echo "----------------------------"
echo "checking dotdrop with pytype"
pytype dotdrop/
# mypy
echo "----------------------------"
echo "checking dotdrop with mypy"
# --strict
mypy \
--ignore-missing-imports \
--allow-redefinition \
dotdrop/
# check shell scripts
# SC2002: Useless cat
# SC2126: Consider using grep -c instead of grep|wc -l

View File

@@ -2,8 +2,11 @@ pycodestyle; python_version > '3.5'
pytest; python_version > '3.5'
coverage; python_version > '3.5'
coveralls; python_version > '3.5'
pyflakes; python_version > '3.5'
flake8; python_version > '3.5'
pylint; python_version > '3.5'
halo; python_version > '3.5'
distro; python_version > '3.5'
urllib3; python_version > '3.5'
urllib3; python_version > '3.5'
pytype; python_version > '3.0'
mypy; python_version > '3.0'
types-requests; python_version > '3.0'