当前位置: 首页>>代码示例>>Python>>正文


Python version.OrderedVersionOperators类代码示例

本文整理汇总了Python中easybuild.framework.easyconfig.format.version.OrderedVersionOperators的典型用法代码示例。如果您正苦于以下问题:Python OrderedVersionOperators类的具体用法?Python OrderedVersionOperators怎么用?Python OrderedVersionOperators使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OrderedVersionOperators类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _squash_versop

    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
开发者ID:akesandgren,项目名称:easybuild-framework,代码行数:50,代码来源:format.py

示例2: __init__

    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 = {}
开发者ID:akesandgren,项目名称:easybuild-framework,代码行数:9,代码来源:format.py

示例3: __init__

    def __init__(self, configobj=None):
        """
        Initialise EBConfigObj instance
        @param configobj: ConfigObj instance
        """
        self.log = fancylogger.getLogger(self.__class__.__name__, fname=False)

        self.tcname = None

        self.default = {}  # default section
        self.supported = {}  # supported section
        self.sections = {}  # all other sections
        self.unfiltered_sections = {}  # unfiltered other sections

        self.versops = OrderedVersionOperators()
        self.tcversops = OrderedVersionOperators()

        if configobj is not None:
            self.parse(configobj)
开发者ID:ebirn,项目名称:easybuild-framework,代码行数:19,代码来源:format.py

示例4: Squashed

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
开发者ID:akesandgren,项目名称:easybuild-framework,代码行数:51,代码来源:format.py

示例5: test_ordered_versop_add_data

    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)
开发者ID:Caylo,项目名称:easybuild-framework,代码行数:48,代码来源:easyconfigversion.py

示例6: test_ordered_versop_expressions

    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])
开发者ID:Caylo,项目名称:easybuild-framework,代码行数:32,代码来源:easyconfigversion.py

示例7: EBConfigObj

class EBConfigObj(object):
    """
    Enhanced ConfigObj, version/toolchain and other easyconfig specific aspects aware

    Given ConfigObj instance, make instance that represents a parser

    Mandatory/minimal (to mimic v1.0 behaviour); first version/toolchain is the default
    [SUPPORTED]
    versions=version_operator
    toolchains=toolchain_version_operator

    Optional
    [DEFAULT]
    ...
    [<operatorX> <versionX>]
    ...
    [<toolchainA> <operatorA> <versionA>]
    [[<operatorY> <versionY>]]
    ...
    ...
    """
    SECTION_MARKER_DEFAULT = 'DEFAULT'
    SECTION_MARKER_DEPENDENCIES = 'DEPENDENCIES'
    SECTION_MARKER_SUPPORTED = 'SUPPORTED'
    # list of known marker types (except default)
    KNOWN_VERSION_MARKER_TYPES = [ToolchainVersionOperator, VersionOperator]  # order matters, see parse_sections
    VERSION_OPERATOR_VALUE_TYPES = {
        # toolchains: comma-separated list of toolchain version operators
        'toolchains': ToolchainVersionOperator,
        # versions: comma-separated list of version operators
        'versions': VersionOperator,
    }

    def __init__(self, configobj=None):
        """
        Initialise EBConfigObj instance
        @param configobj: ConfigObj instance
        """
        self.log = fancylogger.getLogger(self.__class__.__name__, fname=False)

        self.tcname = None

        self.default = {}  # default section
        self.supported = {}  # supported section
        self.sections = {}  # all other sections
        self.unfiltered_sections = {}  # unfiltered other sections

        self.versops = OrderedVersionOperators()
        self.tcversops = OrderedVersionOperators()

        if configobj is not None:
            self.parse(configobj)

    def parse_sections(self, configobj, toparse=None, parent=None, depth=0):
        """
        Parse configobj instance; convert all supported sections, keys and values to their respective representations

        Returns a dict of (nested) Sections

        @param configobj: a ConfigObj instance, basically a dict of (unparsed) sections
        """
        # note: configobj already converts comma-separated strings in lists
        #
        # list of supported keywords, all else will fail
        special_keys = self.VERSION_OPERATOR_VALUE_TYPES.keys()
        if parent is None:
            # no parent, so top sections
            parsed = {}
        else:
            # parent specified, so not a top section
            parsed = Section(parent=parent, depth=depth + 1, main=configobj)

        # start with full configobj initially, and then process subsections recursively
        if toparse is None:
            toparse = configobj

        for key, value in toparse.items():
            if isinstance(value, Section):
                self.log.debug("Enter subsection key %s value %s" % (key, value))
                # only supported types of section keys are:
                # * DEFAULT
                # * SUPPORTED
                # * dependencies
                # * VersionOperator or ToolchainVersionOperator (e.g. [> 2.0], [goolf > 1])
                if key in [self.SECTION_MARKER_DEFAULT, self.SECTION_MARKER_SUPPORTED]:
                    # parse value as a section, recursively
                    new_value = self.parse_sections(configobj, toparse=value, parent=value.parent, depth=value.depth)
                    self.log.debug('Converted %s section to new value %s' % (key, new_value))
                    parsed[key] = new_value

                elif key == self.SECTION_MARKER_DEPENDENCIES:
                    new_key = 'dependencies'
                    new_value = []
                    for dep_name, dep_val in value.items():
                        if isinstance(dep_val, Section):
                            self.log.error("Unsupported nested section '%s' found in dependencies section" % dep_name)
                        else:
                            # FIXME: parse the dependency specification for version, toolchain, suffix, etc.
                            dep = Dependency(dep_val, name=dep_name)
                            if dep.name() is None or dep.version() is None:
#.........这里部分代码省略.........
开发者ID:ebirn,项目名称:easybuild-framework,代码行数:101,代码来源:format.py


注:本文中的easybuild.framework.easyconfig.format.version.OrderedVersionOperators类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。