本文整理汇总了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
示例2: test_aot
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import aot [as 别名]
def test_aot():
t = tomlkit.aot()
assert isinstance(t, AoT)
示例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
示例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
示例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