Skip to content
Snippets Groups Projects
Commit 0f48ba44 authored by Eduardo Rodrigues's avatar Eduardo Rodrigues Committed by Nate Grieser
Browse files

Add Flake8 linting in 2018-patches, targetting only Phys/StrippingConf for now

parent 8581e8b5
No related branches found
No related tags found
4 merge requests!1762adding D0->K3pi mode for DiCharm,!1737Revert "Merge branch 'gmeier_bd2jpsieeksdetached_b2cc' into '2018-patches'",!1733Fix 2018 tests,!1727Add Flake8 linting in 2018-patches, targetting only Phys/StrippingConf for now
###############################################################################
## (c) Copyright 2023 CERN for the benefit of the LHCb Collaboration #
################################################################################
## (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration #
## #
## This software is distributed under the terms of the GNU General Public #
## Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
......@@ -25,6 +25,15 @@ check-copyright:
default:
image: gitlab-registry.cern.ch/lhcb-core/lbdocker/centos7-build:latest
python-linting:
stage: Lint
tags:
- cvmfs
script:
- . /cvmfs/lhcb.cern.ch/lib/LbEnv.sh
# TODO: get rid of ignores and run on full directory !
- flake8 --extend-ignore E501 $(find Phys/StrippingConf/python/StrippingConf/ -name '*.py')
.setup_script_2016:
before_script:
- source /cvmfs/lhcb.cern.ch/lib/LbEnv
......
This diff is collapsed.
......@@ -18,7 +18,6 @@ __all__ = (
'StrippingConfigurableUser'
)
from GaudiConf.Configuration import *
from Configurables import LHCbConfigurableUser
......
#!/usr/bin/env python
###############################################################################
# (c) Copyright 2000-2019 CERN for the benefit of the LHCb Collaboration #
# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
......@@ -10,6 +10,8 @@
# or submit itself to any jurisdiction. #
###############################################################################
from __future__ import print_function
#
# StrippingLine
#
......@@ -112,7 +114,7 @@ def _add_to_stripping_lines_( line ) :
"""
lname = line.name()
if lname in _stripping_lines__:
raise ValueError,"Created StrippingLine with duplicate name %s" % lname
raise ValueError,"Created StrippingLine with duplicate name %s" % lname # noqa
_stripping_lines__[lname] = line
......@@ -865,8 +867,8 @@ class StrippingLine(object):
lines)
matches[expr] = linematches
if not linematches :
print 'WARNING: For line', self.name(), 'trigger requirement', \
expr, 'doesn\'t match any trigger line!'
print('WARNING: For line' + self.name() + 'trigger requirement' +
expr + 'doesn\'t match any trigger line!')
return matches
def _extract_hlt_exprs(self, code) :
......
This diff is collapsed.
###############################################################################
# (c) Copyright 2000-2019 CERN for the benefit of the LHCb Collaboration #
# (c) Copyright 2000-2023 CERN for the benefit of the LHCb Collaboration #
# #
# This software is distributed under the terms of the GNU General Public #
# Licence version 3 (GPL Version 3), copied verbatim in the file "COPYING". #
......@@ -19,17 +19,22 @@ from Gaudi.Configuration import log
def _limitCombinatoricsMaxCandidates(configurable, MaxCandidates,
MaxCombinations, force, incidentName):
'''Limit combinatorics of a configurable assuming it has MaxCandidates,
StopAtMaxCandidates, MaxCombinations, StopAtMaxCombinations and StopIncidentType attributes.'''
'''
Limit combinatorics of a configurable assuming it has MaxCandidates,
StopAtMaxCandidates, MaxCombinations, StopAtMaxCombinations
and StopIncidentType attributes.
'''
didsomething = False
if (force or not configurable.isPropertySet('MaxCandidates')) and None != MaxCandidates:
if (force or not configurable.isPropertySet('MaxCandidates')) and \
(MaxCandidates is not None):
log.debug("Forcing MaxCandidates settings for " + configurable.name())
configurable.MaxCandidates = MaxCandidates
configurable.StopAtMaxCandidates = True
didsomething = True
if (force or not configurable.isPropertySet('MaxCombinations')) and None != MaxCombinations:
log.debug("Forcing MaxCombinations settings for " + configurable.name())
if (force or not configurable.isPropertySet('MaxCombinations')) and \
(MaxCombinations is not None):
log.debug("Forcing MaxCombinations settings for " + configurable.name()) # noqa
configurable.MaxCombinations = MaxCombinations
configurable.StopAtMaxCombinations = True
didsomething = True
......@@ -38,11 +43,18 @@ def _limitCombinatoricsMaxCandidates(configurable, MaxCandidates,
return didsomething
def _limitCombinatoricsMaxParticles(configurable, MaxCandidates, force, incidentName):
'''Limit combinatorics for a configurable assuming it's got MaxParticles & StopIncidentType
attributes.'''
def _limitCombinatoricsMaxParticles(configurable,
MaxCandidates,
force,
incidentName):
'''
Limit combinatorics for a configurable
assuming it's got MaxParticles & StopIncidentType
attributes.
'''
if (force or not configurable.isPropertySet('MaxParticles')) and None != MaxCandidates:
if (force or not configurable.isPropertySet('MaxParticles')) and \
(MaxCandidates is not None):
log.debug("Forcing MaxParticles settings for " + configurable.name())
configurable.MaxParticles = MaxCandidates
configurable.StopIncidentType = incidentName
......@@ -82,9 +94,11 @@ def limitCombinatorics(configurable,
force,
incidentName='ExceedsCombinatoricsLimit'):
"""
- This function has the highest call counts. So it needs careful optimization.
- Because the action is reactive, it's best to order the case of most-probable
to the least-probable to exit the check as early as possible.
- This function has the highest call counts.
So it needs careful optimization.
- Because the action is reactive, it's best to order
the case of most-probable to the least-probable
to exit the check as early as possible.
"""
# Check the name by string is MUCH FASTER than by class.
......@@ -102,13 +116,22 @@ def limitCombinatorics(configurable,
conf, MaxCandidates, MaxCombinations, force, incidentName)
return val
if classname in ('CombineParticles', 'DaVinci__N3BodyDecays', 'DaVinci__N4BodyDecays', 'DaVinci__N5BodyDecays'):
return _limitCombinatoricsMaxCandidates(configurable, MaxCandidates, MaxCombinations, force, incidentName)
if classname in ('CombineParticles',
'DaVinci__N3BodyDecays',
'DaVinci__N4BodyDecays',
'DaVinci__N5BodyDecays'
):
return _limitCombinatoricsMaxCandidates(configurable,
MaxCandidates,
MaxCombinations,
force,
incidentName)
if classname == 'StrippingAlg':
val = False
stages = ['Filter1']
for conf in [getattr(configurable, stage) for stage in stages if hasattr(configurable, stage)]:
for conf in [getattr(configurable, stage)
for stage in stages if hasattr(configurable, stage)]:
val |= limitCombinatorics(
conf, MaxCandidates, MaxCombinations, force, incidentName)
if val:
......@@ -116,15 +139,28 @@ def limitCombinatorics(configurable,
return val
if classname in ('SubPIDMMFilter', 'SubstitutePID'):
return _limitCombinatoricsMaxParticles(configurable, MaxCandidates, force, incidentName)
return _limitCombinatoricsMaxParticles(configurable,
MaxCandidates,
force,
incidentName)
# Generic handling (slow)
if hasattr(type(configurable), 'StopAtMaxCandidates') and hasattr(type(configurable), 'MaxCandidates') and \
hasattr(type(configurable), 'StopAtMaxCombinations') and hasattr(type(configurable), 'MaxCombinations'):
return _limitCombinatoricsMaxCandidates(configurable, MaxCandidates, MaxCombinations, force, incidentName)
if hasattr(configurable, 'MaxParticles') and hasattr(configurable, 'StopIncidentType'):
return _limitCombinatoricsMaxParticles(configurable, MaxCandidates, force, incidentName)
if hasattr(type(configurable), 'StopAtMaxCandidates') and \
hasattr(type(configurable), 'MaxCandidates') and \
hasattr(type(configurable), 'StopAtMaxCombinations') and \
hasattr(type(configurable), 'MaxCombinations'):
return _limitCombinatoricsMaxCandidates(configurable,
MaxCandidates,
MaxCombinations,
force,
incidentName)
if (hasattr(configurable, 'MaxParticles') and
hasattr(configurable, 'StopIncidentType')):
return _limitCombinatoricsMaxParticles(configurable,
MaxCandidates,
force,
incidentName)
# Generic handling (slow)
if hasattr(configurable, 'Members'):
......@@ -135,5 +171,4 @@ def limitCombinatorics(configurable,
i, MaxCandidates, MaxCombinations, force, incidentName)
return val
# log.warning('Not able to set MaxCandidates and MaxCombinations to algorithm '+str(type(configurable))+'/'+configurable.name())
return False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment