Files
distcloud/distributedcloud/run_black.py
Hugo Brito 75cb349622 Create stx-distcloud-tox-black job
This commit introduces a new Zuul job, stx-distcloud-tox-black,
and a corresponding black_check tox environment to ensure Python
files are formatted with Black.

Initially, the black_check environment will check the formatting
of specified modules[1]. As modules are progressively formatted, the
configuration will be updated to enforce Black formatting on these
modules. During this transition, the job will only fail for modules
that have been updated to comply with Black formatting. Eventually,
the environment will be configured to check the entire project,
ensuring consistent code style across all files.

1: Check `modules` in run_black.py script.

Note: Once all modules are formatted, run_black.py will be deleted.

Test Plan:
PASS - Success in stx-distcloud-tox-black

Story: 2011149
Task: 50432

Change-Id: I8a8044d44b85679cf5e71106784c192ef343f5b6
Signed-off-by: Hugo Brito <hugo.brito@windriver.com>
2024-06-25 14:49:42 -03:00

44 lines
1.0 KiB
Python

# noqa: H102
import subprocess
import sys
# List of module directories to check
modules = [
"dccommon",
"dcdbsync/api",
"dcdbsync",
"dcorch/api",
"dcorch/common",
"dcorch/db",
"dcorch/engine",
"dcorch",
"dcmanager/api",
"dcmanager/audit",
"dcmanager/common",
"dcmanager/db",
"dcmanager/orchestrator",
"dcmanager/tests",
"dcmanager",
]
# List of modules that are already formatted with black
formatted_modules = []
# Function to run black check
def run_black_check(module):
try:
subprocess.run(["black", "--check", "--quiet", f"./{module}"], check=True)
print(f"Black check passed for {module}")
except subprocess.CalledProcessError as e:
print(f"Black check failed for {module}")
# If the module is in formatted_modules, stx-distcloud-tox-black will fail
if module in formatted_modules:
sys.exit(e.returncode)
# Iterate over modules and run black check
for module in modules:
run_black_check(module)