From 40f7c167d808b0594293f6caf22581014e1fbbd9 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Tue, 23 Jan 2024 11:58:55 +0000 Subject: [PATCH] Add pre-commit Change-Id: Ifdee3615f26b370cda531ae0cc736b8db67ed204 Signed-off-by: Stephen Finucane --- .pre-commit-config.yaml | 30 ++++++++++++++++++++++++++++++ setup.py | 4 +--- test-requirements.txt | 1 - tests/check_osc_commands.py | 9 +++++---- tests/test_openstackclient.py | 1 - tox.ini | 8 ++++++-- 6 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..f939028 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +--- +default_language_version: + # force all unspecified python hooks to run python3 + python: python3 +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: mixed-line-ending + args: ['--fix', 'lf'] + exclude: '.*\.(svg)$' + - id: check-byte-order-marker + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: debug-statements + - id: check-yaml + files: .*\.(yaml|yml)$ + args: ['--unsafe'] + - repo: https://github.com/psf/black + rev: 23.12.1 + hooks: + - id: black + args: ['-S', '-l', '79'] + - repo: https://opendev.org/openstack/hacking + rev: 6.1.0 + hooks: + - id: hacking + additional_dependencies: [] + exclude: '^(doc|releasenotes|tools)/.*$' diff --git a/setup.py b/setup.py index f63cc23..83c92e2 100644 --- a/setup.py +++ b/setup.py @@ -16,6 +16,4 @@ # THIS FILE IS MANAGED BY THE GLOBAL REQUIREMENTS REPO - DO NOT EDIT import setuptools -setuptools.setup( - setup_requires=['pbr>=2.0.0'], - pbr=True) +setuptools.setup(setup_requires=['pbr>=2.0.0'], pbr=True) diff --git a/test-requirements.txt b/test-requirements.txt index 9e8f4d9..5b4651c 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,3 +1,2 @@ -hacking>=3.0,<3.1.0 # Apache-2.0 oslotest>=3.2.0 # Apache-2.0 stestr>=2.0.0 # Apache-2.0 diff --git a/tests/check_osc_commands.py b/tests/check_osc_commands.py index 6ae296c..f2ad8e6 100755 --- a/tests/check_osc_commands.py +++ b/tests/check_osc_commands.py @@ -71,7 +71,6 @@ def find_duplicates(): # Iterate over all entry points for ep in pkg_resources.iter_entry_points(module): - # Check for a colon, since valid entrypoints will have one, for # example: quota_show = openstackclient.common.quota:ShowQuota # and plugin entrypoints will not, for @@ -166,9 +165,11 @@ def _is_valid_command(ep_name, ep_module_name, valid_cmds): module_parts = ep_module_name.split(".") for valid_module_name in valid_cmds[ep_name]: valid_module_parts = valid_module_name.split(".") - if (module_parts[0] == valid_module_parts[0] and - module_parts[1] == valid_module_parts[1] and - module_parts[3] == valid_module_parts[3]): + if ( + module_parts[0] == valid_module_parts[0] + and module_parts[1] == valid_module_parts[1] + and module_parts[3] == valid_module_parts[3] + ): return True return False diff --git a/tests/test_openstackclient.py b/tests/test_openstackclient.py index 4796d0e..ea34328 100644 --- a/tests/test_openstackclient.py +++ b/tests/test_openstackclient.py @@ -14,6 +14,5 @@ from oslotest import base class TestOpenstackClient(base.BaseTestCase): - def test_something(self): pass diff --git a/tox.ini b/tox.ini index 8875217..4986a95 100644 --- a/tox.ini +++ b/tox.ini @@ -10,8 +10,12 @@ commands = stestr run --slowest {posargs} [testenv:pep8] +description = + Run style checks. +deps = + pre-commit commands = - flake8 + pre-commit run --all-files --show-diff-on-failure [testenv:venv] commands = {posargs} @@ -26,4 +30,4 @@ commands = [flake8] show-source = True exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,__init__.py -ignore = E123,H405,W504 +ignore = E123,H405,W503