Skip to content

Commit

Permalink
[format] Run black on all python sources
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Feb 12, 2024
1 parent 381c08b commit 7ce7301
Show file tree
Hide file tree
Showing 26 changed files with 456 additions and 326 deletions.
2 changes: 1 addition & 1 deletion k4FWCore/python/k4FWCore/parseArgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@
#
import argparse

parser = argparse.ArgumentParser(description="Run job in the Key4HEP framework", add_help=False)
parser = argparse.ArgumentParser(description="Run job in the Key4HEP framework", add_help=False)
84 changes: 43 additions & 41 deletions k4FWCore/scripts/k4-print-joboptions
Original file line number Diff line number Diff line change
Expand Up @@ -14,54 +14,56 @@ import re
# groups are added for each quote, the number and the semicolon
# so the quote can easily be removed
_regexp_int = re.compile(r'(")([-+]?[0-9]+)(")(;)')


def _sanitize(s):
"""
helper function for postprocessing of key4hep job options
quotes need to be removed around ints, lists, dicts and bools,
and some properties that get stored by the job options svc need to be disabled
Parameters
----------
s: str
String containing key4hep joboptions (.opts format) to be sanitized.
Returns
-------
s: str
The sanitized string that should be compatible with gaudirun.py
"""
# convert s to standard string (might be a root string)
s = str(s)
s = s.replace('"False"', 'False')
s = s.replace('"True"', 'True')
s = s.replace('"[', '[')
s = s.replace(']"', ']')
s = s.replace('"{', '{')
s = s.replace('}"', '}')
s = re.sub(_regexp_int, r"\g<2>\g<4>", s)
s = s.replace("ApplicationMgr.Go = ", "#ApplicationMgr.Go = ")
s = s.replace("ApplicationMgr.Exit = ", "#ApplicationMgr.Exit = ")
s = s.replace("ApplicationMgr.Environment = { };", "#ApplicationMgr.Environment = { };")
s = s.replace("ApplicationMgr.AlgTypeAliases = { };", "#ApplicationMgr.AlgTypeAliases = { };")
return s
"""
helper function for postprocessing of key4hep job options
quotes need to be removed around ints, lists, dicts and bools,
and some properties that get stored by the job options svc need to be disabled
Parameters
----------
s: str
String containing key4hep joboptions (.opts format) to be sanitized.
Returns
-------
s: str
The sanitized string that should be compatible with gaudirun.py
"""
# convert s to standard string (might be a root string)
s = str(s)
s = s.replace('"False"', "False")
s = s.replace('"True"', "True")
s = s.replace('"[', "[")
s = s.replace(']"', "]")
s = s.replace('"{', "{")
s = s.replace('}"', "}")
s = re.sub(_regexp_int, r"\g<2>\g<4>", s)
s = s.replace("ApplicationMgr.Go = ", "#ApplicationMgr.Go = ")
s = s.replace("ApplicationMgr.Exit = ", "#ApplicationMgr.Exit = ")
s = s.replace("ApplicationMgr.Environment = { };", "#ApplicationMgr.Environment = { };")
s = s.replace(
"ApplicationMgr.AlgTypeAliases = { };", "#ApplicationMgr.AlgTypeAliases = { };"
)
return s


def dump_joboptions(filename):
f = ROOT.TFile.Open(filename)
t = f.metadata
for event in t:
s = event.gaudiConfigOptions
for e in s:
print(_sanitize(e))
f = ROOT.TFile.Open(filename)
t = f.metadata
for event in t:
s = event.gaudiConfigOptions
for e in s:
print(_sanitize(e))


parser = argparse.ArgumentParser(description='K4 Job Options Writer')
parser.add_argument( dest='filename', type=str, help="name of file to read")
parser = argparse.ArgumentParser(description="K4 Job Options Writer")
parser.add_argument(dest="filename", type=str, help="name of file to read")

if __name__ == "__main__":
args = parser.parse_args()
dump_joboptions(args.filename)


Loading

0 comments on commit 7ce7301

Please sign in to comment.