本文整理汇总了Python中easybuild.framework.easyconfig.format.version.OrderedVersionOperators.add方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedVersionOperators.add方法的具体用法?Python OrderedVersionOperators.add怎么用?Python OrderedVersionOperators.add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类easybuild.framework.easyconfig.format.version.OrderedVersionOperators
的用法示例。
在下文中一共展示了OrderedVersionOperators.add方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ordered_versop_expressions
# 需要导入模块: from easybuild.framework.easyconfig.format.version import OrderedVersionOperators [as 别名]
# 或者: from easybuild.framework.easyconfig.format.version.OrderedVersionOperators import add [as 别名]
def test_ordered_versop_expressions(self):
"""Given set of ranges, order them according to version/operator (most recent/specific first)"""
# simple version ordering, all different versions
ovop = OrderedVersionOperators()
versop_exprs = [
'> 3.0.0',
'>= 2.5.0',
'> 2.0.0',
'== 1.0.0',
]
# add version expressions out of order intentionally
ovop.add(versop_exprs[1])
ovop.add(versop_exprs[-1])
ovop.add(versop_exprs[0])
ovop.add(versop_exprs[2])
# verify whether order is what we expect it to be
self.assertEqual(ovop.versops, [VersionOperator(x) for x in versop_exprs])
# more complex version ordering, identical/overlapping vesions
ovop = OrderedVersionOperators()
versop_exprs = [
'== 1.0.0',
'> 1.0.0',
'< 1.0.0',
]
# add version expressions out of order intentionally
ovop.add(versop_exprs[-1])
ovop.add(versop_exprs[1])
ovop.add(versop_exprs[0])
# verify whether order is what we expect it to be
self.assertEqual(ovop.versops, [VersionOperator(x) for x in versop_exprs])
示例2: _squash_versop
# 需要导入模块: from easybuild.framework.easyconfig.format.version import OrderedVersionOperators [as 别名]
# 或者: from easybuild.framework.easyconfig.format.version.OrderedVersionOperators import add [as 别名]
def _squash_versop(self, key, value, squashed, sanity, vt_tuple):
"""
Squash VERSION_OPERATOR_VALUE_TYPES value
return None or new Squashed instance
:param key: section key
:param nested_dict: the nested_dict instance
:param squashed: Squashed instance
:param sanity: the sanity dict
:param vt_tuple: version, tc_name, tc_version tuple
"""
version, tcname, tcversion = vt_tuple
if key == 'toolchains':
# remove any other toolchain from list
self.log.debug("Filtering 'toolchains' key")
matching_toolchains = []
tmp_tc_oversops = {} # temporary, only for conflict checking
for tcversop in value:
tc_overops = tmp_tc_oversops.setdefault(tcversop.tc_name, OrderedVersionOperators())
self.log.debug("Add tcversop %s to tc_overops %s tcname %s tcversion %s",
tcversop, tc_overops, tcname, tcversion)
tc_overops.add(tcversop) # test non-conflicting list
if tcversop.test(tcname, tcversion):
matching_toolchains.append(tcversop)
if matching_toolchains:
# does this have any use?
self.log.debug('Matching toolchains %s found (but data not needed)' % matching_toolchains)
else:
self.log.debug('No matching toolchains, removing the whole current key %s' % key)
return Squashed()
elif key == 'versions':
self.log.debug("Adding all versions %s from versions key" % value)
matching_versions = []
tmp_versops = OrderedVersionOperators() # temporary, only for conflict checking
for versop in value:
tmp_versops.add(versop) # test non-conflicting list
if versop.test(version):
matching_versions.append(versop)
if matching_versions:
# does this have any use?
self.log.debug('Matching versions %s found (but data not needed)' % matching_versions)
else:
self.log.debug('No matching versions, removing the whole current key %s' % key)
return Squashed()
else:
raise EasyBuildError('Unexpected VERSION_OPERATOR_VALUE_TYPES key %s value %s', key, value)
return None
示例3: test_ordered_versop_add_data
# 需要导入模块: from easybuild.framework.easyconfig.format.version import OrderedVersionOperators [as 别名]
# 或者: from easybuild.framework.easyconfig.format.version.OrderedVersionOperators import add [as 别名]
def test_ordered_versop_add_data(self):
"""Test the add and data handling"""
ovop = OrderedVersionOperators()
tests = [
('> 1', '5'),
('> 2', {'x': 3}),
]
for versop_txt, data in tests:
versop = VersionOperator(versop_txt)
ovop.add(versop)
# no data was added, this is a new entry, mapper is initialised with None
self.assertEqual(ovop.get_data(versop), None)
ovop.add(versop, data)
# test data
self.assertEqual(ovop.get_data(versop), data)
# new data for same versops
tests = [
('> 1', '6'),
('> 2', {'x': 4}),
]
for versop_txt, data in tests:
versop = VersionOperator(versop_txt)
ovop.add(versop, data)
# test updated data
self.assertEqual(ovop.get_data(versop), data)
# 'update' a value
# the data for '> 1' has no .update()
extra_data = {'y': 4}
tests = [
('> 2', extra_data),
]
for versop_txt, data in tests:
versop = VersionOperator(versop_txt)
prevdata = copy.deepcopy(ovop.get_data(versop))
prevdata.update(extra_data)
ovop.add(versop, data, update=True)
# test updated data
self.assertEqual(ovop.get_data(versop), prevdata)
# use update=True on new element
versop = VersionOperator('> 10000')
new_data = {'new': 5}
ovop.add(versop, new_data, update=True)
# test updated data
self.assertEqual(ovop.get_data(versop), new_data)
示例4: Squashed
# 需要导入模块: from easybuild.framework.easyconfig.format.version import OrderedVersionOperators [as 别名]
# 或者: from easybuild.framework.easyconfig.format.version.OrderedVersionOperators import add [as 别名]
class Squashed(object):
"""Class to ease the squashing of OrderedVersionOperators and OrderedToolchainVersionOperators"""
def __init__(self):
"""Initialise Squashed instance"""
self.log = fancylogger.getLogger(self.__class__.__name__, fname=False)
# OrderedVersionOperators instances to keep track of the data of the matching
# version and toolchain version sections
self.versions = OrderedVersionOperators()
self.tcversions = OrderedVersionOperators()
self.result = {}
def add_toolchain(self, squashed):
"""
Add squashed instance from a toolchain section
:param squashed: a Squashed instance
"""
# TODO unify with add_version, make one .add()
# data from toolchain
self.result.update(squashed.result)
for versop in squashed.versions.versops:
self.versions.add(versop, squashed.versions.get_data(versop), update=True)
def add_version(self, section, squashed):
"""
Add squashed instance from version section
:param section: the version section versionoperator instance
:param squashed: a Squashed instance
"""
# TODO unify with add_toolchain, make one .add()
# don't update res_sections
# add this to a orderedversop that has matching versops.
# data in this matching orderedversop must be updated to the res at the end
for versop in squashed.versions.versops:
self.versions.add(versop, squashed.versions.get_data(versop), update=True)
self.versions.add(section, squashed.result, update=True)
def final(self):
"""Final squashing of version and toolchainversion operators and return the result"""
self.log.debug('Pre-final result %s' % self.result)
self.log.debug('Pre-final versions %s with data %s' % (self.versions, self.versions.datamap))
self.log.debug('Pre-final tcversions %s with data %s' % (self.tcversions, self.tcversions.datamap))
# update self.result, most strict matching versionoperator should be first element
# so update in reversed order
# also update toolchain data before version data
for vers in [self.tcversions, self.versions]:
for versop in vers.versops[::-1]:
self.result.update(vers.get_data(versop))
return self.result
示例5: EBConfigObj
# 需要导入模块: from easybuild.framework.easyconfig.format.version import OrderedVersionOperators [as 别名]
# 或者: from easybuild.framework.easyconfig.format.version.OrderedVersionOperators import add [as 别名]
#.........这里部分代码省略.........
tup = (key, value, type(value))
self.log.error('Bug: supported but unknown key %s with non-string value: %s, type %s' % tup)
self.log.debug("Converted value '%s' for key '%s' into new value '%s'" % (value, key, new_value))
parsed[key] = new_value
return parsed
def validate_and_filter_by_toolchain(self, tcname, processed=None, filtered_sections=None, other_sections=None):
"""
Build the ordered version operator and toolchain version operator, ignoring all other toolchains
@param tcname: toolchain name to keep
@param processed: a processed dict of sections to filter
@param path: list of keys to identify the path in the dict
"""
top_call = False
if processed is None:
processed = self.sections
top_call = True
if filtered_sections is None:
filtered_sections = {}
if other_sections is None:
other_sections = {}
# walk over dictionary of parsed sections, and check for marker conflicts (using .add())
# add section markers relevant to specified toolchain to self.tcversops
for key, value in processed.items():
if isinstance(value, Section):
if isinstance(key, ToolchainVersionOperator):
if not key.tc_name == tcname:
self.log.debug("Found marker for other toolchain '%s'" % key.tc_name)
# also perform sanity check for other toolchains, make add check for conflicts
tc_overops = other_sections.setdefault(key.tc_name, OrderedVersionOperators())
tc_overops.add(key)
# nothing more to do here, just continue with other sections
continue
else:
self.log.debug("Found marker for specified toolchain '%s': %s" % (tcname, key))
# add marker to self.tcversops (which triggers a conflict check)
self.tcversops.add(key, value)
filtered_sections[key] = value
elif isinstance(key, VersionOperator):
self.log.debug("Found marker for version '%s'" % key)
# keep track of all version operators, and enforce conflict check
self.versops.add(key, value)
filtered_sections[key] = value
else:
self.log.error("Unhandled section marker '%s' (type '%s')" % (key, type(key)))
# recursively go deeper for (relevant) sections
self.validate_and_filter_by_toolchain(tcname, processed=value, filtered_sections=filtered_sections,
other_sections=other_sections)
elif key in self.VERSION_OPERATOR_VALUE_TYPES:
self.log.debug("Found version operator key-value entry (%s)" % key)
if key == 'toolchains':
# remove any other toolchain from list
filtered_sections[key] = [tcversop for tcversop in value if tcversop.tc_name == tcname]
else:
# retain all other values
filtered_sections[key] = value
else:
self.log.debug("Found non-special key-value entry (key %s), skipping it" % key)
if top_call:
self.unfiltered_sections = self.sections