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


Python Spec.from_yaml方法代码示例

本文整理汇总了Python中spack.spec.Spec.from_yaml方法的典型用法代码示例。如果您正苦于以下问题:Python Spec.from_yaml方法的具体用法?Python Spec.from_yaml怎么用?Python Spec.from_yaml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在spack.spec.Spec的用法示例。


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

示例1: test_yaml_subdag

# 需要导入模块: from spack.spec import Spec [as 别名]
# 或者: from spack.spec.Spec import from_yaml [as 别名]
def test_yaml_subdag(config, builtin_mock):
    spec = Spec('mpileaks^mpich+debug')
    spec.concretize()
    yaml_spec = Spec.from_yaml(spec.to_yaml())

    for dep in ('callpath', 'mpich', 'dyninst', 'libdwarf', 'libelf'):
        assert spec[dep].eq_dag(yaml_spec[dep])
开发者ID:justintoo,项目名称:spack,代码行数:9,代码来源:spec_yaml.py

示例2: read_spec

# 需要导入模块: from spack.spec import Spec [as 别名]
# 或者: from spack.spec.Spec import from_yaml [as 别名]
    def read_spec(self, path):
        """Read the contents of a file and parse them as a spec"""
        with open(path) as f:
            spec = Spec.from_yaml(f)

        # Specs read from actual installations are always concrete
        spec._mark_concrete()
        return spec
开发者ID:Exteris,项目名称:spack,代码行数:10,代码来源:directory_layout.py

示例3: test_yaml_subdag

# 需要导入模块: from spack.spec import Spec [as 别名]
# 或者: from spack.spec.Spec import from_yaml [as 别名]
    def test_yaml_subdag(self):
        spec = Spec('mpileaks^mpich+debug')
        spec.concretize()

        yaml_spec = Spec.from_yaml(spec.to_yaml())

        for dep in ('callpath', 'mpich', 'dyninst', 'libdwarf', 'libelf'):
            self.assertTrue(spec[dep].eq_dag(yaml_spec[dep]))
开发者ID:Exteris,项目名称:spack,代码行数:10,代码来源:spec_yaml.py

示例4: test_read_and_write_spec

# 需要导入模块: from spack.spec import Spec [as 别名]
# 或者: from spack.spec.Spec import from_yaml [as 别名]
    def test_read_and_write_spec(self):
        """This goes through each package in spack and creates a directory for
           it.  It then ensures that the spec for the directory's
           installed package can be read back in consistently, and
           finally that the directory can be removed by the directory
           layout.
        """
        packages = list(spack.repo.all_packages())[:max_packages]

        for pkg in packages:
            if pkg.name.startswith('external'):
                #External package tests cannot be installed
                continue            
            spec = pkg.spec

            # If a spec fails to concretize, just skip it.  If it is a
            # real error, it will be caught by concretization tests.
            try:
                spec.concretize()
            except:
                continue

            self.layout.create_install_directory(spec)

            install_dir = self.layout.path_for_spec(spec)
            spec_path = self.layout.spec_file_path(spec)

            # Ensure directory has been created in right place.
            self.assertTrue(os.path.isdir(install_dir))
            self.assertTrue(install_dir.startswith(self.tmpdir))

            # Ensure spec file exists when directory is created
            self.assertTrue(os.path.isfile(spec_path))
            self.assertTrue(spec_path.startswith(install_dir))

            # Make sure spec file can be read back in to get the original spec
            spec_from_file = self.layout.read_spec(spec_path)
            self.assertEqual(spec, spec_from_file)
            self.assertTrue(spec.eq_dag, spec_from_file)
            self.assertTrue(spec_from_file.concrete)

            # Ensure that specs that come out "normal" are really normal.
            with open(spec_path) as spec_file:
                read_separately = Spec.from_yaml(spec_file.read())

                read_separately.normalize()
                self.assertEqual(read_separately, spec_from_file)

                read_separately.concretize()
                self.assertEqual(read_separately, spec_from_file)

            # Make sure the hash of the read-in spec is the same
            self.assertEqual(spec.dag_hash(), spec_from_file.dag_hash())

            # Ensure directories are properly removed
            self.layout.remove_install_directory(spec)
            self.assertFalse(os.path.isdir(install_dir))
            self.assertFalse(os.path.exists(install_dir))
开发者ID:Exteris,项目名称:spack,代码行数:60,代码来源:directory_layout.py

示例5: check_yaml_round_trip

# 需要导入模块: from spack.spec import Spec [as 别名]
# 或者: from spack.spec.Spec import from_yaml [as 别名]
def check_yaml_round_trip(spec):
    yaml_text = spec.to_yaml()
    spec_from_yaml = Spec.from_yaml(yaml_text)
    assert spec.eq_dag(spec_from_yaml)
开发者ID:justintoo,项目名称:spack,代码行数:6,代码来源:spec_yaml.py

示例6: test_ordered_read_not_required_for_consistent_dag_hash

# 需要导入模块: from spack.spec import Spec [as 别名]
# 或者: from spack.spec.Spec import from_yaml [as 别名]
def test_ordered_read_not_required_for_consistent_dag_hash(
        config, builtin_mock
):
    """Make sure ordered serialization isn't required to preserve hashes.

    For consistent hashes, we require that YAML and json documents
    have their keys serialized in a deterministic order. However, we
    don't want to require them to be serialized in order. This
    ensures that is not required.
    """
    specs = ['mpileaks ^zmpi', 'dttop', 'dtuse']
    for spec in specs:
        spec = Spec(spec)
        spec.concretize()

        #
        # Dict & corresponding YAML & JSON from the original spec.
        #
        spec_dict = spec.to_dict()
        spec_yaml = spec.to_yaml()
        spec_json = spec.to_json()

        #
        # Make a spec with reversed OrderedDicts for every
        # OrderedDict in the original.
        #
        reversed_spec_dict = reverse_all_dicts(spec.to_dict())

        #
        # Dump to YAML and JSON
        #
        yaml_string = syaml.dump(spec_dict, default_flow_style=False)
        reversed_yaml_string = syaml.dump(reversed_spec_dict,
                                          default_flow_style=False)
        json_string = sjson.dump(spec_dict)
        reversed_json_string = sjson.dump(reversed_spec_dict)

        #
        # Do many consistency checks
        #

        # spec yaml is ordered like the spec dict
        assert yaml_string == spec_yaml
        assert json_string == spec_json

        # reversed string is different from the original, so it
        # *would* generate a different hash
        assert yaml_string != reversed_yaml_string
        assert json_string != reversed_json_string

        # build specs from the "wrongly" ordered data
        round_trip_yaml_spec = Spec.from_yaml(yaml_string)
        round_trip_json_spec = Spec.from_json(json_string)
        round_trip_reversed_yaml_spec = Spec.from_yaml(
            reversed_yaml_string
        )
        round_trip_reversed_json_spec = Spec.from_yaml(
            reversed_json_string
        )

        # TODO: remove this when build deps are in provenance.
        spec = spec.copy(deps=('link', 'run'))
        # specs are equal to the original
        assert spec == round_trip_yaml_spec
        assert spec == round_trip_json_spec
        assert spec == round_trip_reversed_yaml_spec
        assert spec == round_trip_reversed_json_spec
        assert round_trip_yaml_spec == round_trip_reversed_yaml_spec
        assert round_trip_json_spec == round_trip_reversed_json_spec
        # dag_hashes are equal
        assert spec.dag_hash() == round_trip_yaml_spec.dag_hash()
        assert spec.dag_hash() == round_trip_json_spec.dag_hash()
        assert spec.dag_hash() == round_trip_reversed_yaml_spec.dag_hash()
        assert spec.dag_hash() == round_trip_reversed_json_spec.dag_hash()
开发者ID:justintoo,项目名称:spack,代码行数:76,代码来源:spec_yaml.py

示例7: test_read_and_write_spec

# 需要导入模块: from spack.spec import Spec [as 别名]
# 或者: from spack.spec.Spec import from_yaml [as 别名]
def test_read_and_write_spec(
        layout_and_dir, config, builtin_mock
):
    """This goes through each package in spack and creates a directory for
    it.  It then ensures that the spec for the directory's
    installed package can be read back in consistently, and
    finally that the directory can be removed by the directory
    layout.
    """
    layout, tmpdir = layout_and_dir
    packages = list(spack.repo.all_packages())[:max_packages]

    for pkg in packages:
        if pkg.name.startswith('external'):
            # External package tests cannot be installed
            continue
        spec = pkg.spec

        # If a spec fails to concretize, just skip it.  If it is a
        # real error, it will be caught by concretization tests.
        try:
            spec.concretize()
        except Exception:
            continue

        layout.create_install_directory(spec)

        install_dir = layout.path_for_spec(spec)
        spec_path = layout.spec_file_path(spec)

        # Ensure directory has been created in right place.
        assert os.path.isdir(install_dir)
        assert install_dir.startswith(str(tmpdir))

        # Ensure spec file exists when directory is created
        assert os.path.isfile(spec_path)
        assert spec_path.startswith(install_dir)

        # Make sure spec file can be read back in to get the original spec
        spec_from_file = layout.read_spec(spec_path)

        # currently we don't store build dependency information when
        # we write out specs to the filesystem.

        # TODO: fix this when we can concretize more loosely based on
        # TODO: what is installed. We currently omit these to
        # TODO: increase reuse of build dependencies.
        stored_deptypes = ('link', 'run')
        expected = spec.copy(deps=stored_deptypes)
        assert expected.concrete
        assert expected == spec_from_file
        assert expected.eq_dag(spec_from_file)
        assert spec_from_file.concrete

        # Ensure that specs that come out "normal" are really normal.
        with open(spec_path) as spec_file:
            read_separately = Spec.from_yaml(spec_file.read())

        # TODO: revise this when build deps are in dag_hash
        norm = read_separately.normalized().copy(deps=stored_deptypes)
        assert norm == spec_from_file
        assert norm.eq_dag(spec_from_file)

        # TODO: revise this when build deps are in dag_hash
        conc = read_separately.concretized().copy(deps=stored_deptypes)
        assert conc == spec_from_file
        assert conc.eq_dag(spec_from_file)

        assert expected.dag_hash() == spec_from_file.dag_hash()

        # Ensure directories are properly removed
        layout.remove_install_directory(spec)
        assert not os.path.isdir(install_dir)
        assert not os.path.exists(install_dir)
开发者ID:justintoo,项目名称:spack,代码行数:76,代码来源:directory_layout.py

示例8: check_yaml_round_trip

# 需要导入模块: from spack.spec import Spec [as 别名]
# 或者: from spack.spec.Spec import from_yaml [as 别名]
 def check_yaml_round_trip(self, spec):
     yaml_text = spec.to_yaml()
     spec_from_yaml = Spec.from_yaml(yaml_text)
     self.assertTrue(spec.eq_dag(spec_from_yaml))
开发者ID:Exteris,项目名称:spack,代码行数:6,代码来源:spec_yaml.py


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