diff --git a/ansibledoctor/doc_generator.py b/ansibledoctor/doc_generator.py index 8a0d263..243f8ef 100644 --- a/ansibledoctor/doc_generator.py +++ b/ansibledoctor/doc_generator.py @@ -47,16 +47,16 @@ class Generator: for file in glob.iglob(template_dir + "/**/*." + self.extension, recursive=True): relative_file = file[len(template_dir) + 1:] if ntpath.basename(file)[:1] != "_": - self.logger.debug("Found template file: " + relative_file) + self.logger.debug(f"Found template file: {relative_file}") self.template_files.append(relative_file) else: - self.logger.debug("Ignoring template file: " + relative_file) + self.logger.debug(f"Ignoring template file: {relative_file}") def _create_dir(self, directory): if not self.config.config["dry_run"] and not os.path.isdir(directory): try: os.makedirs(directory, exist_ok=True) - self.logger.info("Creating dir: " + directory) + self.logger.info(f"Creating dir: {directory}") except FileExistsError as e: self.log.sysexit_with_message(str(e)) @@ -84,14 +84,14 @@ class Generator: if len(files_to_overwite) > 0 and self.config.config.get("force_overwrite") is False: if not self.config.config["dry_run"]: - self.logger.warn("This files will be overwritten:") + self.logger.warning("This files will be overwritten:") print(*files_to_overwite, sep="\n") try: if not FileUtils.query_yes_no("Do you want to continue?"): self.log.sysexit_with_message("Aborted...") except ansibledoctor.exception.InputError as e: - self.logger.debug(str(e)) + self.logger.debug(str(e)) # noqa self.log.sysexit_with_message("Aborted...") for file in self.template_files: @@ -101,7 +101,7 @@ class Generator: ) source_file = self.config.get_template() + "/" + file - self.logger.debug("Writing doc output to: " + doc_file + " from: " + source_file) + self.logger.debug(f"Writing doc output to: {doc_file} from: {source_file}") # make sure the directory exists self._create_dir(os.path.dirname(doc_file)) @@ -124,9 +124,9 @@ class Generator: with open(doc_file, "wb") as outfile: outfile.write(header_content.encode("utf-8")) outfile.write(data.encode("utf-8")) - self.logger.info("Writing to: " + doc_file) + self.logger.info(f"Writing to: {doc_file}") else: - self.logger.info("Writing to: " + doc_file) + self.logger.info(f"Writing to: {doc_file}") except ( jinja2.exceptions.UndefinedError, jinja2.exceptions.TemplateSyntaxError ) as e: @@ -167,5 +167,5 @@ class Generator: return normalized def render(self): - self.logger.info("Using output dir: " + self.config.config.get("output_dir")) + self.logger.info(f"Using output dir: {self.config.config.get('output_dir')}") self._write_doc() diff --git a/ansibledoctor/doc_parser.py b/ansibledoctor/doc_parser.py index 34c09b8..a11ddc0 100644 --- a/ansibledoctor/doc_parser.py +++ b/ansibledoctor/doc_parser.py @@ -128,7 +128,7 @@ class Parser: """Generate the documentation data object.""" tags = defaultdict(dict) for annotation in self.config.get_annotations_names(automatic=True): - self.logger.info("Finding annotations for: @" + annotation) + self.logger.info(f"Finding annotations for: @{annotation}") self._annotation_objs[annotation] = Annotation( name=annotation, files_registry=self._files_registry ) diff --git a/ansibledoctor/file_registry.py b/ansibledoctor/file_registry.py index d46d66b..e6588e3 100644 --- a/ansibledoctor/file_registry.py +++ b/ansibledoctor/file_registry.py @@ -40,7 +40,7 @@ class Registry: excludes = self.config.config.get("exclude_files") excludespec = pathspec.PathSpec.from_lines("gitwildmatch", excludes) - self.log.debug("Scan for files: " + role_dir) + self.log.debug(f"Scan for files: {role_dir}") for extension in extensions: pattern = os.path.join(role_dir, "**/*." + extension) diff --git a/ansibledoctor/utils.py b/ansibledoctor/utils.py index 75d0002..8909bc5 100644 --- a/ansibledoctor/utils.py +++ b/ansibledoctor/utils.py @@ -92,11 +92,11 @@ class MultilineJsonFormatter(jsonlogger.JsonFormatter): class Log: """Handle logging.""" - def __init__(self, level=logging.WARN, name="ansibledoctor", json=False): + def __init__(self, level=logging.WARNING, name="ansibledoctor", json=False): self.logger = logging.getLogger(name) self.logger.setLevel(level) self.logger.addHandler(self._get_error_handler(json=json)) - self.logger.addHandler(self._get_warn_handler(json=json)) + self.logger.addHandler(self._get_warning_handler(json=json)) self.logger.addHandler(self._get_info_handler(json=json)) self.logger.addHandler(self._get_critical_handler(json=json)) self.logger.addHandler(self._get_debug_handler(json=json)) @@ -121,13 +121,13 @@ class Log: return handler - def _get_warn_handler(self, json=False): + def _get_warning_handler(self, json=False): handler = logging.StreamHandler(sys.stdout) - handler.setLevel(logging.WARN) - handler.addFilter(LogFilter(logging.WARN)) + handler.setLevel(logging.WARNING) + handler.addFilter(LogFilter(logging.WARNING)) handler.setFormatter( MultilineFormatter( - self.warn( + self.warning( CONSOLE_FORMAT.format( colorama.Fore.YELLOW, colorama.Style.BRIGHT, colorama.Style.RESET_ALL ) @@ -212,8 +212,8 @@ class Log: """Format error messages and return string.""" return msg - def warn(self, msg): - """Format warn messages and return string.""" + def warning(self, msg): + """Format warning messages and return string.""" return msg def info(self, msg): diff --git a/poetry.lock b/poetry.lock index 8222955..922f479 100644 --- a/poetry.lock +++ b/poetry.lock @@ -38,10 +38,10 @@ optional = false python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [package.extras] -dev = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "furo", "sphinx", "sphinx-notfound-page", "pre-commit", "cloudpickle"] -docs = ["furo", "sphinx", "zope.interface", "sphinx-notfound-page"] -tests = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "zope.interface", "cloudpickle"] -tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>=4.3.0)", "six", "mypy", "pytest-mypy-plugins", "cloudpickle"] +tests_no_zope = ["cloudpickle", "pytest-mypy-plugins", "mypy", "six", "pytest (>=4.3.0)", "pympler", "hypothesis", "coverage[toml] (>=5.0.2)"] +tests = ["cloudpickle", "zope.interface", "pytest-mypy-plugins", "mypy", "six", "pytest (>=4.3.0)", "pympler", "hypothesis", "coverage[toml] (>=5.0.2)"] +docs = ["sphinx-notfound-page", "zope.interface", "sphinx", "furo"] +dev = ["cloudpickle", "pre-commit", "sphinx-notfound-page", "sphinx", "furo", "zope.interface", "pytest-mypy-plugins", "mypy", "six", "pytest (>=4.3.0)", "pympler", "hypothesis", "coverage[toml] (>=5.0.2)"] [[package]] name = "bandit" @@ -58,9 +58,9 @@ PyYAML = ">=5.3.1" stevedore = ">=1.20.0" [package.extras] -test = ["coverage (>=4.5.4)", "fixtures (>=3.0.0)", "flake8 (>=4.0.0)", "stestr (>=2.5.0)", "testscenarios (>=0.5.0)", "testtools (>=2.3.0)", "toml", "beautifulsoup4 (>=4.8.0)", "pylint (==1.9.4)"] -toml = ["toml"] yaml = ["pyyaml"] +toml = ["toml"] +test = ["pylint (==1.9.4)", "beautifulsoup4 (>=4.8.0)", "toml", "testtools (>=2.3.0)", "testscenarios (>=0.5.0)", "stestr (>=2.5.0)", "flake8 (>=4.0.0)", "fixtures (>=3.0.0)", "coverage (>=4.5.4)"] [[package]] name = "colorama" @@ -160,7 +160,7 @@ pydocstyle = ">=2.1" [[package]] name = "flake8-eradicate" -version = "1.2.1" +version = "1.3.0" description = "Flake8 plugin to find commented out code" category = "dev" optional = false @@ -169,7 +169,7 @@ python-versions = ">=3.6,<4.0" [package.dependencies] attrs = "*" eradicate = ">=2.0,<3.0" -flake8 = ">=3.5,<5" +flake8 = ">=3.5,<6" [[package]] name = "flake8-isort" @@ -188,12 +188,16 @@ test = ["pytest-cov"] [[package]] name = "flake8-logging-format" -version = "0.6.0" -description = "Flake8 extension to validate (lack of) logging format strings" +version = "0.7.5" +description = "" category = "dev" optional = false python-versions = "*" +[package.extras] +lint = ["flake8"] +test = ["pytest", "pytest-cov", "pyhamcrest"] + [[package]] name = "flake8-pep3101" version = "1.3.0" @@ -266,8 +270,8 @@ typing-extensions = {version = ">=3.6.4", markers = "python_version < \"3.8\""} zipp = ">=0.5" [package.extras] -docs = ["sphinx", "jaraco.packaging (>=8.2)", "rst.linker (>=1.9)"] -testing = ["pytest (>=4.6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "packaging", "pep517", "pyfakefs", "flufl.flake8", "pytest-black (>=0.3.7)", "pytest-mypy", "importlib-resources (>=1.3)"] +testing = ["importlib-resources (>=1.3)", "pytest-mypy", "pytest-black (>=0.3.7)", "flufl.flake8", "pyfakefs", "pep517", "packaging", "pytest-enabler (>=1.0.1)", "pytest-cov", "pytest-flake8", "pytest-checkdocs (>=2.4)", "pytest (>=4.6)"] +docs = ["rst.linker (>=1.9)", "jaraco.packaging (>=8.2)", "sphinx"] [[package]] name = "importlib-resources" @@ -301,10 +305,10 @@ optional = false python-versions = ">=3.6.1,<4.0" [package.extras] -pipfile_deprecated_finder = ["pipreqs", "requirementslib"] -requirements_deprecated_finder = ["pipreqs", "pip-api"] -colors = ["colorama (>=0.4.3,<0.5.0)"] plugins = ["setuptools"] +colors = ["colorama (>=0.4.3,<0.5.0)"] +requirements_deprecated_finder = ["pip-api", "pipreqs"] +pipfile_deprecated_finder = ["requirementslib", "pipreqs"] [[package]] name = "jinja2" @@ -413,11 +417,11 @@ python-versions = ">=2.6" [[package]] name = "pep8-naming" -version = "0.13.1" +version = "0.13.2" description = "Check PEP-8 naming conventions, plugin for flake8" category = "dev" optional = false -python-versions = "*" +python-versions = ">=3.7" [package.dependencies] flake8 = ">=3.9.1" @@ -492,7 +496,7 @@ optional = false python-versions = ">=3.6.8" [package.extras] -diagrams = ["railroad-diagrams", "jinja2"] +diagrams = ["jinja2", "railroad-diagrams"] [[package]] name = "pyrsistent" @@ -522,7 +526,7 @@ py = ">=1.8.2" tomli = ">=1.0.0" [package.extras] -testing = ["argcomplete", "hypothesis (>=3.56)", "mock", "nose", "pygments (>=2.7.2)", "requests", "xmlschema"] +testing = ["xmlschema", "requests", "pygments (>=2.7.2)", "nose", "mock", "hypothesis (>=3.56)", "argcomplete"] [[package]] name = "pytest-cov" @@ -680,13 +684,13 @@ optional = false python-versions = ">=3.7" [package.extras] -docs = ["sphinx", "jaraco.packaging (>=9)", "rst.linker (>=1.9)"] -testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-cov", "pytest-enabler (>=1.0.1)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy (>=0.9.1)"] +testing = ["pytest-mypy (>=0.9.1)", "pytest-black (>=0.3.7)", "func-timeout", "jaraco.itertools", "pytest-enabler (>=1.0.1)", "pytest-cov", "pytest-flake8", "pytest-checkdocs (>=2.4)", "pytest (>=6)"] +docs = ["rst.linker (>=1.9)", "jaraco.packaging (>=9)", "sphinx"] [metadata] lock-version = "1.1" python-versions = "^3.7.0" -content-hash = "2ff99781f90c7c90baafb3a3f946e1d84397bfbb12ad291145d9220f992ccbd2" +content-hash = "5908a53fcf4cfd8c5e7b826b00370668d2013aac7708dc60c8e13b4604fb3d75" [metadata.files] anyconfig = [ @@ -789,15 +793,15 @@ flake8-docstrings = [ {file = "flake8_docstrings-1.6.0-py2.py3-none-any.whl", hash = "sha256:99cac583d6c7e32dd28bbfbef120a7c0d1b6dde4adb5a9fd441c4227a6534bde"}, ] flake8-eradicate = [ - {file = "flake8-eradicate-1.2.1.tar.gz", hash = "sha256:e486f8ab7e2dba3667223688e9239158fbf4ecaa88125e2283bcda81171412b7"}, - {file = "flake8_eradicate-1.2.1-py3-none-any.whl", hash = "sha256:00d77faefb64cef18b3c1b48a004c3a2ad663aa3cf85650f422437d25ece6441"}, + {file = "flake8-eradicate-1.3.0.tar.gz", hash = "sha256:e4c98f00d17dc8653e3388cac2624cd81e9735de2fd4a8dcf99029633ebd7a63"}, + {file = "flake8_eradicate-1.3.0-py3-none-any.whl", hash = "sha256:85a71e0c5f4e07f7c6c5fec520483561fd6bd295417d622855bdeade99242e3d"}, ] flake8-isort = [ {file = "flake8-isort-4.2.0.tar.gz", hash = "sha256:26571500cd54976bbc0cf1006ffbcd1a68dd102f816b7a1051b219616ba9fee0"}, {file = "flake8_isort-4.2.0-py3-none-any.whl", hash = "sha256:5b87630fb3719bf4c1833fd11e0d9534f43efdeba524863e15d8f14a7ef6adbf"}, ] flake8-logging-format = [ - {file = "flake8-logging-format-0.6.0.tar.gz", hash = "sha256:ca5f2b7fc31c3474a0aa77d227e022890f641a025f0ba664418797d979a779f8"}, + {file = "flake8-logging-format-0.7.5.tar.gz", hash = "sha256:54f7e349c934ce5c594f251885bc2240e99f6b48752a672a8fc7e3d1388352bb"}, ] flake8-pep3101 = [ {file = "flake8-pep3101-1.3.0.tar.gz", hash = "sha256:86e3eb4e42de8326dcd98ebdeaf9a3c6854203a48f34aeb3e7e8ed948107f512"}, @@ -908,8 +912,8 @@ pbr = [ {file = "pbr-5.9.0.tar.gz", hash = "sha256:e8dca2f4b43560edef58813969f52a56cef023146cbb8931626db80e6c1c4308"}, ] pep8-naming = [ - {file = "pep8-naming-0.13.1.tar.gz", hash = "sha256:3af77cdaa9c7965f7c85a56cd579354553c9bbd3fdf3078a776f12db54dd6944"}, - {file = "pep8_naming-0.13.1-py3-none-any.whl", hash = "sha256:f7867c1a464fe769be4f972ef7b79d6df1d9aff1b1f04ecf738d471963d3ab9c"}, + {file = "pep8-naming-0.13.2.tar.gz", hash = "sha256:93eef62f525fd12a6f8c98f4dcc17fa70baae2f37fa1f73bec00e3e44392fa48"}, + {file = "pep8_naming-0.13.2-py3-none-any.whl", hash = "sha256:59e29e55c478db69cffbe14ab24b5bd2cd615c0413edf790d47d3fb7ba9a4e23"}, ] pkgutil-resolve-name = [ {file = "pkgutil_resolve_name-1.3.10-py3-none-any.whl", hash = "sha256:ca27cc078d25c5ad71a9de0a7a330146c4e014c2462d9af19c6b828280649c5e"}, diff --git a/pyproject.toml b/pyproject.toml index 3d5236c..f28d96a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,13 +53,13 @@ flake8 = "4.0.1" flake8-blind-except = "0.2.1" flake8-builtins = "1.5.3" flake8-docstrings = "1.6.0" -flake8-eradicate = "1.2.1" +flake8-eradicate = "1.3.0" flake8-isort = "4.2.0" -flake8-logging-format = "0.6.0" +flake8-logging-format = "0.7.5" flake8-pep3101 = "1.3.0" flake8-polyfill = "1.0.2" flake8-quotes = "3.3.1" -pep8-naming = "0.13.1" +pep8-naming = "0.13.2" pydocstyle = "6.1.1" pytest = "7.1.2" pytest-cov = "3.0.0" diff --git a/setup.cfg b/setup.cfg index 439b889..595f550 100644 --- a/setup.cfg +++ b/setup.cfg @@ -6,8 +6,10 @@ # D105: Missing docstring in magic method # D107: Missing docstring in __init__ # D202: No blank lines allowed after function docstring -# W503:Line break occurred before a binary operator -ignore = D102, D103, D105, D107, D202, W503 +# G001: Logging statements should not use string.format() for their first argument +# G004: Logging statements should not use f"..." for their first argument +# W503: Line break occurred before a binary operator +ignore = D102, D103, D105, D107, D202, G001, G004, W503 max-line-length = 99 inline-quotes = double exclude = .git, __pycache__, build, dist, test, *.pyc, *.egg-info, .cache, .eggs, env*