本文整理汇总了Python中tomlkit.loads方法的典型用法代码示例。如果您正苦于以下问题:Python tomlkit.loads方法的具体用法?Python tomlkit.loads怎么用?Python tomlkit.loads使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tomlkit
的用法示例。
在下文中一共展示了tomlkit.loads方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def load(cls, f, encoding=None):
# type: (Any, Text) -> PipfileLoader
content = f.read()
if encoding is not None:
content = content.decode(encoding)
_data = tomlkit.loads(content)
should_reload = "source" not in _data
_data = reorder_source_keys(_data)
if should_reload:
if "sources" in _data:
content = tomlkit.dumps(_data)
else:
# HACK: There is no good way to prepend a section to an existing
# TOML document, but there's no good way to copy non-structural
# content from one TOML document to another either. Modify the
# TOML content directly, and load the new in-memory document.
sep = "" if content.startswith("\n") else "\n"
content = plette.pipfiles.DEFAULT_SOURCE_TOML + sep + content
data = tomlkit.loads(content)
data = cls.ensure_package_sections(data)
instance = cls(data)
instance._data = dict(instance._data)
return instance
示例2: test_coverage_include_all_packages
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def test_coverage_include_all_packages():
"""Coverage source should include all packages.
1. From the main pyproject.toml.
2. From test helpers pyproject.toml.
3. The tests package.
"""
ini_parser = configparser.ConfigParser()
ini_parser.read(".coveragerc")
coverage_sources = ini_parser["run"]["source"].strip().splitlines()
pyproject_toml = tomlkit.loads(open("pyproject.toml").read())
packages = [
re.sub(r"\.py$", "", p["include"])
for p in pyproject_toml["tool"]["poetry"]["packages"]
]
pyproject_toml = tomlkit.loads(open("tests/helpers/pyproject.toml").read())
helpers = [
re.sub(r"\.py$", "", p["include"])
for p in pyproject_toml["tool"]["poetry"]["packages"]
]
assert coverage_sources == packages + helpers + ["tests"]
示例3: main
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def main(*, config_path: str = DEFAULT_CONFIG_PATH) -> None:
"""Main entry point for the default bot launcher."""
log.info("Loading config")
config_data = Path(config_path).read_text()
config: util.config.Config = tomlkit.loads(config_data)
# Initialize Sentry reporting here to exempt config syntax errors and query
# the user's report_errors value, defaulting to enabled if not specified
if config["bot"].get("report_errors", True):
log.info("Initializing Sentry error reporting")
util.sentry.init()
# Use preliminary loop for config upgrading
loop = asyncio.get_event_loop()
aiorun.run(_upgrade(config, config_path), stop_on_unhandled_errors=True, loop=loop)
loop.close()
loop = setup_asyncio(config)
# Start bot
log.info("Initializing bot")
aiorun.run(Bot.create_and_run(config, loop=loop), loop=loop)
示例4: read_version
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def read_version(self) -> int:
lines = self.pre_commit_hook.split('\n')
if len(lines) < 2:
return -1
try:
parsed = tomlkit.loads(lines[1][1:])
except tomlkit.exceptions.TOMLKitError:
return -1
try:
meta = parsed['meta']
return int(meta['version'])
except KeyError:
return -1
示例5: from_pyproject_toml
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def from_pyproject_toml(pyproject_toml: Path = None) -> "AutohooksConfig":
if pyproject_toml is None:
pyproject_toml = get_pyproject_toml_path()
if not pyproject_toml.exists():
return AutohooksConfig()
config_dict = tomlkit.loads(pyproject_toml.read_text())
return AutohooksConfig(config_dict)
示例6: test_parse_can_parse_valid_toml_files
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def test_parse_can_parse_valid_toml_files(example, example_name):
assert isinstance(parse(example(example_name)), TOMLDocument)
assert isinstance(loads(example(example_name)), TOMLDocument)
示例7: test_parsed_document_are_properly_json_representable
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def test_parsed_document_are_properly_json_representable(
example, json_example, example_name
):
doc = json.loads(json.dumps(parse(example(example_name)), default=json_serial))
json_doc = json.loads(json_example(example_name))
assert doc == json_doc
示例8: test_write_backslash
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def test_write_backslash():
d = {"foo": "\e\u25E6\r"}
expected = """foo = "\\\\e\u25E6\\r"
"""
assert expected == dumps(d)
assert loads(dumps(d))["foo"] == "\e\u25E6\r"
示例9: test_bump_pyproject
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def test_bump_pyproject(temp_path: Path):
from_path = temp_path / 'pyproject.toml'
from_path.write_text(dedent("""
[tool.poetry]
name = "check-me"
version = "1.2.3"
[tool.poetry.dependencies]
python = "*"
sentry_sdk = ">=0.9.0"
npm = "^0.9.0"
reponame = { git = "ssh://git@our-git-server:port/group/reponame.git", branch = "v3_2" }
[[tool.poetry.source]]
name = "pypi"
url = "https://pypi.org/pypi"
"""))
before_toml = tomlkit.loads(from_path.read_text())
config = Config()
config.attach({
'project': str(temp_path),
'from': {'format': 'poetry', 'path': 'pyproject.toml'},
})
command = ProjectBumpCommand(argv=['fix'], config=config)
result = command()
assert result is True
after_toml = tomlkit.loads(from_path.read_text())
assert after_toml['tool']['poetry']['version'] == '1.2.4', 'Version was not bumped properly'
after_toml['tool']['poetry']['version'] = '1.2.3'
assert after_toml == before_toml, 'Bump command altered attributes other than version'
示例10: generate_poetry_content
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [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)
示例11: load
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def load(cls, f, encoding=None):
content = f.read()
if encoding is not None:
content = content.decode(encoding)
data = tomlkit.loads(content)
if "source" not in data:
# HACK: There is no good way to prepend a section to an existing
# TOML document, but there's no good way to copy non-structural
# content from one TOML document to another either. Modify the
# TOML content directly, and load the new in-memory document.
sep = "" if content.startswith("\n") else "\n"
content = DEFAULT_SOURCE_TOML + sep + content
data = tomlkit.loads(content)
return cls(data)
示例12: is_installable_dir
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def is_installable_dir(path):
# type: (STRING_TYPE) -> bool
if pip_shims.shims.is_installable_dir(path):
return True
pyproject_path = os.path.join(path, "pyproject.toml")
if os.path.exists(pyproject_path):
pyproject = Path(pyproject_path)
pyproject_toml = tomlkit.loads(pyproject.read_text())
build_system = pyproject_toml.get("build-system", {}).get("build-backend", "")
if build_system:
return True
return False
示例13: _read_pyproject
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def _read_pyproject(self):
# type: () -> None
pyproject = self.path.parent.joinpath("pyproject.toml")
if pyproject.exists():
self._pyproject = tomlkit.loads(pyproject.read_text())
build_system = self._pyproject.get("build-system", None)
if build_system and not build_system.get("build_backend"):
build_system["build-backend"] = "setuptools.build_meta:__legacy__"
elif not build_system or not build_system.get("requires"):
build_system = {
"requires": ["setuptools>=40.8", "wheel"],
"build-backend": "setuptools.build_meta:__legacy__",
}
self.build_system = build_system
示例14: test_packages_are_ordered
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def test_packages_are_ordered():
"""Packages of pyproject.toml files should be in order."""
for pyproject_toml in ["pyproject.toml", "tests/helpers/pyproject.toml"]:
pyproject_toml = tomlkit.loads(open(pyproject_toml).read())
packages = [
re.sub(r"\.py$", "", p["include"])
for p in pyproject_toml["tool"]["poetry"]["packages"]
]
assert packages == sorted(packages)
示例15: test_build_requires_are_ordered
# 需要导入模块: import tomlkit [as 别名]
# 或者: from tomlkit import loads [as 别名]
def test_build_requires_are_ordered():
"""Build system requirements of pyproject.toml files should be in order."""
for pyproject_toml in ["pyproject.toml", "tests/helpers/pyproject.toml"]:
pyproject_toml = tomlkit.loads(open(pyproject_toml).read())
requires = pyproject_toml["build-system"]["requires"]
assert requires == sorted(requires)