當前位置: 首頁>>代碼示例>>Python>>正文


Python tomlkit.aot方法代碼示例

本文整理匯總了Python中tomlkit.aot方法的典型用法代碼示例。如果您正苦於以下問題:Python tomlkit.aot方法的具體用法?Python tomlkit.aot怎麽用?Python tomlkit.aot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tomlkit的用法示例。


在下文中一共展示了tomlkit.aot方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: reorder_source_keys

# 需要導入模塊: import tomlkit [as 別名]
# 或者: from tomlkit import aot [as 別名]
def reorder_source_keys(data):
    # type: (tomlkit.toml_document.TOMLDocument) -> tomlkit.toml_document.TOMLDocument
    sources = []  # type: sources_type
    for source_key in ["source", "sources"]:
        sources.extend(data.get(source_key, tomlkit.aot()).value)
    new_source_aot = tomlkit.aot()
    for entry in sources:
        table = tomlkit.table()  # type: tomlkit.items.Table
        source_entry = PipfileLoader.populate_source(entry.copy())
        for key in ["name", "url", "verify_ssl"]:
            table.update({key: source_entry[key]})
        new_source_aot.append(table)
    data["source"] = new_source_aot
    if data.get("sources", None):
        del data["sources"]
    return data 
開發者ID:pypa,項目名稱:pipenv,代碼行數:18,代碼來源:pipfile.py

示例2: test_aot

# 需要導入模塊: import tomlkit [as 別名]
# 或者: from tomlkit import aot [as 別名]
def test_aot():
    t = tomlkit.aot()

    assert isinstance(t, AoT) 
開發者ID:sdispater,項目名稱:tomlkit,代碼行數:6,代碼來源:test_api.py

示例3: _add_repositories

# 需要導入模塊: import tomlkit [as 別名]
# 或者: from tomlkit import aot [as 別名]
def _add_repositories(section, root: RootDependency):
        # get repositories
        urls = dict()
        for repo in root.warehouses:
            if isinstance(repo, WarehouseLocalRepo):
                continue
            urls[repo.name] = repo.pretty_url

        # remove or update old repositories
        added = []
        sources = tomlkit.aot()
        if section.get('source'):
            if hasattr(section, 'item'):
                old_sources = section.item('source')
            else:
                old_sources = section['source']
            for source in old_sources:
                if source['name'] in urls:
                    if source['url'] != urls[source['name']]:
                        source['url'] = urls[source['name']]
                    sources.append(source)
                    added.append(source['name'])

        # add new repositories
        for name, url in sorted(urls.items()):
            if name not in added:
                source = tomlkit.table()
                source['name'] = name
                source['url'] = url
                sources.append(source)

        section['source'] = sources

        # remove section if empty
        if not section['source']:
            del section['source']

    # https://github.com/sdispater/tomlkit/blob/master/pyproject.toml 
開發者ID:dephell,項目名稱:dephell,代碼行數:40,代碼來源:poetry.py

示例4: format_lockfile

# 需要導入模塊: import tomlkit [as 別名]
# 或者: from tomlkit import aot [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

示例5: dumps

# 需要導入模塊: import tomlkit [as 別名]
# 或者: from tomlkit import aot [as 別名]
def dumps(self, reqs, project: RootDependency, content=None) -> str:
        doc = tomlkit.parse(content) if content else tomlkit.document()
        doc['package'] = [self._format_req(req=req) for req in reqs]

        # add extras
        extras = defaultdict(list)
        for req in reqs:
            if req.is_main:
                for extra in req.main_envs:
                    extras[extra].append(req.name)
            if req.is_dev:
                for extra in req.dev_envs:
                    extras[extra].append(req.name)
        if extras:
            doc['extras'] = dict(extras)

        # add repositories
        sources = tomlkit.aot()
        if not project.dependencies:
            project.attach_dependencies([req.dep for req in reqs])
        for repo in project.warehouses:
            if isinstance(repo, WarehouseLocalRepo):
                continue
            source = tomlkit.table()
            source['name'] = repo.name
            source['url'] = repo.pretty_url
            sources.append(source)
        if sources:
            doc['source'] = sources

        doc['metadata'] = {
            # sha256 of tool.poetry section from pyproject.toml
            # 'content-hash': ...,
            # 'platform': '*',
            'python-versions': str(project.python),
        }

        doc['metadata']['hashes'] = tomlkit.table()
        for req in reqs:
            doc['metadata']['hashes'][req.name] = list(req.hashes or [])

        return tomlkit.dumps(doc)

    # https://github.com/sdispater/poetry/blob/master/poetry.lock 
開發者ID:dephell,項目名稱:dephell,代碼行數:46,代碼來源:poetrylock.py


注:本文中的tomlkit.aot方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。