1
0
mirror of https://github.com/deadc0de6/dotdrop.git synced 2026-02-12 22:45:13 +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 tags
env env
venv venv
.pytype
# coverage stuff # coverage stuff
.coverage .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. 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)) * 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 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)) * 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 subprocess
import os import os
from typing import List
# local imports # local imports
from dotdrop.dictparser import DictParser from dotdrop.dictparser import DictParser
@@ -17,7 +18,7 @@ from dotdrop.exceptions import UndefinedException
class Cmd(DictParser): class Cmd(DictParser):
"""A command to execute""" """A command to execute"""
args = [] args: List[str] = []
eq_ignore = ('log',) eq_ignore = ('log',)
descr = 'command' descr = 'command'
@@ -32,13 +33,13 @@ class Cmd(DictParser):
self.silent = key.startswith('_') self.silent = key.startswith('_')
def _get_action(self, templater, debug): def _get_action(self, templater, debug):
action = None action = ''
try: try:
action = templater.generate_string(self.action) action = templater.generate_string(self.action)
except UndefinedException as exc: except UndefinedException as exc:
err = f'undefined variable for {self.descr}: \"{exc}\"' err = f'undefined variable for {self.descr}: \"{exc}\"'
self.log.warn(err) self.log.warn(err)
return False return action
if debug: if debug:
self.log.dbg(f'{self.descr}:') self.log.dbg(f'{self.descr}:')
self.log.dbg(f' - raw \"{self.action}\"') self.log.dbg(f' - raw \"{self.action}\"')

View File

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

View File

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

View File

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

View File

@@ -28,12 +28,26 @@ fi
echo "=> pycodestyle version:" echo "=> pycodestyle version:"
pycodestyle --version pycodestyle --version
if ! which pyflakes >/dev/null 2>&1; then if ! which flake8 >/dev/null 2>&1; then
echo "Install pyflakes" echo "Install flake8"
exit 1 exit 1
fi fi
echo "=> pyflakes version:" echo "=> flake8 version:"
pyflakes --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 # checking for TODO/FIXME
echo "--------------------------------------" echo "--------------------------------------"
@@ -62,10 +76,10 @@ echo "checking dotdrop with pycodestyle"
pycodestyle --ignore=W503,W504 dotdrop/ pycodestyle --ignore=W503,W504 dotdrop/
pycodestyle scripts/ pycodestyle scripts/
# pyflakes tests # flake8 tests
echo "------------------------------" echo "------------------------------"
echo "checking dotdrop with pyflakes" echo "checking dotdrop with flake8"
pyflakes dotdrop/ flake8 dotdrop/
# pylint # pylint
echo "----------------------------" echo "----------------------------"
@@ -90,6 +104,20 @@ pylint \
--disable=R0904 \ --disable=R0904 \
dotdrop/ 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 # check shell scripts
# SC2002: Useless cat # SC2002: Useless cat
# SC2126: Consider using grep -c instead of grep|wc -l # 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' pytest; python_version > '3.5'
coverage; python_version > '3.5' coverage; python_version > '3.5'
coveralls; python_version > '3.5' coveralls; python_version > '3.5'
pyflakes; python_version > '3.5' flake8; python_version > '3.5'
pylint; python_version > '3.5' pylint; python_version > '3.5'
halo; python_version > '3.5' halo; python_version > '3.5'
distro; 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'