Skip to content

Commit e133033

Browse files
authored
Format and upgrade Python (alisw#974)
* Format Python * Upgrade
1 parent 4e1da3b commit e133033

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+7055
-5519
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ repos:
2020
rev: v3.19.1
2121
hooks:
2222
- id: pyupgrade
23+
args: ["--py310-plus"]
2324
- repo: https://github.com/shellcheck-py/shellcheck-py
2425
rev: v0.10.0.1
2526
hooks:

machine_learning_hep/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#############################################################################
1414

1515
import sys
16+
1617
from machine_learning_hep.steer_analysis import main
1718

1819
sys.exit(main())

machine_learning_hep/analysis/analyzer.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@
1212
## along with this program. if not, see <https://www.gnu.org/licenses/>. ##
1313
#############################################################################
1414

15-
from os.path import exists, join
16-
from os import makedirs
1715
import os
16+
from os import makedirs
17+
from os.path import exists, join
18+
19+
from machine_learning_hep.io import dump_yaml_from_dict
1820

1921
# HF specific imports
2022
from machine_learning_hep.workflow.workflow_base import WorkflowBase
21-
from machine_learning_hep.io import dump_yaml_from_dict
23+
2224

2325
class Analyzer(WorkflowBase):
2426
def __init__(self, datap, case, typean, period):
@@ -28,15 +30,16 @@ def __init__(self, datap, case, typean, period):
2830
for mcordata in ("mc", "data"):
2931
dp = datap["analysis"][typean][mcordata]
3032
prefix_dir_res = dp.get("prefix_dir_res", "")
31-
results_dir = prefix_dir_res + os.path.expandvars(dp["results"][period]) \
32-
if period is not None \
33-
else prefix_dir_res + os.path.expandvars(dp["resultsallp"])
33+
results_dir = (
34+
prefix_dir_res + os.path.expandvars(dp["results"][period])
35+
if period is not None
36+
else prefix_dir_res + os.path.expandvars(dp["resultsallp"])
37+
)
3438
if not exists(results_dir):
3539
# create otput directories in case they do not exist
3640
makedirs(results_dir)
3741
if mcordata == "data":
38-
dump_yaml_from_dict({case: datap},
39-
join(results_dir, f"database_{case}_{typean}.yml"))
42+
dump_yaml_from_dict({case: datap}, join(results_dir, f"database_{case}_{typean}.yml"))
4043

4144

4245
class AnalyzerAfterBurner(WorkflowBase):

machine_learning_hep/analysis/analyzer_jets.py

Lines changed: 615 additions & 517 deletions
Large diffs are not rendered by default.

machine_learning_hep/analysis/analyzer_manager.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@
1212

1313
from machine_learning_hep.logger import get_logger
1414

15+
1516
# pylint: disable=too-many-instance-attributes
1617
class AnalyzerManager:
1718
"""
1819
Manager class handling analysis and systematic objects
1920
"""
2021

2122
def __init__(self, ana_class, database, case, typean, doperiodbyperiod, *args):
22-
2323
self.ana_class = ana_class
2424
self.database = database
2525
self.case = case
@@ -36,7 +36,6 @@ def __init__(self, ana_class, database, case, typean, doperiodbyperiod, *args):
3636

3737
self.is_initialized = False
3838

39-
4039
def get_analyzers(self, none_for_unused_period=True):
4140
self.initialize()
4241
if not none_for_unused_period:
@@ -50,7 +49,6 @@ def get_analyzers(self, none_for_unused_period=True):
5049
analyzers[-1] = self.analyzers[-1]
5150
return analyzers
5251

53-
5452
def initialize(self):
5553
"""
5654
Collect all analyzer objects required in a list and initialises the after_burner if present
@@ -65,10 +63,8 @@ def initialize(self):
6563

6664
for ip, period in enumerate(useperiod):
6765
if self.doperiodbyperiod and period:
68-
self.analyzers.append(self.ana_class(self.database, self.case, self.typean, ip,
69-
*self.add_args))
70-
self.analyzers.append(self.ana_class(self.database, self.case, self.typean, None,
71-
*self.add_args))
66+
self.analyzers.append(self.ana_class(self.database, self.case, self.typean, ip, *self.add_args))
67+
self.analyzers.append(self.ana_class(self.database, self.case, self.typean, None, *self.add_args))
7268

7369
if self.doperiodbyperiod:
7470
# get after-burner, if any
@@ -79,7 +75,6 @@ def initialize(self):
7975

8076
self.is_initialized = True
8177

82-
8378
def analyze(self, ana_steps):
8479
"""
8580
Gives a list of analyzers and analysis steps do each step for each analyzer
@@ -88,14 +83,16 @@ def analyze(self, ana_steps):
8883
"""
8984

9085
if not ana_steps:
91-
self.logger.info("No analysis steps to be done for Analyzer class %s. Return...",
92-
self.ana_class.__name__)
86+
self.logger.info("No analysis steps to be done for Analyzer class %s. Return...", self.ana_class.__name__)
9387
return
9488

9589
self.initialize()
9690

97-
self.logger.info("Run all registered analyzers of type %s for following analysis steps: %s",
98-
self.ana_class.__name__, ana_steps)
91+
self.logger.info(
92+
"Run all registered analyzers of type %s for following analysis steps: %s",
93+
self.ana_class.__name__,
94+
ana_steps,
95+
)
9996

10097
# Collect potentially failed systematic steps
10198
failed_steps = []

0 commit comments

Comments
 (0)