From 45440dfdb908da60b673091da228d735ea126904 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Mon, 14 Apr 2025 19:24:47 +0900 Subject: [PATCH] Use pre-commit to run format check ... and integrate pyupgrade to clean up syntaxes to support Python 2. Change-Id: Idbafe08951a27b8888aad4b800f404cfff86d475 --- .pre-commit-config.yaml | 30 ++++++++++++++++++++++++++++++ doc/source/conf.py | 4 ++-- test-requirements.txt | 2 -- tox.ini | 6 +++++- 4 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 .pre-commit-config.yaml mode change 100755 => 100644 doc/source/conf.py diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..31d9d64 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v5.0.0 + hooks: + - id: trailing-whitespace + # Replaces or checks mixed line ending + - id: mixed-line-ending + args: ['--fix', 'lf'] + exclude: '.*\.(svg)$' + # Forbid files which have a UTF-8 byte-order marker + - id: check-byte-order-marker + # Checks that non-binary executables have a proper shebang + - id: check-executables-have-shebangs + # Check for files that contain merge conflict strings. + - id: check-merge-conflict + # Check for debugger imports and py37+ breakpoint() + # calls in python source + - id: debug-statements + - id: check-yaml + files: .*\.(yaml|yml)$ + - repo: https://opendev.org/openstack/hacking + rev: 7.0.0 + hooks: + - id: hacking + additional_dependencies: [] + - repo: https://github.com/asottile/pyupgrade + rev: v3.18.0 + hooks: + - id: pyupgrade + args: [--py3-only] diff --git a/doc/source/conf.py b/doc/source/conf.py old mode 100755 new mode 100644 index cd33d8b..9e13f66 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -22,7 +22,7 @@ sys.path.insert(0, os.path.abspath('../..')) extensions = [ 'sphinx.ext.autodoc', 'openstackdocstheme', - #'sphinx.ext.intersphinx', + # 'sphinx.ext.intersphinx', ] # autodoc generation is a bit aggressive and a nuisance when doing heavy @@ -77,4 +77,4 @@ latex_documents = [ ] # Example configuration for intersphinx: refer to the Python standard library. -#intersphinx_mapping = {'http://docs.python.org/': None} +# intersphinx_mapping = {'http://docs.python.org/': None} diff --git a/test-requirements.txt b/test-requirements.txt index 16da9c8..1a2b9da 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,5 +1,3 @@ -hacking>=7.0.0,<7.1.0 # Apache-2.0 - coverage>=4.0,!=4.4 # Apache-2.0 python-subunit>=0.0.18 # Apache-2.0/BSD oslotest>=1.10.0 # Apache-2.0 diff --git a/tox.ini b/tox.ini index fe483b0..b4b1cf5 100644 --- a/tox.ini +++ b/tox.ini @@ -18,7 +18,11 @@ deps = -c{env:UPPER_CONSTRAINTS_FILE:https://releases.openstack.org/constraints/ commands = stestr run {posargs} [testenv:pep8] -commands = flake8 {posargs} +skip_install = true +deps = + pre-commit +commands = + pre-commit run -a [testenv:venv] commands = {posargs}