From 9668f26a26815f747f9606684d576c51631b5f08 Mon Sep 17 00:00:00 2001 From: Kate Case Date: Wed, 29 Mar 2023 18:18:57 -0400 Subject: [PATCH] Update pre-commit config (#245) * Update pre-commit config --- .pre-commit-config.yaml | 34 ++++++---------------- changelogs/fragments/pre-commit.yaml | 3 ++ galaxy.yml | 6 ++-- plugins/filter/consolidate.py | 1 - plugins/filter/from_xml.py | 1 - plugins/filter/keep_keys.py | 1 - plugins/filter/remove_keys.py | 1 - plugins/filter/replace_keys.py | 1 - plugins/filter/usable_range.py | 1 - plugins/plugin_utils/base/ipaddr_utils.py | 1 - plugins/plugin_utils/base/validate.py | 1 - plugins/plugin_utils/index_of.py | 1 - tests/unit/compat/builtins.py | 35 ----------------------- tests/unit/compat/mock.py | 1 - 14 files changed, 16 insertions(+), 72 deletions(-) create mode 100644 changelogs/fragments/pre-commit.yaml delete mode 100644 tests/unit/compat/builtins.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a156b20..a7b82f8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,11 @@ --- repos: + - repo: https://github.com/ansible-network/collection_prep + rev: 1.1.0 + hooks: + - id: autoversion + - id: update-docs + - repo: https://github.com/pre-commit/pre-commit-hooks rev: v4.4.0 hooks: @@ -7,7 +13,6 @@ repos: - id: debug-statements - id: end-of-file-fixer - id: no-commit-to-branch - args: [--branch, main] - id: trailing-whitespace - repo: https://github.com/asottile/add-trailing-comma @@ -16,26 +21,9 @@ repos: - id: add-trailing-comma - repo: https://github.com/pre-commit/mirrors-prettier - rev: "v3.0.0-alpha.4" + rev: "v3.0.0-alpha.6" hooks: - id: prettier - # Original hook implementation is flaky due to *several* bugs described - # in https://github.com/prettier/prettier/issues/12364 - # a) CI=1 needed to avoid incomplete output - # b) two executions are needed because --list-different works correctly - # only when run with --check as with --write the output will also - # include other entries and logging level cannot be used to keep only - # modified files listed (any file is listed using the log level, regardless if - # is modified or not). - # c) We avoid letting pre-commit pass each filename in order to avoid - # running multiple instances in parallel. This also ensures that running - # prettier from the command line behaves identically with the pre-commit - # one. No real performance downsides. - # d) exit with the return code from list-different (0=none, 1=some) - # rather than the write (0=successfully rewrote files). pre-commit.ci - entry: env CI=1 bash -c "prettier --list-different . || ec=$? && prettier --loglevel=error --write . && exit $ec" - pass_filenames: false - args: [] additional_dependencies: - prettier - prettier-plugin-toml @@ -45,13 +33,9 @@ repos: hooks: - id: isort name: Sort import statements using isort + args: ["--filter-files"] - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.3.0 hooks: - id: black - - - repo: https://github.com/ansible-network/collection_prep - rev: 1.0.1 - hooks: - - id: update-docs diff --git a/changelogs/fragments/pre-commit.yaml b/changelogs/fragments/pre-commit.yaml new file mode 100644 index 0000000..7bed354 --- /dev/null +++ b/changelogs/fragments/pre-commit.yaml @@ -0,0 +1,3 @@ +--- +trivial: + - Update pre-commit config to add autoversion hook diff --git a/galaxy.yml b/galaxy.yml index 7e608c6..3810cea 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -4,11 +4,13 @@ authors: license_file: LICENSE name: utils namespace: ansible -description: Ansible Collection with utilities to ease the management, manipulation, and validation of data within a playbook +description: + Ansible Collection with utilities to ease the management, manipulation, + and validation of data within a playbook readme: README.md repository: https://github.com/ansible-collections/ansible.utils issues: https://github.com/ansible-collections/ansible.utils/issues tags: [linux, networking, security, cloud, utilities, data, validation, utils] # NOTE(pabelanger): We create an empty version key to keep ansible-galaxy # happy. We dynamically inject version info based on git information. -version: null +version: 2.9.1-dev diff --git a/plugins/filter/consolidate.py b/plugins/filter/consolidate.py index 0f677c9..b07226e 100644 --- a/plugins/filter/consolidate.py +++ b/plugins/filter/consolidate.py @@ -1480,6 +1480,5 @@ class FilterModule(object): """Consolidate""" def filters(self): - """A mapping of filter names to functions""" return {"consolidate": _consolidate} diff --git a/plugins/filter/from_xml.py b/plugins/filter/from_xml.py index b6407d2..ce39439 100644 --- a/plugins/filter/from_xml.py +++ b/plugins/filter/from_xml.py @@ -143,6 +143,5 @@ class FilterModule(object): """from_xml""" def filters(self): - """a mapping of filter names to functions""" return {"from_xml": _from_xml} diff --git a/plugins/filter/keep_keys.py b/plugins/filter/keep_keys.py index 4331575..fc85a0d 100644 --- a/plugins/filter/keep_keys.py +++ b/plugins/filter/keep_keys.py @@ -325,6 +325,5 @@ class FilterModule(object): """keep_keys""" def filters(self): - """a mapping of filter names to functions""" return {"keep_keys": _keep_keys} diff --git a/plugins/filter/remove_keys.py b/plugins/filter/remove_keys.py index 5370799..f08db14 100644 --- a/plugins/filter/remove_keys.py +++ b/plugins/filter/remove_keys.py @@ -342,6 +342,5 @@ class FilterModule(object): """remove_keys""" def filters(self): - """a mapping of filter names to functions""" return {"remove_keys": _remove_keys} diff --git a/plugins/filter/replace_keys.py b/plugins/filter/replace_keys.py index b1a6f33..7037563 100644 --- a/plugins/filter/replace_keys.py +++ b/plugins/filter/replace_keys.py @@ -319,6 +319,5 @@ class FilterModule(object): """replace_keys""" def filters(self): - """a mapping of filter names to functions""" return {"replace_keys": _replace_keys} diff --git a/plugins/filter/usable_range.py b/plugins/filter/usable_range.py index ca69da7..46f7823 100644 --- a/plugins/filter/usable_range.py +++ b/plugins/filter/usable_range.py @@ -181,6 +181,5 @@ class FilterModule(object): """usable_range""" def filters(self): - """a mapping of filter names to functions""" return {"usable_range": _usable_range} diff --git a/plugins/plugin_utils/base/ipaddr_utils.py b/plugins/plugin_utils/base/ipaddr_utils.py index 23cf0a6..ddbe3bb 100644 --- a/plugins/plugin_utils/base/ipaddr_utils.py +++ b/plugins/plugin_utils/base/ipaddr_utils.py @@ -468,7 +468,6 @@ def ipaddr(value, query="", version=False, alias="ipaddr"): # Check if value is a number and convert it to an IP address elif str(value).isdigit(): - # We don't know what IP version to assume, so let's check IPv4 first, # then IPv6 try: diff --git a/plugins/plugin_utils/base/validate.py b/plugins/plugin_utils/base/validate.py index 8e26238..1dff866 100644 --- a/plugins/plugin_utils/base/validate.py +++ b/plugins/plugin_utils/base/validate.py @@ -75,7 +75,6 @@ class ValidateBase(object): return None for option_name, option_value in iteritems(options): - option_var_name_list = option_value.get("vars", []) option_env_name_list = option_value.get("env", []) diff --git a/plugins/plugin_utils/index_of.py b/plugins/plugin_utils/index_of.py index 96a90df..45181cc 100644 --- a/plugins/plugin_utils/index_of.py +++ b/plugins/plugin_utils/index_of.py @@ -159,7 +159,6 @@ def index_of( res.append(idx) elif isinstance(key, (string_types, integer_types, bool)): - if not all(isinstance(entry, dict) for entry in data): all_tipes = [type(_to_well_known_type(entry)).__name__ for entry in data] msg = ( diff --git a/tests/unit/compat/builtins.py b/tests/unit/compat/builtins.py deleted file mode 100644 index 49822ae..0000000 --- a/tests/unit/compat/builtins.py +++ /dev/null @@ -1,35 +0,0 @@ -# (c) 2014, Toshio Kuratomi -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Make coding more python3-ish -from __future__ import absolute_import, division, print_function - - -__metaclass__ = type - -# -# Compat for python2.7 -# - -# One unittest needs to import builtins via __import__() so we need to have -# the string that represents it -try: - import __builtin__ # pyright: ignore[reportMissingImports] # noqa F401 -except ImportError: - BUILTINS = "builtins" -else: - BUILTINS = "__builtin__" diff --git a/tests/unit/compat/mock.py b/tests/unit/compat/mock.py index 2c67fdd..3a3e082 100644 --- a/tests/unit/compat/mock.py +++ b/tests/unit/compat/mock.py @@ -104,7 +104,6 @@ if sys.version_info >= (3,) and sys.version_info < (3, 4, 4): global file_spec if file_spec is None: - file_spec = list(set(dir(_io.TextIOWrapper)).union(set(dir(_io.BytesIO)))) if mock is None: