From 2654458c6edf548203a5bb89203c55aca18d46c9 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Thu, 29 Apr 2021 15:27:22 +0200 Subject: [PATCH] linting --- dotdrop/cfg_aggregator.py | 6 ++++-- dotdrop/comparator.py | 15 +++++++++++---- dotdrop/dictparser.py | 1 + dotdrop/dotfile.py | 22 +++++++++++----------- dotdrop/exceptions.py | 2 -- dotdrop/importer.py | 4 +--- dotdrop/linktypes.py | 18 ++++++++++++++++-- dotdrop/profile.py | 16 ++++++++-------- dotdrop/settings.py | 34 ++++++++++++++++++---------------- 9 files changed, 70 insertions(+), 48 deletions(-) diff --git a/dotdrop/cfg_aggregator.py b/dotdrop/cfg_aggregator.py index 017a256..799f5ef 100644 --- a/dotdrop/cfg_aggregator.py +++ b/dotdrop/cfg_aggregator.py @@ -312,7 +312,8 @@ class CfgAggregator: return self._get_long_key(path, existing_keys) return self._get_short_key(path, existing_keys) - def _norm_key_elem(self, elem): + @classmethod + def _norm_key_elem(cls, elem): """normalize path element for sanity""" elem = elem.lstrip('.') elem = elem.replace(' ', '-') @@ -369,7 +370,8 @@ class CfgAggregator: self._load() self.debug = olddebug - def _norm_path(self, path): + @classmethod + def _norm_path(cls, path): if not path: return path path = os.path.expanduser(path) diff --git a/dotdrop/comparator.py b/dotdrop/comparator.py index b4d937d..3fbf89f 100644 --- a/dotdrop/comparator.py +++ b/dotdrop/comparator.py @@ -15,6 +15,7 @@ from dotdrop.utils import must_ignore, uniq_list, diff, \ class Comparator: + """compare dotfiles helper""" def __init__(self, diff_cmd='', debug=False, ignore_missing_in_dotdrop=False): @@ -27,9 +28,11 @@ class Comparator: self.log = Logger(debug=self.debug) self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop - def compare(self, local_path, deployed_path, ignore=[]): + def compare(self, local_path, deployed_path, ignore=None): """diff local_path (dotdrop dotfile) and deployed_path (destination file)""" + if not ignore: + ignore = [] local_path = os.path.expanduser(local_path) deployed_path = os.path.expanduser(deployed_path) self.log.dbg('comparing {} and {}'.format( @@ -113,15 +116,19 @@ class Comparator: return '' if not os.path.isdir(deployed_path): return '\"{}\" is a file\n'.format(deployed_path) + + return self._compare_dirs(local_path, deployed_path, ignore) + + def _compare_dirs(self, local_path, deployed_path, ignore): + """compare directories""" self.log.dbg('compare {} and {}'.format(local_path, deployed_path)) ret = [] comp = filecmp.dircmp(local_path, deployed_path) # handle files only in deployed dir for i in comp.left_only: - if self.ignore_missing_in_dotdrop: - continue - if must_ignore([os.path.join(local_path, i)], + if self.ignore_missing_in_dotdrop or \ + must_ignore([os.path.join(local_path, i)], ignore, debug=self.debug): continue ret.append('=> \"{}\" does not exist on destination\n'.format(i)) diff --git a/dotdrop/dictparser.py b/dotdrop/dictparser.py index 3031164..49017b8 100644 --- a/dotdrop/dictparser.py +++ b/dotdrop/dictparser.py @@ -9,6 +9,7 @@ from dotdrop.logger import Logger class DictParser: + """a dict parser""" log = Logger() diff --git a/dotdrop/dotfile.py b/dotdrop/dotfile.py index 6de3397..65712e9 100644 --- a/dotdrop/dotfile.py +++ b/dotdrop/dotfile.py @@ -19,10 +19,10 @@ class Dotfile(DictParser): key_template = 'template' def __init__(self, key, dst, src, - actions=[], trans_r=None, trans_w=None, + actions=None, trans_r=None, trans_w=None, link=LinkTypes.NOLINK, noempty=False, - cmpignore=[], upignore=[], - instignore=[], template=True, chmod=None, + cmpignore=None, upignore=None, + instignore=None, template=True, chmod=None, ignore_missing_in_dotdrop=False): """ constructor @@ -40,7 +40,7 @@ class Dotfile(DictParser): @template: template this dotfile @chmod: file permission """ - self.actions = actions + self.actions = actions or [] self.dst = dst self.key = key self.link = LinkTypes.get(link) @@ -48,9 +48,9 @@ class Dotfile(DictParser): self.src = src self.trans_r = trans_r self.trans_w = trans_w - self.upignore = upignore - self.cmpignore = cmpignore - self.instignore = instignore + self.upignore = upignore or [] + self.cmpignore = cmpignore or [] + self.instignore = instignore or [] self.template = template self.chmod = chmod self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop @@ -135,14 +135,14 @@ class Dotfile(DictParser): out += '\n{}pre-action:'.format(indent) some = self.get_pre_actions() if some: - for a in some: - out += '\n{}- {}'.format(2 * indent, a) + for act in some: + out += '\n{}- {}'.format(2 * indent, act) out += '\n{}post-action:'.format(indent) some = self.get_post_actions() if some: - for a in some: - out += '\n{}- {}'.format(2 * indent, a) + for act in some: + out += '\n{}- {}'.format(2 * indent, act) out += '\n{}trans_r:'.format(indent) some = self.get_trans_r() diff --git a/dotdrop/exceptions.py b/dotdrop/exceptions.py index 9c2df22..faee4ca 100644 --- a/dotdrop/exceptions.py +++ b/dotdrop/exceptions.py @@ -8,9 +8,7 @@ diverse exceptions class YamlException(Exception): """exception in CfgYaml""" - pass class UndefinedException(Exception): """exception in templating""" - pass diff --git a/dotdrop/importer.py b/dotdrop/importer.py index 7b2edfa..91f114c 100644 --- a/dotdrop/importer.py +++ b/dotdrop/importer.py @@ -41,9 +41,7 @@ class Importer: self.safe = safe self.debug = debug self.keepdot = keepdot - if not ignore: - ignore = [] - self.ignore = ignore + self.ignore = ignore or [] self.umask = get_umask() self.log = Logger(debug=self.debug) diff --git a/dotdrop/linktypes.py b/dotdrop/linktypes.py index 68e2b3b..e3288ad 100644 --- a/dotdrop/linktypes.py +++ b/dotdrop/linktypes.py @@ -1,19 +1,33 @@ +""" +author: deadc0de6 (https://github.com/deadc0de6) +Copyright (c) 2020, deadc0de6 + +represents a type of link in dotdrop +""" + +# https://github.com/PyCQA/pylint/issues/2062 +# pylint: disable=E1101 + from enum import IntEnum class LinkTypes(IntEnum): + """a type of link""" NOLINK = 0 LINK = 1 LINK_CHILDREN = 2 @classmethod def get(cls, key, default=None): + """get the linktype""" try: return key if isinstance(key, cls) else cls[key.upper()] - except KeyError: + except KeyError as exc: if default: return default - raise ValueError('bad {} value: "{}"'.format(cls.__name__, key)) + err = 'bad {} value: "{}"'.format(cls.__name__, key) + raise ValueError(err) from exc def __str__(self): + """linktype to string""" return self.name.lower() diff --git a/dotdrop/profile.py b/dotdrop/profile.py index fd7bd3f..a117092 100644 --- a/dotdrop/profile.py +++ b/dotdrop/profile.py @@ -10,13 +10,14 @@ from dotdrop.action import Action class Profile(DictParser): + """dotdrop profile""" # profile keys key_include = 'include' key_import = 'import' - def __init__(self, key, actions=[], dotfiles=[], - variables=[], dynvariables=[]): + def __init__(self, key, actions=None, dotfiles=None, + variables=None, dynvariables=None): """ constructor @key: profile key @@ -26,10 +27,10 @@ class Profile(DictParser): @dynvariables: list of interpreted variable keys """ self.key = key - self.actions = actions - self.dotfiles = dotfiles - self.variables = variables - self.dynvariables = dynvariables + self.actions = actions or [] + self.dotfiles = dotfiles or [] + self.variables = variables or [] + self.dynvariables = dynvariables or [] def get_pre_actions(self): """return all 'pre' actions""" @@ -51,8 +52,7 @@ class Profile(DictParser): def __hash__(self): return (hash(self.key) ^ - hash(tuple(self.dotfiles)) ^ - hash(tuple(self.included_profiles))) + hash(tuple(self.dotfiles))) def __str__(self): msg = 'key:"{}"' diff --git a/dotdrop/settings.py b/dotdrop/settings.py index fa8467e..7827b9b 100644 --- a/dotdrop/settings.py +++ b/dotdrop/settings.py @@ -16,6 +16,7 @@ ENV_WORKDIR = 'DOTDROP_WORKDIR' class Settings(DictParser): + """Settings block in config""" # key in yaml file key_yaml = 'config' @@ -50,14 +51,15 @@ class Settings(DictParser): key_import_variables = 'import_variables' def __init__(self, backup=True, banner=True, - create=True, default_actions=[], dotpath='dotfiles', - ignoreempty=False, import_actions=[], import_configs=[], - import_variables=[], keepdot=False, + create=True, default_actions=None, dotpath='dotfiles', + ignoreempty=False, import_actions=None, import_configs=None, + import_variables=None, keepdot=False, link_dotfile_default=LinkTypes.NOLINK, link_on_import=LinkTypes.NOLINK, longkey=False, - upignore=[], cmpignore=[], instignore=[], impignore=[], - workdir='~/.config/dotdrop', showdiff=False, - minversion=None, func_file=[], filter_file=[], + upignore=None, cmpignore=None, instignore=None, + impignore=None, workdir='~/.config/dotdrop', + showdiff=False, minversion=None, + func_file=None, filter_file=None, diff_command='diff -r -u {0} {1}', template_dotfile_default=True, ignore_missing_in_dotdrop=False, @@ -65,27 +67,27 @@ class Settings(DictParser): self.backup = backup self.banner = banner self.create = create - self.default_actions = default_actions + self.default_actions = default_actions or [] self.dotpath = dotpath self.ignoreempty = ignoreempty - self.import_actions = import_actions - self.import_configs = import_configs - self.import_variables = import_variables + self.import_actions = import_actions or [] + self.import_configs = import_configs or [] + self.import_variables = import_variables or [] self.keepdot = keepdot self.longkey = longkey self.showdiff = showdiff - self.upignore = upignore - self.cmpignore = cmpignore - self.instignore = instignore - self.impignore = impignore + self.upignore = upignore or [] + self.cmpignore = cmpignore or [] + self.instignore = instignore or [] + self.impignore = impignore or [] self.workdir = workdir if ENV_WORKDIR in os.environ: self.workdir = os.environ[ENV_WORKDIR] self.link_dotfile_default = LinkTypes.get(link_dotfile_default) self.link_on_import = LinkTypes.get(link_on_import) self.minversion = minversion - self.func_file = func_file - self.filter_file = filter_file + self.func_file = func_file or [] + self.filter_file = filter_file or [] self.diff_command = diff_command self.template_dotfile_default = template_dotfile_default self.ignore_missing_in_dotdrop = ignore_missing_in_dotdrop