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


Python tomlkit.inline_table方法代码示例

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


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

示例1: _format_req

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def _format_req(self, req: Requirement) -> Union[InlineTable, String]:
        result = tomlkit.inline_table()
        for name, value in req:
            if name == 'rev':
                name = 'ref'
            if name in self.fields:
                if isinstance(value, tuple):
                    value = list(value)
                result[name] = value
        if isinstance(req.dep.repo, WarehouseBaseRepo) and req.dep.repo.name != 'pypi':
            result['index'] = req.dep.repo.name
        if 'version' not in result:
            result['version'] = '*'
        # if we have only version, return string instead of table
        if tuple(result.value) == ('version', ):
            return result['version']
        # do not specify version explicit
        if result['version'] == '*':
            del result['version']

        return result 
开发者ID:dephell,项目名称:dephell,代码行数:23,代码来源:pipfile.py

示例2: _format_req

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def _format_req(self, req: Requirement) -> Union[InlineTable, String]:
        result = tomlkit.inline_table()
        for name, value in req:
            if name in self.fields:
                if isinstance(value, tuple):
                    value = list(value)
                result[name] = value
        if req.prereleases:
            result['allows-prereleases'] = True
        if 'version' not in result and 'git' not in result:
            result['version'] = '*'
        # if we have only version, return string instead of table
        if tuple(result.value) == ('version', ):
            return result['version']

        return result 
开发者ID:dephell,项目名称:dephell,代码行数:18,代码来源:poetry.py

示例3: _format_requirements

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def _format_requirements(
        self, requirements
    ):  # type: (List[Dict[str, str]]) -> Dict[str, Union[str, Dict[str, str]]]
        requires = {}
        for requirement in requirements:
            name = requirement.pop("name")
            if "version" in requirement and len(requirement) == 1:
                constraint = requirement["version"]
            else:
                constraint = inline_table()
                constraint.trivia.trail = "\n"
                constraint.update(requirement)

            requires[name] = constraint

        return requires 
开发者ID:python-poetry,项目名称:poetry,代码行数:18,代码来源:init.py

示例4: add_line_to_pipfile

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def add_line_to_pipfile(self, line, develop):
        from requirementslib import Requirement

        requirement = Requirement.from_line(line)
        section = self._get_pipfile_section(develop=develop)
        key = requirement.normalized_name
        entry = next(iter(requirement.as_pipfile().values()))
        if isinstance(entry, dict):
            # HACK: TOMLKit prefers to expand tables by default, but we
            # always want inline tables here. Also tomlkit.inline_table
            # does not have `update()`.
            table = tomlkit.inline_table()
            for k, v in entry.items():
                table[k] = v
            entry = table
        section[key] = entry 
开发者ID:pypa,项目名称:pipenv,代码行数:18,代码来源:project.py

示例5: test_getting_inline_table_is_still_an_inline_table

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def test_getting_inline_table_is_still_an_inline_table():
    content = """\
[tool.poetry]
name = "foo"

[tool.poetry.dependencies]

[tool.poetry.dev-dependencies]
"""

    doc = parse(content)
    poetry_section = doc["tool"]["poetry"]
    dependencies = poetry_section["dependencies"]
    dependencies["foo"] = tomlkit.inline_table()
    dependencies["foo"]["version"] = "^2.0"
    dependencies["foo"]["source"] = "local"
    dependencies["bar"] = tomlkit.inline_table()
    dependencies["bar"]["version"] = "^3.0"
    dependencies["bar"]["source"] = "remote"
    dev_dependencies = poetry_section["dev-dependencies"]
    dev_dependencies["baz"] = tomlkit.inline_table()
    dev_dependencies["baz"]["version"] = "^4.0"
    dev_dependencies["baz"]["source"] = "other"

    assert (
        """\
[tool.poetry]
name = "foo"

[tool.poetry.dependencies]
foo = {version = "^2.0", source = "local"}
bar = {version = "^3.0", source = "remote"}

[tool.poetry.dev-dependencies]
baz = {version = "^4.0", source = "other"}
"""
        == doc.as_string()
    ) 
开发者ID:sdispater,项目名称:tomlkit,代码行数:40,代码来源:test_toml_document.py

示例6: test_inline_table

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def test_inline_table():
    t = tomlkit.inline_table()

    assert isinstance(t, InlineTable) 
开发者ID:sdispater,项目名称:tomlkit,代码行数:6,代码来源:test_api.py

示例7: test_trim_comments_when_building_inline_table

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def test_trim_comments_when_building_inline_table():
    table = inline_table()
    row = parse('foo = "bar"  # Comment')
    table.update(row)
    assert table.as_string() == '{foo = "bar"}'
    value = item("foobaz")
    value.comment("Another comment")
    table.append("baz", value)
    assert "# Another comment" not in table.as_string()
    assert '{foo = "bar", baz = "foobaz"}' == table.as_string() 
开发者ID:sdispater,项目名称:tomlkit,代码行数:12,代码来源:test_items.py

示例8: _make_env

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def _make_env(from_format: str, from_path: str, to_format: str, to_path: str) -> Table:
        table = tomlkit.table()

        table['from'] = tomlkit.inline_table()
        table['from']['format'] = from_format
        table['from']['path'] = from_path

        table['to'] = tomlkit.inline_table()
        table['to']['format'] = to_format
        table['to']['path'] = to_path

        return table 
开发者ID:dephell,项目名称:dephell,代码行数:14,代码来源:generate_config.py

示例9: set_lock_data

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def set_lock_data(self, root, packages):  # type: (...) -> bool
        files = table()
        packages = self._lock_packages(packages)
        # Retrieving hashes
        for package in packages:
            if package["name"] not in files:
                files[package["name"]] = []

            for f in package["files"]:
                file_metadata = inline_table()
                for k, v in sorted(f.items()):
                    file_metadata[k] = v

                files[package["name"]].append(file_metadata)

            if files[package["name"]]:
                files[package["name"]] = item(files[package["name"]]).multiline(True)

            del package["files"]

        lock = document()
        lock["package"] = packages

        if root.extras:
            lock["extras"] = {
                extra: [dep.pretty_name for dep in deps]
                for extra, deps in root.extras.items()
            }

        lock["metadata"] = {
            "python-versions": root.python_versions,
            "content-hash": self._content_hash,
            "files": files,
        }

        if not self.is_locked() or lock != self.lock_data:
            self._write_lock_data(lock)

            return True

        return False 
开发者ID:python-poetry,项目名称:poetry,代码行数:43,代码来源:locker.py

示例10: add_dependencies

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def add_dependencies(
        self, requirements: Dict[str, Requirement], show_message: bool = True
    ) -> None:
        for name, dep in requirements.items():
            if dep.from_section == "default":
                deps = self.tool_settings["dependencies"]
            elif dep.from_section == "dev":
                deps = self.tool_settings["dev-dependencies"]
            else:
                section = f"{dep.from_section}-dependencies"
                if section not in self.tool_settings:
                    self.tool_settings[section] = tomlkit.table()
                deps = self.tool_settings[section]

            matched_name = next(
                filter(
                    lambda k: strip_extras(name)[0] == safe_name(k).lower(), deps.keys()
                ),
                None,
            )
            name_to_save = dep.name if matched_name is None else matched_name
            _, req_dict = dep.as_req_dict()
            if isinstance(req_dict, dict):
                req = tomlkit.inline_table()
                req.update(req_dict)
                req_dict = req
            deps[name_to_save] = req_dict
        self.write_pyproject(show_message) 
开发者ID:frostming,项目名称:pdm,代码行数:30,代码来源:core.py

示例11: format_lockfile

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def format_lockfile(mapping, fetched_dependencies, summary_collection):
    """Format lock file from a dict of resolved candidates, a mapping of dependencies
    and a collection of package summaries.
    """
    packages = tomlkit.aot()
    metadata = tomlkit.table()
    for k, v in sorted(mapping.items()):
        base = tomlkit.table()
        base.update(v.as_lockfile_entry())
        base.add("summary", summary_collection[strip_extras(k)[0]])
        deps = tomlkit.table()
        for r in fetched_dependencies[k].values():
            name, req = r.as_req_dict()
            if getattr(req, "items", None) is not None:
                inline = tomlkit.inline_table()
                inline.update(req)
                deps.add(name, inline)
            else:
                deps.add(name, req)
        if len(deps) > 0:
            base.add("dependencies", deps)
        packages.append(base)
        if v.hashes:
            key = f"{k} {v.version}"
            array = tomlkit.array()
            array.multiline(True)
            for filename, hash_value in v.hashes.items():
                inline = tomlkit.inline_table()
                inline.update({"file": filename, "hash": hash_value})
                array.append(inline)
            if array:
                metadata.add(key, array)
    doc = tomlkit.document()
    doc.update({"package": packages, "metadata": metadata})
    return doc 
开发者ID:frostming,项目名称:pdm,代码行数:37,代码来源:utils.py

示例12: format_toml

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def format_toml(pdm_settings):
    """Ensure the dependencies are inline tables"""
    for section in pdm_settings:
        if not section.endswith("dependencies"):
            continue
        for name in pdm_settings[section]:
            if getattr(pdm_settings[section][name], "items", None):
                table = tomlkit.inline_table()
                table.update(pdm_settings[section][name])
                pdm_settings[section][name] = table 
开发者ID:frostming,项目名称:pdm,代码行数:12,代码来源:utils.py

示例13: convert_toml_outline_tables

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def convert_toml_outline_tables(parsed):
    """Converts all outline tables to inline tables."""
    def convert_tomlkit_table(section):
        if isinstance(section, tomlkit.items.Table):
            body = section.value._body
        else:
            body = section._body
        for key, value in body:
            if not key:
                continue
            if hasattr(value, "keys") and not isinstance(value, tomlkit.items.InlineTable):
                table = tomlkit.inline_table()
                table.update(value.value)
                section[key.key] = table

    def convert_toml_table(section):
        for package, value in section.items():
            if hasattr(value, "keys") and not isinstance(value, toml.decoder.InlineTableDict):
                table = toml.TomlDecoder().get_empty_inline_table()
                table.update(value)
                section[package] = table

    is_tomlkit_parsed = isinstance(parsed, tomlkit.container.Container)
    for section in ("packages", "dev-packages"):
        table_data = parsed.get(section, {})
        if not table_data:
            continue
        if is_tomlkit_parsed:
            convert_tomlkit_table(table_data)
        else:
            convert_toml_table(table_data)

    return parsed 
开发者ID:pypa,项目名称:pipenv,代码行数:35,代码来源:utils.py

示例14: write_toml

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def write_toml(self, data, path=None):
        """Writes the given data structure out as TOML."""
        if path is None:
            path = self.pipfile_location
        data = convert_toml_outline_tables(data)
        try:
            formatted_data = tomlkit.dumps(data).rstrip()
        except Exception:
            document = tomlkit.document()
            for section in ("packages", "dev-packages"):
                document[section] = tomlkit.table()
                # Convert things to inline tables — fancy :)
                for package in data.get(section, {}):
                    if hasattr(data[section][package], "keys"):
                        table = tomlkit.inline_table()
                        table.update(data[section][package])
                        document[section][package] = table
                    else:
                        document[section][package] = tomlkit.string(data[section][package])
            formatted_data = tomlkit.dumps(document).rstrip()

        if (
            vistir.compat.Path(path).absolute()
            == vistir.compat.Path(self.pipfile_location).absolute()
        ):
            newlines = self._pipfile_newlines
        else:
            newlines = DEFAULT_NEWLINES
        formatted_data = cleanup_toml(formatted_data)
        with io.open(path, "w", newline=newlines) as f:
            f.write(formatted_data)
        # pipfile is mutated!
        self.clear_pipfile_cache() 
开发者ID:pypa,项目名称:pipenv,代码行数:35,代码来源:project.py

示例15: add_line_to_pipfile

# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import inline_table [as 别名]
def add_line_to_pipfile(self, line, develop):
        from requirementslib import Requirement
        requirement = Requirement.from_line(line)
        section = self._get_pipfile_section(develop=develop)
        key = requirement.normalized_name
        entry = next(iter(requirement.as_pipfile().values()))
        if isinstance(entry, dict):
            # HACK: TOMLKit prefers to expand tables by default, but we
            # always want inline tables here. Also tomlkit.inline_table
            # does not have `update()`.
            table = tomlkit.inline_table()
            for k, v in entry.items():
                table[k] = v
            entry = table
        section[key] = entry 
开发者ID:pypa,项目名称:pipenv,代码行数:17,代码来源:projects.py


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