From dcbabdad09c6724560fa87df8e16d723a563dbce Mon Sep 17 00:00:00 2001 From: Hugo Brito Date: Fri, 1 Mar 2024 17:38:15 -0300 Subject: [PATCH] WIP Create a zuul for black style Create a format check Test Plan TODO - SUCCESS on black zuul Closes-bug: ##### Change-Id: I5d7b537e83931304ffd5f67ce51e8ebb44f7e65b Signed-off-by: Hugo Brito --- .zuul.yaml | 14 +++++++++ distributedcloud-client/black_pre_run.yaml | 5 ++++ .../dcmanagerclient/shell.py | 3 +- .../dcmanagerclient/tests/base.py | 3 +- distributedcloud-client/tox.ini | 29 ++++++++++++++----- tox.ini | 6 ++++ 6 files changed, 51 insertions(+), 9 deletions(-) create mode 100644 distributedcloud-client/black_pre_run.yaml diff --git a/.zuul.yaml b/.zuul.yaml index 22860a7..8a705d5 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -10,12 +10,14 @@ - stx-distcloud-client-tox-pep8 - stx-distcloud-client-tox-py39 - stx-distcloud-client-tox-pylint + - stx-distcloud-client-tox-black gate: jobs: - openstack-tox-linters - stx-distcloud-client-tox-pep8 - stx-distcloud-client-tox-py39 - stx-distcloud-client-tox-pylint + - stx-distcloud-client-tox-black post: jobs: - stx-distcloud-client-upload-git-mirror @@ -50,6 +52,18 @@ tox_envlist: pep8 tox_extra_args: -c distributedcloud-client/tox.ini +- job: + name: stx-distcloud-client-tox-black + parent: tox + description: Run black for distcloud-client + nodeset: debian-bullseye + voting: false + vars: + python_version: 3.9 + tox_envlist: black_zuul + tox_extra_args: -c distributedcloud-client/tox.ini + pre-run: black_pre_run.yaml + - job: name: stx-distcloud-client-upload-git-mirror parent: upload-git-mirror diff --git a/distributedcloud-client/black_pre_run.yaml b/distributedcloud-client/black_pre_run.yaml new file mode 100644 index 0000000..f8108ad --- /dev/null +++ b/distributedcloud-client/black_pre_run.yaml @@ -0,0 +1,5 @@ +--- +- hosts: controller + tasks: + - name: create modified_files.txt + command: git diff HEAD^ --name-only -- '*.py' > modified_files.txt diff --git a/distributedcloud-client/dcmanagerclient/shell.py b/distributedcloud-client/dcmanagerclient/shell.py index ffe2299..b40d2c8 100644 --- a/distributedcloud-client/dcmanagerclient/shell.py +++ b/distributedcloud-client/dcmanagerclient/shell.py @@ -23,7 +23,8 @@ import logging import os import sys -from cliff import app, commandmanager +from cliff import app +from cliff import commandmanager from cliff import help as cliff_help from osc_lib.command import command diff --git a/distributedcloud-client/dcmanagerclient/tests/base.py b/distributedcloud-client/dcmanagerclient/tests/base.py index 8ac9a9a..6f74f97 100644 --- a/distributedcloud-client/dcmanagerclient/tests/base.py +++ b/distributedcloud-client/dcmanagerclient/tests/base.py @@ -263,7 +263,8 @@ FAKE_INSTALL_VALUES = { class FakeResponse: """Fake response for testing DC Manager Client.""" - def __init__(self, status_code, content=None): + def __init__(self, + status_code, content=None): self.status_code = status_code self.content = content self.headers = {} diff --git a/distributedcloud-client/tox.ini b/distributedcloud-client/tox.ini index 2747084..48cc95f 100644 --- a/distributedcloud-client/tox.ini +++ b/distributedcloud-client/tox.ini @@ -1,8 +1,7 @@ [tox] envlist = py39,pep8,pylint -minversion = 2.3 +minversion = 4.4.0 skipsdist = True - toxworkdir = /tmp/{env:USER}_dc_client_tox [dcclient] @@ -10,17 +9,16 @@ client_base_dir = . [testenv] basepython = python3.9 -install_command = pip install \ - -c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/starlingx/root/raw/branch/master/build-tools/requirements/debian/upper-constraints.txt} \ - {opts} {packages} setenv = VIRTUAL_ENV={envdir} OS_STDOUT_CAPTURE=1 OS_STDERR_CAPTURE=1 OS_TEST_TIMEOUT=60 -deps = -r{toxinidir}/test-requirements.txt - -r{toxinidir}/requirements.txt +deps = + -c{env:UPPER_CONSTRAINTS_FILE:https://opendev.org/starlingx/root/raw/branch/master/build-tools/requirements/debian/upper-constraints.txt} + -r{toxinidir}/requirements.txt + -r{toxinidir}/test-requirements.txt allowlist_externals = rm @@ -51,6 +49,23 @@ exclude=.venv,.git,.tox,dist,doc,*lib/python*,*egg,build commands = pylint {posargs} dcmanagerclient --rcfile=./.pylintrc +[testenv:black] +# To check only the files that will be modified, use the following command: +# tox -e black -- --diff --check +deps = + black>=23.11.0 # MIT +commands = + black --line-length 85 {posargs} . + +[testenv:black_zuul] +setenv = + {[testenv]setenv} + MODIFIED_FILES={toxinidir}/modified_files.txt +deps = + black>=23.11.0 # MIT +commands = + black --line-length 85 --diff --check {env:MODIFIED_FILES} + [testenv:cover] setenv = PYTHON=coverage run --parallel-mode diff --git a/tox.ini b/tox.ini index 4d7da7e..c52ec2e 100644 --- a/tox.ini +++ b/tox.ini @@ -27,6 +27,12 @@ description = Dummy environment to allow pep8 to be run in subdir tox [testenv:pylint] description = Dummy environment to allow pylint to be run in subdir tox +[testenv:black] +description = Dummy environment to allow black to be run in subdir tox + +[testenv:black_zuul] +description = Dummy environment to allow black_zuul check to be run in subdir tox + [testenv:docs] deps = -r{toxinidir}/doc/requirements.txt commands =