Skip to content

Commit

Permalink
Merge pull request #27 from rest-for-physics/lobis-pre-commit
Browse files Browse the repository at this point in the history
Implement pre-commit checks and format files
  • Loading branch information
lobis authored Feb 10, 2023
2 parents b7f0e27 + 88b3f5f commit e4dd425
Show file tree
Hide file tree
Showing 30 changed files with 2,265 additions and 2,310 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ DerivePointerAlignment: false
PointerAlignment: Left

IndentWidth: 4
ColumnLimit : 110
ColumnLimit: 110
6 changes: 6 additions & 0 deletions .cmake-format.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 6 additions & 2 deletions .github/workflows/validation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ defaults:
jobs:
framework-validation:
uses: rest-for-physics/framework/.github/workflows/validation.yml@master

libCheck:
name: Validate library
runs-on: ubuntu-latest
container:
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-tracklib:
name: Build only tracklib
Expand All @@ -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_TRACK=ON"
branch: ${{ env.BRANCH_NAME }}
- name: Verify pre-commit config files match
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
Expand Down
35 changes: 35 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
15 changes: 7 additions & 8 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
set( LibraryVersion "1.4" )
set(LibraryVersion "1.4")
add_definitions(-DLIBRARY_VERSION="${LibraryVersion}")

file(GLOB_RECURSE addon_src
file(
GLOB_RECURSE
addon_src
"trackMinimization.c"
"allocrus.c"
"edgelen.c"
"edgeutil.c"
"heldkarp.c" )
"heldkarp.c")

set(addon_inc ${CMAKE_CURRENT_SOURCE_DIR}/tsp/inc)

COMPILELIB("")

compilelib("")

file(GLOB_RECURSE MAC "${CMAKE_CURRENT_SOURCE_DIR}/macros/*")
INSTALL(FILES ${MAC} DESTINATION ./macros/track)


install(FILES ${MAC} DESTINATION ./macros/track)
3 changes: 2 additions & 1 deletion inc/TRestTrackPathMinimizationProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
#define RestCore_TRestTrackPathMinimizationProcess

#include <TRestTrackEvent.h>
#include "TRestEventProcess.h"
#include <trackMinimization.h>

#include "TRestEventProcess.h"

class TRestTrackPathMinimizationProcess : public TRestEventProcess {
private:
#ifndef __CINT__
Expand Down
1 change: 0 additions & 1 deletion pipeline/clang-format/clang-format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,3 @@ if [ "-" = "$1" ] ; then
}"' '"${file}"'
done
fi

1 change: 0 additions & 1 deletion pipeline/clang-format/clangformattest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,3 @@ fi
git reset HEAD --hard

exit 1

59 changes: 32 additions & 27 deletions pipeline/validateLibrary.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

def validateClass(className):
print(f"\n++++ Validating class : {className}")
with open(className, 'r') as file:
with open(className, "r") as file:
data = file.read()

data = data[data.find("::Initialize"):]
data = data[data.find("::Initialize") :]
data = getMethodDefinition(data)
data = removeCppComment(data)

Expand All @@ -30,13 +30,13 @@ def validateClass(className):
def getObservablePositions(data):
obsposes = {}
pos = 0
str = "SETOBSERVABLEVALUE(\""
str = 'SETOBSERVABLEVALUE("'
while pos < len(data):
pos1 = data.find(str, pos)
if pos1 == -1:
break
pos1 += len(str)
pos2 = data.find("\"", pos1)
pos2 = data.find('"', pos1)
if pos2 == -1:
break

Expand Down Expand Up @@ -78,60 +78,65 @@ def getMethodDefinition(text):

def removeCppComment(strInput):
state = 0
strOutput = ''
strRemoved = ''
strOutput = ""
strRemoved = ""

for c in strInput:
if state == 0 and c == '/': # ex. [/]
if state == 0 and c == "/": # ex. [/]
state = 1
elif state == 1 and c == '*': # ex. [/*]
elif state == 1 and c == "*": # ex. [/*]
state = 2
elif state == 1 and c == '/': # ex. [#]
elif state == 1 and c == "/": # ex. [#]
state = 4
elif state == 1: # ex. [<secure/_stdio.h> or 5/3]
state = 0

elif state == 3 and c == '*': # ex. [/*he**]
elif state == 3 and c == "*": # ex. [/*he**]
state = 3
elif state == 2 and c == '*': # ex. [/*he*]
elif state == 2 and c == "*": # ex. [/*he*]
state = 3
elif state == 2: # ex. [/*heh]
state = 2

elif state == 3 and c == '/': # ex. [/*heh*/]
elif state == 3 and c == "/": # ex. [/*heh*/]
state = 0
elif state == 3: # ex. [/*heh*e]
state = 2

elif state == 4 and c == '\\': # ex. [//hehe\]
elif state == 4 and c == "\\": # ex. [//hehe\]
state = 9
elif state == 9 and c == '\\': # ex. [//hehe\\\\\]
elif state == 9 and c == "\\": # ex. [//hehe\\\\\]
state = 9
elif state == 9: # ex. [//hehe\<enter> or //hehe\a]
state = 4
elif state == 4 and c == '\n': # ex. [//hehe<enter>]
elif state == 4 and c == "\n": # ex. [//hehe<enter>]
state = 0

elif state == 0 and c == '\'': # ex. [']
elif state == 0 and c == "'": # ex. [']
state = 5
elif state == 5 and c == '\\': # ex. ['\]
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.]
elif state == 5 and c == "'": # ex. ['\n' or '\'' or '\t' ect.]
state = 0

elif state == 0 and c == '\"': # ex. ["]
elif state == 0 and c == '"': # ex. ["]
state = 7
elif state == 7 and c == '\\': # ex. ["\]
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.]
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:
if (
(state == 0 and c != "/")
or state == 5
or state == 6
or state == 7
or state == 8
):
strOutput += c
else:
# removed characters
Expand All @@ -146,15 +151,15 @@ def removeCppComment(strInput):
for r, d, f in os.walk(sys.argv[1]):
for file in f:
validate = 0
if '.cxx' in file:
if ".cxx" in file:
with open(os.path.join(r, file)) as fin:
if '::InitFromConfigFile' in fin.read():
if "::InitFromConfigFile" in fin.read():
validate = 1
with open(os.path.join(r, file)) as fin:
if '::LoadDefaultConfig' in fin.read():
if "::LoadDefaultConfig" in fin.read():
validate = 1
with open(os.path.join(r, file)) as fin:
if '::Initialize' in fin.read():
if "::Initialize" in fin.read():
validate = validate + 1
if validate == 2:
files.append(os.path.join(r, file))
Expand Down
3 changes: 2 additions & 1 deletion src/TRestTrackDetachIsolatedNodesProcess.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ TRestEvent* TRestTrackDetachIsolatedNodesProcess::ProcessEvent(TRestEvent* input
cout << "TRestTrackDetachIsolatedNodesProcess. Number of tracks : "
<< fInputTrackEvent->GetNumberOfTracks() << endl;

if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug) fInputTrackEvent->PrintEvent();
if (GetVerboseLevel() >= TRestStringOutput::REST_Verbose_Level::REST_Debug)
fInputTrackEvent->PrintEvent();

// Copying the input tracks to the output track
for (int tck = 0; tck < fInputTrackEvent->GetNumberOfTracks(); tck++)
Expand Down
2 changes: 1 addition & 1 deletion tsp/inc/bigguy.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ CCbigguy CCbigguy_itobigguy(int d), CCbigguy_dtobigguy(double d), CCbigguy_ceil(
#define CCbigguy_add(x, y) (CCbigguy_addmult(x, y, 1))
#define CCbigguy_sub(x, y) (CCbigguy_addmult(x, y, -1))

int CCbigguy_swrite(CC_SFILE*f, CCbigguy x), CCbigguy_sread(CC_SFILE*f, CCbigguy*x);
int CCbigguy_swrite(CC_SFILE* f, CCbigguy x), CCbigguy_sread(CC_SFILE* f, CCbigguy* x);

#endif /* __BIGGUY_H */
12 changes: 6 additions & 6 deletions tsp/inc/combs.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ typedef struct CC_GCgraph {
CC_GCedge* edgespace;
} CC_GCgraph;

int CCcombs_find_blocks(int ncount, int ecount, int*elist, double*x, int*nblocks, int**blockcnts,
int***blocks, int*ncutnodes, int**cutnodes),
CCcombs_greedy_cut(CC_GCgraph*g, int*setsize, int*set, int mark_fixed, int forced_moves, int bad_moves,
int fixed_moves, int*moves_done, double*cut_val),
CCcombs_GC_build_graph(CC_GCgraph*G, int ncount, int ecount, int*elist, double*x);
int CCcombs_find_blocks(int ncount, int ecount, int* elist, double* x, int* nblocks, int** blockcnts,
int*** blocks, int* ncutnodes, int** cutnodes),
CCcombs_greedy_cut(CC_GCgraph* g, int* setsize, int* set, int mark_fixed, int forced_moves, int bad_moves,
int fixed_moves, int* moves_done, double* cut_val),
CCcombs_GC_build_graph(CC_GCgraph* G, int ncount, int ecount, int* elist, double* x);

void CCcombs_GC_init_graph(CC_GCgraph*G), CCcombs_GC_free_graph(CC_GCgraph*G);
void CCcombs_GC_init_graph(CC_GCgraph* G), CCcombs_GC_free_graph(CC_GCgraph* G);

#endif /* __COMBS_H */
Loading

0 comments on commit e4dd425

Please sign in to comment.