Skip to content

Commit

Permalink
CI: Ruff (ECP-WarpX#5123)
Browse files Browse the repository at this point in the history
* Pre-Commits: Ruff

Ruff is an extremely fast Python linter and code formatter. It replaces
tools such as autoflake, flake8, pyflakes, or pylint.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Import Bugs: Missing and Shadowing

- add missing imports
- fix shadowing of import names with variables

* Constant `c` already imported

Fix "Redefinition of unused `c`".

* Fix: E741 Ambiguous variable name: `l`/`I`

* Fix: File is not always closed

Properly close file after reading `warpx_used_inputs`.

* Checksum import: Use Temporaries

Suggestion by Dave.

* f-string

* Capacitive Discharge Analysis: Keep Block

Format off

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
ax3l and pre-commit-ci[bot] authored Aug 21, 2024
1 parent c2337d3 commit 3dda26f
Show file tree
Hide file tree
Showing 224 changed files with 14,057 additions and 10,093 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/source/ci_matrix.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#!/usr/bin/env python

# Concatenation of tests in each of the 6 elements in CI matrix
f = open('./ci_matrix_elements.txt') ; matrix_elements = f.readlines() ; f.close()
f = open("./ci_matrix_elements.txt")
matrix_elements = f.readlines()
f.close()
# All tests read by prepare_file_ci.py
f = open('./ci_all_tests.txt') ; all_tests = f.readlines() ; f.close()
f = open("./ci_all_tests.txt")
all_tests = f.readlines()
f.close()

# Now let's make sure these two are equal

# Remove these elements from both lists, as they are are not test names
elements_to_remove = ['[main]\n', '[AMReX]\n', '[source]\n', '[extra-PICSAR]\n']
elements_to_remove = ["[main]\n", "[AMReX]\n", "[source]\n", "[extra-PICSAR]\n"]
for element in elements_to_remove:
for x in range(matrix_elements.count(element)):
matrix_elements.remove(element)
Expand All @@ -23,4 +27,4 @@
print("Tests in initial list but not in the matrix:")
print(list(set(all_tests) - set(matrix_elements)))

assert( matrix_elements == all_tests )
assert matrix_elements == all_tests
38 changes: 24 additions & 14 deletions .github/workflows/source/makeMakefileForClangTidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,49 @@

def makeMakefileForClangTidy(argv):
parser = argparse.ArgumentParser()
parser.add_argument("--input",
help="Ccache log file",
default="ccache.log.txt")
parser.add_argument("--identifier",
help="Unique identifier for finding compilation line in the log file",
default="WarpX/Source")
parser.add_argument("--input", help="Ccache log file", default="ccache.log.txt")
parser.add_argument(
"--identifier",
help="Unique identifier for finding compilation line in the log file",
default="WarpX/Source",
)
# We assume WarpX/Source can be used as an identifier to distinguish
# WarpX code from amrex, openMPD, and cmake's temporary files like
# build/CMakeFiles/CMakeScratch/TryCompile-hw3x4m/test_mpi.cpp
parser.add_argument("--output",
help="Make file for clang-tidy",
default="clang-tidy-ccache-misses.mak")
parser.add_argument(
"--output",
help="Make file for clang-tidy",
default="clang-tidy-ccache-misses.mak",
)
args = parser.parse_args()

fin = open(args.input, "r")
fout = open(args.output, "w")

fout.write("CLANG_TIDY ?= clang-tidy\n")
fout.write("override CLANG_TIDY_ARGS += --extra-arg=-Wno-unknown-warning-option --extra-arg-before=--driver-mode=g++\n")
fout.write(
"override CLANG_TIDY_ARGS += --extra-arg=-Wno-unknown-warning-option --extra-arg-before=--driver-mode=g++\n"
)
fout.write("\n")

fout.write(".SECONDEXPANSION:\n")
fout.write("clang-tidy: $$(all_targets)\n")
fout.write("\t@echo SUCCESS\n\n")

exe_re = re.compile(r" Executing .*? (-.*{}.*) -c .* -o .* (\S*)".format(args.identifier))
exe_re = re.compile(
r" Executing .*? (-.*{}.*) -c .* -o .* (\S*)".format(args.identifier)
)

count = 0
for line in fin.readlines():
ret_exe_re = exe_re.search(line)
if (ret_exe_re):
if ret_exe_re:
fout.write("target_{}: {}\n".format(count, ret_exe_re.group(2)))
fout.write("\t$(CLANG_TIDY) $(CLANG_TIDY_ARGS) $< -- {}\n".format
(ret_exe_re.group(1)))
fout.write(
"\t$(CLANG_TIDY) $(CLANG_TIDY_ARGS) $< -- {}\n".format(
ret_exe_re.group(1)
)
)
fout.write("\ttouch target_{}\n\n".format(count))
count = count + 1

Expand All @@ -61,5 +70,6 @@ def makeMakefileForClangTidy(argv):
fout.close()
fin.close()


if __name__ == "__main__":
makeMakefileForClangTidy(sys.argv)
46 changes: 9 additions & 37 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -66,44 +66,16 @@ repos:
# C++ formatting
# clang-format

# Autoremoves unused Python imports
- repo: https://github.com/hadialqattan/pycln
rev: v2.4.0
# Python: Ruff linter & formatter
# https://docs.astral.sh/ruff/
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.5.7
hooks:
- id: pycln
name: pycln (python)

# Sorts Python imports according to PEP8
# https://www.python.org/dev/peps/pep-0008/#imports
- repo: https://github.com/pycqa/isort
rev: 5.13.2
hooks:
- id: isort
name: isort (python)
args: ['--profile black']

# Python: Flake8 (checks only, does this support auto-fixes?)
#- repo: https://github.com/PyCQA/flake8
# rev: 4.0.1
# hooks:
# - id: flake8
# additional_dependencies: &flake8_dependencies
# - flake8-bugbear
# - pep8-naming
# exclude: ^(docs/.*|tools/.*)$
# Alternatively: use autopep8?

# Python Formatting
#- repo: https://github.com/psf/black
# rev: 21.10b0 # Keep in sync with blacken-docs
# hooks:
# - id: black
#- repo: https://github.com/asottile/blacken-docs
# rev: v1.11.0
# hooks:
# - id: blacken-docs
# additional_dependencies:
# - black==21.10b0 # keep in sync with black hook
# Run the linter
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
# Run the formatter
- id: ruff-format

# Jupyter Notebooks: clean up all cell outputs
- repo: https://github.com/roy-ht/pre-commit-jupyter
Expand Down
Loading

0 comments on commit 3dda26f

Please sign in to comment.