Skip to content

Commit

Permalink
Apply formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
aandvalenzuela committed Nov 18, 2024
1 parent 1c95ad8 commit 5b9be8f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
17 changes: 11 additions & 6 deletions PFA.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
#!/usr/bin/python3
import os
import argparse


def find_file_path(file):
if not os.path.isfile(file):
return None
return os.path.realpath(file)


def find_python_files(directory):
py_files = []
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".py"):
py_files.append(os.path.join(root, file))
return py_files


def CodeQualityChecks(python_files):
if python_files:
for file in python_files:
Expand All @@ -23,15 +29,13 @@ def CodeQualityChecks(python_files):
format_command = "ruff format {}".format(file_path)
print("Executing command: {}".format(format_command)) # Debug print
os.system(format_command)


def main():
parser = argparse.ArgumentParser(
description="Linting and formatting Python files in directories or file paths."
)
parser.add_argument(
"paths",
nargs="+",
help="List of directories or file paths to process"
)
parser.add_argument("paths", nargs="+", help="List of directories or file paths to process")
args = parser.parse_args()

all_python_files = []
Expand All @@ -44,6 +48,7 @@ def main():
print("Error: {} is not a valid file or directory.".format(path))
return
CodeQualityChecks(all_python_files)


if __name__ == "__main__":
main()

13 changes: 5 additions & 8 deletions run-python-format.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/python3
import os
import argparse


def main():
parser = argparse.ArgumentParser(description="Run Python formatting and linting.")
parser.add_argument(
Expand All @@ -23,9 +25,7 @@ def main():
return
try:
with open(input_file, "r") as file:
files_list = [
os.path.join(cmssw_base, line.strip()) for line in file if line.strip()
]
files_list = [os.path.join(cmssw_base, line.strip()) for line in file if line.strip()]
except IOError as e:
print("Error reading {}: {}".format(input_file, e))
return
Expand All @@ -47,10 +47,7 @@ def main():
linting_output.write("All checks passed!\n")

print("Python linting completed. Check 'python-linting.txt' for details.")
pfa_command = (
"python3 ../cms-bot/PFA.py "
+ " ".join(files_list)
)
pfa_command = "python3 ../cms-bot/PFA.py " + " ".join(files_list)

format_result = os.system(pfa_command)

Expand All @@ -59,6 +56,6 @@ def main():
else:
print("An error occurred while running PFA.py. Exit code: {}".format(format_result))


if __name__ == "__main__":
main()

0 comments on commit 5b9be8f

Please sign in to comment.