From df4e0cca8c4a99b8d05e01230667fbd5d4e33f92 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Fri, 10 Feb 2023 16:56:59 +0100 Subject: [PATCH 1/5] add pre-commit config files --- .cmake-format.yaml | 6 ++++++ .pre-commit-config.yaml | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 .cmake-format.yaml create mode 100644 .pre-commit-config.yaml diff --git a/.cmake-format.yaml b/.cmake-format.yaml new file mode 100644 index 0000000..5b703c9 --- /dev/null +++ b/.cmake-format.yaml @@ -0,0 +1,6 @@ +# https://cmake-format.readthedocs.io/en/latest/configuration.html + +format: + tab_size: 4 + separate_ctrl_name_with_space: true + separate_fn_name_with_space: false diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..87c5b7f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,35 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + - id: check-added-large-files + - id: check-case-conflict + - id: check-merge-conflict + - id: check-symlinks + - id: check-yaml + - id: check-xml + - id: requirements-txt-fixer + - id: end-of-file-fixer + exclude: external/.*$ + - id: mixed-line-ending + exclude: external/.*$ + - id: trailing-whitespace + exclude: external/.*$ + + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v15.0.6 + hooks: + - id: clang-format + exclude: external/.*$ + + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.13 + hooks: + - id: cmake-format + additional_dependencies: [ pyyaml ] + # - id: cmake-lint + + - repo: https://github.com/psf/black + rev: 22.12.0 + hooks: + - id: black From 17c05ab5caa1564821f93cca5a64669c21992e30 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Fri, 10 Feb 2023 17:09:13 +0100 Subject: [PATCH 2/5] run pre-commit on all files --- .github/workflows/validation.yml | 2 +- .gitlab-ci.yml | 1 - CMakeLists.txt | 16 +- inc/TRestDetectorHitsToTrackFastProcess.h | 4 +- inc/TRestRawReadoutAnalysisProcess.h | 2 +- inc/TRestRawToDetectorSignalProcess.h | 8 +- pipeline/clang-format/clang-format.sh | 1 - pipeline/clang-format/clangformattest.sh | 1 - pipeline/validateLibrary.py | 224 +++++++++++----------- 9 files changed, 134 insertions(+), 125 deletions(-) diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 5bf37f3..1d15428 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -21,7 +21,7 @@ defaults: jobs: framework-validation: uses: rest-for-physics/framework/.github/workflows/validation.yml@master - + libCheck: name: Validate library runs-on: ubuntu-latest diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a5e01b9..47d71a6 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -28,4 +28,3 @@ Validate Library: except: variables: - $CRONJOB == "YES" - diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ada95e..b8a41cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,11 +6,14 @@ set(excludes) set(deps detector geant4 track raw) if (NOT ${RESTLIB_RAW} MATCHES "ON") list(REMOVE_ITEM deps raw) - set(excludes ${excludes} TRestDetectorSignalToRawSignalProcess TRestRawReadoutAnalysisProcess TRestRawToDetectorSignalProcess) + set(excludes ${excludes} TRestDetectorSignalToRawSignalProcess + TRestRawReadoutAnalysisProcess TRestRawToDetectorSignalProcess) endif () if (NOT ${RESTLIB_TRACK} MATCHES "ON") list(REMOVE_ITEM deps track) - set(excludes ${excludes} TRestDetectorHitsToTrackProcess TRestDetectorHitsToTrackFastProcess TRestTrackToDetectorHitsProcess) + set(excludes + ${excludes} TRestDetectorHitsToTrackProcess + TRestDetectorHitsToTrackFastProcess TRestTrackToDetectorHitsProcess) endif () if (NOT ${RESTLIB_GEANT4} MATCHES "ON") list(REMOVE_ITEM deps geant4) @@ -19,9 +22,12 @@ endif () list(LENGTH deps ndeps) if (NOT ${ndeps} MATCHES 1) - COMPILELIB(deps) + compilelib(deps) else () - message(WARNING "Library RESTConnectors requires at least one active library (${deps})") + message( + WARNING + "Library RESTConnectors requires at least one active library (${deps})" + ) endif () -ADD_LIBRARY_TEST() +add_library_test() diff --git a/inc/TRestDetectorHitsToTrackFastProcess.h b/inc/TRestDetectorHitsToTrackFastProcess.h index ebf1e05..c9c03c9 100644 --- a/inc/TRestDetectorHitsToTrackFastProcess.h +++ b/inc/TRestDetectorHitsToTrackFastProcess.h @@ -53,8 +53,8 @@ class TRestDetectorHitsToTrackFastProcess : public TRestEventProcess { RESTMetadata << " Cell resolution : " << fCellResolution << " mm " << RESTendl; RESTMetadata << " Net size : " << fNetSize << " mm " << RESTendl; - RESTMetadata << " Net origin : ( " << fNetOrigin.X() << " , " << fNetOrigin.Y() << " , " << fNetOrigin.Z() - << " ) mm " << RESTendl; + RESTMetadata << " Net origin : ( " << fNetOrigin.X() << " , " << fNetOrigin.Y() << " , " + << fNetOrigin.Z() << " ) mm " << RESTendl; RESTMetadata << " Number of nodes (per axis) : " << fNodes << RESTendl; EndPrintProcess(); diff --git a/inc/TRestRawReadoutAnalysisProcess.h b/inc/TRestRawReadoutAnalysisProcess.h index 9c753e3..5dc03de 100644 --- a/inc/TRestRawReadoutAnalysisProcess.h +++ b/inc/TRestRawReadoutAnalysisProcess.h @@ -14,7 +14,7 @@ #include -//#include +// #include #include #include diff --git a/inc/TRestRawToDetectorSignalProcess.h b/inc/TRestRawToDetectorSignalProcess.h index 70c362f..9af1950 100644 --- a/inc/TRestRawToDetectorSignalProcess.h +++ b/inc/TRestRawToDetectorSignalProcess.h @@ -90,10 +90,10 @@ class TRestRawToDetectorSignalProcess : public TRestEventProcess { RESTMetadata << "Gain : " << fGain << RESTendl; if (fZeroSuppression) { - RESTMetadata << "Base line range definition : ( " << fBaseLineRange.X() << " , " << fBaseLineRange.Y() - << " ) " << RESTendl; - RESTMetadata << "Integral range : ( " << fIntegralRange.X() << " , " << fIntegralRange.Y() << " ) " - << RESTendl; + RESTMetadata << "Base line range definition : ( " << fBaseLineRange.X() << " , " + << fBaseLineRange.Y() << " ) " << RESTendl; + RESTMetadata << "Integral range : ( " << fIntegralRange.X() << " , " << fIntegralRange.Y() + << " ) " << RESTendl; RESTMetadata << "Point Threshold : " << fPointThreshold << " sigmas" << RESTendl; RESTMetadata << "Signal threshold : " << fSignalThreshold << " sigmas" << RESTendl; RESTMetadata << "Number of points over threshold : " << fNPointsOverThreshold << RESTendl; diff --git a/pipeline/clang-format/clang-format.sh b/pipeline/clang-format/clang-format.sh index 09ad268..f06fdef 100755 --- a/pipeline/clang-format/clang-format.sh +++ b/pipeline/clang-format/clang-format.sh @@ -106,4 +106,3 @@ if [ "-" = "$1" ] ; then }"' '"${file}"' done fi - diff --git a/pipeline/clang-format/clangformattest.sh b/pipeline/clang-format/clangformattest.sh index 41defb1..6c4fb55 100755 --- a/pipeline/clang-format/clangformattest.sh +++ b/pipeline/clang-format/clangformattest.sh @@ -52,4 +52,3 @@ fi git reset HEAD --hard exit 1 - diff --git a/pipeline/validateLibrary.py b/pipeline/validateLibrary.py index 6510e05..c943d94 100755 --- a/pipeline/validateLibrary.py +++ b/pipeline/validateLibrary.py @@ -5,7 +5,7 @@ # J. Galan - Javier.Galan.Lacarra@cern.ch # 23 - Dec - 2019 -#from __future__ import print_function +# from __future__ import print_function import os import sys import re @@ -14,41 +14,42 @@ def validateClass(className): - print ("") - print ("++++ Validating class : " + className) - with open(className, 'r', encoding="utf-8") as file: + print("") + print("++++ Validating class : " + className) + with open(className, "r", encoding="utf-8") as file: data = file.read() - data = data[data.find("::Initialize"):] + data = data[data.find("::Initialize") :] data = getMethodDefinition(data) data = removeCppComment(data) - #print (data) - #print data.find("SETLIBRARYVERSION(LIBRARY_VERSION);") + # print (data) + # print data.find("SETLIBRARYVERSION(LIBRARY_VERSION);") if data.find("SETLIBRARYVERSION(LIBRARY_VERSION);") >= 0: - print ("OK") + print("OK") return else: - print( "Problem found at class : " + className ) - print( "SetLibraryVersion was NOT found at Initialization!" ) + print("Problem found at class : " + className) + print("SetLibraryVersion was NOT found at Initialization!") sys.exit(1) return + def getObservablePositions(data): obsposes = {} pos = 0 - str = "SETOBSERVABLEVALUE(\"" - while(pos < len(data)): - pos1 = data.find(str,pos) - if(pos1 == -1): - break + str = 'SETOBSERVABLEVALUE("' + while pos < len(data): + pos1 = data.find(str, pos) + if pos1 == -1: + break pos1 += len(str) - pos2 = data.find("\"",pos1) - if(pos2 == -1): - break + pos2 = data.find('"', pos1) + if pos2 == -1: + break name = data[pos1:pos2] - if(not name in obsposes): + if not name in obsposes: obsposes[name] = pos1 pos = pos2 + 1 @@ -60,115 +61,120 @@ def getMethodDefinition(text): counter = 1 start = initPos + 1 - while(counter > 0): - pos1 = text.find("{",start) - pos2 = text.find("}",start) + while counter > 0: + pos1 = text.find("{", start) + pos2 = text.find("}", start) endPosition = pos2 + 1 - if(pos1 != -1 and pos2 != -1): - if(pos1 < pos2): + if pos1 != -1 and pos2 != -1: + if pos1 < pos2: counter = counter + 1 start = pos1 + 1 - if(pos2 < pos1): + if pos2 < pos1: counter = counter - 1 start = pos2 + 1 elif pos1 != -1: - print ("Big error!!") + print("Big error!!") else: - counter = counter - 1 - start = pos2 + 1 + counter = counter - 1 + start = pos2 + 1 return text[initPos:endPosition].upper() -def removeCppComment(strInput) : - state = 0; - strOutput = '' - strRemoved = '' - - for c in strInput : - if state == 0 and c == '/' : # ex. [/] - state = 1 - elif state == 1 and c == '*' : # ex. [/*] - state = 2 - elif state == 1 and c == '/' : # ex. [#] - state = 4 - elif state == 1 : # ex. [ or 5/3] - state = 0 - - elif state == 3 and c == '*': # ex. [/*he**] - state = 3 - elif state == 2 and c == '*': # ex. [/*he*] - state = 3 - elif state == 2: # ex. [/*heh] - state = 2 - - elif state == 3 and c == '/': # ex. [/*heh*/] - state = 0 - elif state == 3: # ex. [/*heh*e] - state = 2 - - elif state == 4 and c == '\\': # ex. [//hehe\] - state = 9 - elif state == 9 and c == '\\': # ex. [//hehe\\\\\] - state = 9 - elif state == 9: # ex. [//hehe\ or //hehe\a] - state = 4 - elif state == 4 and c == '\n': # ex. [//hehe] - state = 0 - - elif state == 0 and c == '\'': # ex. ['] - state = 5 - elif state == 5 and c == '\\': # ex. ['\] - state = 6 - elif state == 6: # ex. ['\n or '\' or '\t etc.] - state = 5 - elif state == 5 and c == '\'': # ex. ['\n' or '\'' or '\t' ect.] - state = 0 - - elif state == 0 and c == '\"': # ex. ["] - state = 7 - elif state == 7 and c == '\\': # ex. ["\] - state = 8 - elif state == 8: # ex. ["\n or "\" or "\t ect.] - state = 7 - elif state == 7 and c == '\"': # ex. ["\n" or "\"" or "\t" ect.] - state = 0 - - if (state == 0 and c != '/') or state == 5 or\ - state == 6 or state == 7 or state == 8 : - strOutput += c - else: - # removed chareters - strRemoved += c - - return strOutput +def removeCppComment(strInput): + state = 0 + strOutput = "" + strRemoved = "" + + for c in strInput: + if state == 0 and c == "/": # ex. [/] + state = 1 + elif state == 1 and c == "*": # ex. [/*] + state = 2 + elif state == 1 and c == "/": # ex. [#] + state = 4 + elif state == 1: # ex. [ or 5/3] + state = 0 + + elif state == 3 and c == "*": # ex. [/*he**] + state = 3 + elif state == 2 and c == "*": # ex. [/*he*] + state = 3 + elif state == 2: # ex. [/*heh] + state = 2 + + elif state == 3 and c == "/": # ex. [/*heh*/] + state = 0 + elif state == 3: # ex. [/*heh*e] + state = 2 + + elif state == 4 and c == "\\": # ex. [//hehe\] + state = 9 + elif state == 9 and c == "\\": # ex. [//hehe\\\\\] + state = 9 + elif state == 9: # ex. [//hehe\ or //hehe\a] + state = 4 + elif state == 4 and c == "\n": # ex. [//hehe] + state = 0 + + elif state == 0 and c == "'": # ex. ['] + state = 5 + elif state == 5 and c == "\\": # ex. ['\] + state = 6 + elif state == 6: # ex. ['\n or '\' or '\t etc.] + state = 5 + elif state == 5 and c == "'": # ex. ['\n' or '\'' or '\t' ect.] + state = 0 + + elif state == 0 and c == '"': # ex. ["] + state = 7 + elif state == 7 and c == "\\": # ex. ["\] + state = 8 + elif state == 8: # ex. ["\n or "\" or "\t ect.] + state = 7 + elif state == 7 and c == '"': # ex. ["\n" or "\"" or "\t" ect.] + state = 0 + + if ( + (state == 0 and c != "/") + or state == 5 + or state == 6 + or state == 7 + or state == 8 + ): + strOutput += c + else: + # removed chareters + strRemoved += c + + return strOutput files = [] # r=root, d=directories, f = files for r, d, f in os.walk(sys.argv[1]): - for file in f: - validate = 0 - if '.cxx' in file: -# print ( file ) - with open(os.path.join(r, file), encoding="utf-8") as fin: - if '::InitFromConfigFile' in fin.read(): - validate = 1 - with open(os.path.join(r, file), encoding="utf-8") as fin: - if '::LoadDefaultConfig' in fin.read(): - validate = 1 - with open(os.path.join(r, file), encoding="utf-8") as fin: - if '::Initialize' in fin.read(): - validate = validate + 1 - if validate == 2: - files.append(os.path.join(r, file)) - validateClass(os.path.join(r, file)) - -#for f in files: + for file in f: + validate = 0 + if ".cxx" in file: + # print ( file ) + with open(os.path.join(r, file), encoding="utf-8") as fin: + if "::InitFromConfigFile" in fin.read(): + validate = 1 + with open(os.path.join(r, file), encoding="utf-8") as fin: + if "::LoadDefaultConfig" in fin.read(): + validate = 1 + with open(os.path.join(r, file), encoding="utf-8") as fin: + if "::Initialize" in fin.read(): + validate = validate + 1 + if validate == 2: + files.append(os.path.join(r, file)) + validateClass(os.path.join(r, file)) + +# for f in files: # print(f) -#validateProcess(sys.argv[1]); +# validateProcess(sys.argv[1]); sys.exit(0) From b7f840d2e876004d2ce9080ee1ebb14b5e0ec0c0 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Fri, 10 Feb 2023 17:12:26 +0100 Subject: [PATCH 3/5] add pre-commit files check to workflow --- .github/workflows/validation.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 1d15428..859db34 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -29,7 +29,7 @@ jobs: image: ghcr.io/lobis/root-geant4-garfield:rest-for-physics steps: - uses: actions/checkout@v3 - - run: python3 pipeline/validateLibrary.py . + - run: python3 pipeline/validateLibrary.py . build-connectorslib: name: Build only connectorslib @@ -43,6 +43,10 @@ jobs: with: cmake-flags: "-DCMAKE_INSTALL_PREFIX=${{ env.REST_PATH }} -DCMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} -DREST_WELCOME=ON -DRESTLIB_CONNECTORS=ON" branch: ${{ env.BRANCH_NAME }} + - name: Verify pre-commit config files match + run: | + cd $GITHUB_WORKSPACE + python ${{ env.REST_PATH }}/scripts/validatePreCommitConfig.py - name: Load REST libraries run: | source ${{ env.REST_PATH }}/thisREST.sh From 360d31eaf86a65cb848e3d97f28f8e97c525d568 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Fri, 10 Feb 2023 17:33:33 +0100 Subject: [PATCH 4/5] run the validation script using curl --- .github/workflows/validation.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index 859db34..c01666b 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -44,9 +44,7 @@ jobs: cmake-flags: "-DCMAKE_INSTALL_PREFIX=${{ env.REST_PATH }} -DCMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} -DREST_WELCOME=ON -DRESTLIB_CONNECTORS=ON" branch: ${{ env.BRANCH_NAME }} - name: Verify pre-commit config files match - run: | - cd $GITHUB_WORKSPACE - python ${{ env.REST_PATH }}/scripts/validatePreCommitConfig.py + run: curl https://raw.githubusercontent.com/rest-for-physics/framework/master/scripts/validatePreCommitConfig.py | sudo python - - name: Load REST libraries run: | source ${{ env.REST_PATH }}/thisREST.sh From 8f023955e9e743cf13c345f6af4642da6ddb46c2 Mon Sep 17 00:00:00 2001 From: Luis Antonio Obis Aparicio Date: Fri, 10 Feb 2023 17:36:17 +0100 Subject: [PATCH 5/5] make sure the directory is correct --- .github/workflows/validation.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/validation.yml b/.github/workflows/validation.yml index c01666b..145e805 100644 --- a/.github/workflows/validation.yml +++ b/.github/workflows/validation.yml @@ -44,7 +44,9 @@ jobs: cmake-flags: "-DCMAKE_INSTALL_PREFIX=${{ env.REST_PATH }} -DCMAKE_BUILD_TYPE=${{ env.CMAKE_BUILD_TYPE }} -DREST_WELCOME=ON -DRESTLIB_CONNECTORS=ON" branch: ${{ env.BRANCH_NAME }} - name: Verify pre-commit config files match - run: curl https://raw.githubusercontent.com/rest-for-physics/framework/master/scripts/validatePreCommitConfig.py | sudo python - + run: | + cd $GITHUB_WORKSPACE + curl https://raw.githubusercontent.com/rest-for-physics/framework/master/scripts/validatePreCommitConfig.py | python - name: Load REST libraries run: | source ${{ env.REST_PATH }}/thisREST.sh