diff --git a/.pylintrc b/.pylintrc index 570941b..d03f0c2 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,6 +1,13 @@ [BASIC] good-names=log +[MESSAGES CONTROL] +# Handled by black +disable=bad-continuation + +[FORMAT] +good-names=f,k,v + [VARIABLES] # List of additional names supposed to be defined in builtins. Remember that # you should avoid to define new builtins when possible. diff --git a/salt_tower/loader.py b/salt_tower/loader.py index b1c6eaf..c8185e3 100644 --- a/salt_tower/loader.py +++ b/salt_tower/loader.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=missing-docstring import os diff --git a/salt_tower/pillar/tower.py b/salt_tower/pillar/tower.py index ed4fde8..b5801df 100644 --- a/salt_tower/pillar/tower.py +++ b/salt_tower/pillar/tower.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=missing-docstring ''' ''' @@ -6,24 +7,24 @@ import collections import copy +import errno import logging import os import string -import errno from glob import glob +import salt.ext.six as six import salt.loader import salt.minion import salt.template -import salt.ext.six as six try: from salt.utils.data import traverse_dict_and_list except ImportError: from salt.utils import traverse_dict_and_list -log = logging.getLogger(__name__) +LOGGER = logging.getLogger(__name__) if hasattr(salt.loader, 'matchers'): @@ -47,7 +48,7 @@ def ext_pillar(minion_id, pillar, *args, **_kwargs): for top in list(args): if not os.path.exists(top): - log.warning("Tower top file `%s' does not exists", top) + LOGGER.warning("Tower top file `%s' does not exists", top) continue tower.run(top) @@ -72,7 +73,7 @@ def __init__(self, minion_id, env, pillar): if 'yamlet' in self._renderers: self._default_renderers = 'jinja|yamlet' else: - log.warning('Yamlet renderer not available. Tower functionality will be limited.') + LOGGER.warning('Yamlet renderer not available. Tower functionality will be limited.') self._default_renderers = 'jinja|yaml' def get(self, key, default=None, **kwargs): @@ -105,7 +106,7 @@ def format(self, obj, *args, **kwargs): return obj def run(self, top): - log.debug("Process tower top file `%s'", top) + LOGGER.debug("Process tower top file `%s'", top) base = os.path.dirname(top) @@ -129,7 +130,7 @@ def _match_minion(self, tgt): 'id': self.minion_id }) except Exception as err: - log.exception(err) + LOGGER.exception(err) return False @@ -137,15 +138,15 @@ def _load_top(self, top): data = self._compile(top) if not isinstance(data, collections.Mapping): - log.critical("Tower top must be a dict, but is %s.", type(data)) + LOGGER.critical("Tower top must be a dict, but is %s.", type(data)) return [] if self.env not in data: - log.warning("Tower top `%s' does not include env %s, skipping.", top, self.env) + LOGGER.warning("Tower top `%s' does not include env %s, skipping.", top, self.env) return [] if not isinstance(data[self.env], list): - log.critical("Tower top `%s' env %s must be a list, but is %s.", + LOGGER.critical("Tower top `%s' env %s must be a list, but is %s.", top, self.env, type(data[self.env])) return [] @@ -172,12 +173,12 @@ def lookup(self, item, base=None, cwd=None): match = [i for i in match if os.path.isfile(i)] if match: - log.debug('Found glob match: %s', match) + LOGGER.debug('Found glob match: %s', match) return sorted(match) for match in [path, '{}.sls'.format(path), '{}/init.sls'.format(path)]: if os.path.isfile(match): - log.debug('Found file match: %s', match) + LOGGER.debug('Found file match: %s', match) return [match] return [] @@ -200,11 +201,11 @@ def _load_file(self, file, base=None): loaded before the loaded data is merged into the current pillar. """ if file in self._included: - log.warning('Skipping already included file: %s', file) + LOGGER.warning('Skipping already included file: %s', file) return if not os.path.isfile(file): - log.warning('Skipping non-existing file: %s', file) + LOGGER.warning('Skipping non-existing file: %s', file) return self._included.append(file) @@ -212,7 +213,7 @@ def _load_file(self, file, base=None): data = self._compile(file, context={'basedir': base}) if not isinstance(data, collections.Mapping): - log.warning('Loading %s did not return dict, but %s', file, type(data)) + LOGGER.warning('Loading %s did not return dict, but %s', file, type(data)) return if 'include' in data: diff --git a/salt_tower/renderers/text.py b/salt_tower/renderers/text.py index 94a6cc3..fd192d8 100644 --- a/salt_tower/renderers/text.py +++ b/salt_tower/renderers/text.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=missing-docstring ''' A text renderer for processing and loading text blobs. @@ -43,14 +44,9 @@ {'path': {'to': {'blob': 'A short text message'}}} ''' -import logging - from salt.ext.six import string_types -log = logging.getLogger(__name__) - - def render(blob, _saltenv, _sls, argline=None, key=None, **_kwargs): if not isinstance(blob, string_types): blob = blob.read() @@ -58,7 +54,6 @@ def render(blob, _saltenv, _sls, argline=None, key=None, **_kwargs): if blob.startswith('#!'): blob = blob[(blob.find('\n') + 1):] - # pylint: disable=invalid-name if argline is not None: for arg in argline.split(None): if '=' in arg: diff --git a/salt_tower/renderers/yamlet.py b/salt_tower/renderers/yamlet.py index bfa6d7e..cb3e151 100644 --- a/salt_tower/renderers/yamlet.py +++ b/salt_tower/renderers/yamlet.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# pylint: disable=missing-docstring ''' Extended YAML renderer for salt. @@ -13,7 +14,6 @@ from __future__ import absolute_import import io -import logging import os import six @@ -32,8 +32,6 @@ except ImportError: from salt.utils import fopen -log = logging.getLogger(__name__) - class YamletLoader(SaltYamlSafeLoader): # pylint: disable=too-many-ancestors def __init__(self, stream, renderers, context=None, tmplpath=None, **_kwargs): diff --git a/test/conftest.py b/test/conftest.py index fdbcc9b..a3b0fcc 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -1,28 +1,29 @@ # -*- coding: utf-8 -*- +# pylint: disable=missing-docstring +# pylint: disable=redefined-outer-name from __future__ import absolute_import import os -import pytest import shutil -import six import tempfile import textwrap -root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) - +import pytest +import six import salt.config import salt.loader try: from salt.utils.files import fopen -except: +except ImportError: from salt.utils import fopen +ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) -__opts__ = salt.config.client_config(os.path.join(root, 'test/master.yml')) -__opts__['cachedir'] = os.path.join(root, 'tmp/cache') +__opts__ = salt.config.client_config(os.path.join(ROOT, 'test/master.yml')) +__opts__['cachedir'] = os.path.join(ROOT, 'tmp/cache') __grains__ = salt.loader.grains(__opts__) __opts__['grains'] = __grains__ @@ -82,7 +83,6 @@ def ext_pillar(self, **kwargs): if isinstance(args, dict): return __pillars__['tower'](minion_id, pillar, **args) - elif isinstance(args, list): + if isinstance(args, list): return __pillars__['tower'](minion_id, pillar, *args) - else: - return __pillars__['tower'](minion_id, pillar, args) + return __pillars__['tower'](minion_id, pillar, args) diff --git a/test/pillar/test_tower_tower.py b/test/pillar/test_tower_tower.py index 714fa26..7121fe5 100644 --- a/test/pillar/test_tower_tower.py +++ b/test/pillar/test_tower_tower.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +# pylint: disable=missing-docstring +# pylint: disable=redefined-outer-name import inspect import pytest diff --git a/test/renderers/test_text.py b/test/renderers/test_text.py index b4f5aca..8ff1536 100644 --- a/test/renderers/test_text.py +++ b/test/renderers/test_text.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- +# pylint: disable=missing-docstring +# pylint: disable=redefined-outer-name -import pytest import textwrap +import pytest + @pytest.fixture def result(env): diff --git a/test/renderers/test_yamlet.py b/test/renderers/test_yamlet.py index 9d5835b..ec1269a 100644 --- a/test/renderers/test_yamlet.py +++ b/test/renderers/test_yamlet.py @@ -1,9 +1,12 @@ # -*- coding: utf-8 -*- +# pylint: disable=missing-docstring +# pylint: disable=redefined-outer-name import os -import pytest import textwrap +import pytest + from salt.utils.odict import OrderedDict diff --git a/test/salt.py b/test/salt.py deleted file mode 100644 index 0002d2f..0000000 --- a/test/salt.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- - -from __future__ import absolute_import - -import os -import pytest - -import salt.config -import salt.loader - - -__root__ = os.path.abspath(os.path.join(os.path.dirname(__file__), '..')) - -__opts__ = salt.config.master_config('/dev/null') -__opts__['extension_modules'] = __root__ -__opts__['log_level'] = 'debug' -__opts__['id'] = 'test_master' -__opts__['cachedir'] = 'tmp/cache' - -__grains__ = salt.loader.grains(__opts__) -__opts__['grains'] = __grains__ - -__utils__ = salt.loader.utils(__opts__) -__salt__ = salt.loader.minion_mods(__opts__, utils=__utils__) -__renderers__ = salt.loader.render(__opts__, __salt__)