本文整理汇总了Python中tomlkit.table方法的典型用法代码示例。如果您正苦于以下问题:Python tomlkit.table方法的具体用法?Python tomlkit.table怎么用?Python tomlkit.table使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tomlkit
的用法示例。
在下文中一共展示了tomlkit.table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _format_req
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import 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
示例2: _format_req
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import 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
示例3: reorder_source_keys
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import table [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
示例4: ensure_package_sections
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import table [as 别名]
def ensure_package_sections(cls, data):
# type: (tomlkit.toml_document.TOMLDocument[Text, Any]) -> tomlkit.toml_document.TOMLDocument[Text, Any]
"""
Ensure that all pipfile package sections are present in the given toml document
:param :class:`~tomlkit.toml_document.TOMLDocument` data: The toml document to
ensure package sections are present on
:return: The updated toml document, ensuring ``packages`` and ``dev-packages``
sections are present
:rtype: :class:`~tomlkit.toml_document.TOMLDocument`
"""
package_keys = (
k for k in plette.pipfiles.PIPFILE_SECTIONS.keys() if k.endswith("packages")
)
for key in package_keys:
if key not in data:
data.update({key: tomlkit.table()})
return data
示例5: add_line_to_pipfile
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import 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
示例6: test_table
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import table [as 别名]
def test_table():
t = tomlkit.table()
assert isinstance(t, Table)
示例7: _make_env
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import 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
示例8: _format_req
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import table [as 别名]
def _format_req(self, req: Requirement) -> Table:
result = tomlkit.table()
for name, value in req:
if name in self.fields:
if isinstance(value, tuple):
value = list(value)
result[name] = value
result['category'] = 'dev' if req.is_dev else 'main'
if 'version' not in result:
result['version'] = '*'
result['version'] = result['version'].lstrip('=')
if req.markers:
result['marker'] = req.markers
# add link
if req.link and (req.git or isinstance(req.link, DirLink)):
result['source'] = tomlkit.table()
if req.git:
result['source']['type'] = 'git'
elif isinstance(req.link, DirLink):
result['source']['type'] = 'directory'
result['source']['url'] = req.link.short
if req.rev:
result['source']['reference'] = req.rev
elif isinstance(req.dep.repo, WarehouseBaseRepo):
repo = req.dep.repo.repos[0]
result['source'] = tomlkit.table()
result['source']['type'] = 'legacy'
result['source']['url'] = repo.pretty_url
result['source']['reference'] = repo.name
# add dependencies
deps = req.dep.dependencies
if deps:
result['dependencies'] = tomlkit.table()
for dep in deps:
result['dependencies'][dep.raw_name] = str(dep.constraint) or '*'
return result
示例9: _add_repositories
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import table [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
示例10: set_lock_data
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import 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
示例11: generate_poetry_content
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import table [as 别名]
def generate_poetry_content(self):
template = POETRY_DEFAULT
if self._license:
template = POETRY_WITH_LICENSE
content = loads(template)
poetry_content = content["tool"]["poetry"]
poetry_content["name"] = self._project
poetry_content["version"] = self._version
poetry_content["description"] = self._description
poetry_content["authors"].append(self._author)
if self._license:
poetry_content["license"] = self._license
poetry_content["dependencies"]["python"] = self._python
for dep_name, dep_constraint in self._dependencies.items():
poetry_content["dependencies"][dep_name] = dep_constraint
for dep_name, dep_constraint in self._dev_dependencies.items():
poetry_content["dev-dependencies"][dep_name] = dep_constraint
# Add build system
build_system = table()
build_system_version = ">=" + BUILD_SYSTEM_MIN_VERSION
if BUILD_SYSTEM_MAX_VERSION is not None:
build_system_version += ",<" + BUILD_SYSTEM_MAX_VERSION
build_system.add("requires", ["poetry" + build_system_version])
build_system.add("build-backend", "poetry.masonry.api")
content.add("build-system", build_system)
return dumps(content)
示例12: add_property
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import table [as 别名]
def add_property(self, key, value): # type: (str, Any) -> None
with self.secure() as config:
keys = key.split(".")
for i, key in enumerate(keys):
if key not in config and i < len(keys) - 1:
config[key] = table()
if i == len(keys) - 1:
config[key] = value
break
config = config[key]
示例13: add_dependencies
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import 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)
示例14: do_init
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import table [as 别名]
def do_init(
project: Project,
name: str = "",
version: str = "",
license: str = "MIT",
author: str = "",
email: str = "",
python_requires: str = "",
) -> None:
"""Bootstrap the project and create a pyproject.toml"""
data = {
"tool": {
"pdm": {
"name": name,
"version": version,
"description": "",
"author": f"{author} <{email}>",
"license": license,
"homepage": "",
"dependencies": tomlkit.table(),
"dev-dependencies": tomlkit.table(),
}
},
"build-system": {"requires": ["pdm"], "build-backend": "pdm.builders.api"},
}
if python_requires and python_requires != "*":
get_specifier(python_requires)
data["tool"]["pdm"]["python_requires"] = python_requires
if not project.pyproject:
project._pyproject = data
else:
project._pyproject.setdefault("tool", {})["pdm"] = data["tool"]["pdm"]
project._pyproject["build-system"] = data["build-system"]
project.write_pyproject()
project.environment.write_site_py()
示例15: format_lockfile
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import 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