diff --git a/.flake8 b/.flake8 index 6e3a62c..83ef6c0 100644 --- a/.flake8 +++ b/.flake8 @@ -1,8 +1,18 @@ [flake8] -# Temp disable Docstring checks D101, D102, D103, D107 -ignore = E501, W503, F401, N813, D101, D102, D103, D107 -max-line-length = 110 +ignore = D102, D103, D107, D202, W503 +max-line-length = 99 inline-quotes = double -exclude = .git,.tox,__pycache__,build,dist,tests,*.pyc,*.egg-info,.cache,.eggs +exclude = + .git + .tox + __pycache__ + build + dist + tests + *.pyc + *.egg-info + .cache + .eggs + env* application-import-names = ansiblelater format = ${cyan}%(path)s:%(row)d:%(col)d${reset}: ${red_bold}%(code)s${reset} %(text)s diff --git a/ansiblelater/command/candidates.py b/ansiblelater/command/candidates.py index ed139a4..8ece4d1 100644 --- a/ansiblelater/command/candidates.py +++ b/ansiblelater/command/candidates.py @@ -189,6 +189,7 @@ class Candidate(object): class RoleFile(Candidate): + """Object classified as Ansible role file.""" def __init__(self, filename, settings={}, standards=[]): super(RoleFile, self).__init__(filename, settings, standards) @@ -203,10 +204,13 @@ class RoleFile(Candidate): class Playbook(Candidate): + """Object classified as Ansible playbook.""" + pass class Task(RoleFile): + """Object classified as Ansible task file.""" def __init__(self, filename, settings={}, standards=[]): super(Task, self).__init__(filename, settings, standards) @@ -214,6 +218,7 @@ class Task(RoleFile): class Handler(RoleFile): + """Object classified as Ansible handler file.""" def __init__(self, filename, settings={}, standards=[]): super(Handler, self).__init__(filename, settings, standards) @@ -221,10 +226,13 @@ class Handler(RoleFile): class Vars(Candidate): + """Object classified as Ansible vars file.""" + pass class Unversioned(Candidate): + """Object classified as unversioned file.""" def __init__(self, filename, settings={}, standards=[]): super(Unversioned, self).__init__(filename, settings, standards) @@ -232,50 +240,74 @@ class Unversioned(Candidate): class InventoryVars(Unversioned): + """Object classified as Ansible inventory vars.""" + pass class HostVars(InventoryVars): + """Object classified as Ansible host vars.""" + pass class GroupVars(InventoryVars): + """Object classified as Ansible group vars.""" + pass class RoleVars(RoleFile): + """Object classified as Ansible role vars.""" + pass class Meta(RoleFile): + """Object classified as Ansible meta file.""" + pass class Inventory(Unversioned): + """Object classified as Ansible inventory file.""" + pass class Code(Unversioned): + """Object classified as code file.""" + pass class Template(RoleFile): + """Object classified as Ansible template file.""" + pass class Doc(Unversioned): + """Object classified as documentation file.""" + pass class Makefile(Unversioned): + """Object classified as makefile.""" + pass class File(RoleFile): + """Object classified as generic file.""" + pass class Rolesfile(Unversioned): + """Object classified as Ansible roles file.""" + pass @@ -310,6 +342,7 @@ class Error(object): class Result(object): + """Generic result object.""" def __init__(self, candidate, errors=None): self.candidate = candidate @@ -335,8 +368,10 @@ def classify(filename, settings={}, standards=[]): return HostVars(filename, settings, standards) if parentdir in ["meta"]: return Meta(filename, settings, standards) - if parentdir in ["library", "lookup_plugins", "callback_plugins", "filter_plugins" - ] or filename.endswith(".py"): + if ( + parentdir in ["library", "lookup_plugins", "callback_plugins", "filter_plugins"] + or filename.endswith(".py") + ): return Code(filename, settings, standards) if "inventory" == basename or "hosts" == basename or parentdir in ["inventories"]: return Inventory(filename, settings, standards) diff --git a/ansiblelater/rules/ansiblefiles.py b/ansiblelater/rules/ansiblefiles.py index ce5a91e..569c61d 100644 --- a/ansiblelater/rules/ansiblefiles.py +++ b/ansiblelater/rules/ansiblefiles.py @@ -33,8 +33,10 @@ def check_braces_spaces(candidate, settings): [leading, trailing] = count_spaces(line) sum_spaces = leading + trailing - if ((sum_spaces < conf["min-spaces-inside"] * 2) - or (sum_spaces > conf["min-spaces-inside"] * 2)): + if ( + sum_spaces < conf["min-spaces-inside"] * 2 + or sum_spaces > conf["min-spaces-inside"] * 2 + ): errors.append(Error(i, description)) return Result(candidate.path, errors) diff --git a/ansiblelater/utils/yamlhelper.py b/ansiblelater/utils/yamlhelper.py index 35e002c..f64c3eb 100644 --- a/ansiblelater/utils/yamlhelper.py +++ b/ansiblelater/utils/yamlhelper.py @@ -23,7 +23,6 @@ import codecs import glob import imp -import inspect import os import ansible.parsing.mod_args @@ -453,11 +452,9 @@ def action_tasks(yaml, file): block_rescue_always = ("block", "rescue", "always") tasks[:] = [task for task in tasks if all(k not in task for k in block_rescue_always)] - return [ - task for task in tasks - if set(["include", "include_tasks", "import_playbook", "import_tasks"] - ).isdisjoint(task.keys()) - ] + allowed = ["include", "include_tasks", "import_playbook", "import_tasks"] + + return [task for task in tasks if set(allowed).isdisjoint(task.keys())] def task_to_str(task):