Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_poetry_deps_not_pinned():
"""Dependencies of pyproject.toml files should not have versions."""
for pyproject_toml in ["pyproject.toml", "tests/helpers/pyproject.toml"]:
pyproject_toml = tomlkit.loads(open(pyproject_toml).read())
versions = [
d.get("version")
for d in pyproject_toml["tool"]["poetry"].get("dependencies", {}).values()
if isinstance(d, dict)
]
assert all(v == "*" for v in versions)
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)
def deserialize(cls, file_object):
import tomlkit
return tomlkit.loads(file_object.read())
def set_converter_log_file(converter_config, log_file):
if os.path.exists(converter_config):
with codecs.open(converter_config, mode='r', encoding='utf-8') as f:
doc = tomlkit.loads(f.read())
f.close()
doc['logger']['file']['level'] = 'normal'
doc['logger']['file']['destination'] = log_file
doc['logger']['file']['mode'] = 'overwrite'
with codecs.open(converter_config, mode='w', encoding='utf-8') as f:
f.write(tomlkit.dumps(doc))
f.close()
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
def parse(cfg_path: Path) -> Config:
parsed = tomlkit.loads(cfg_path.text())
parsed = validate_basic_schema(parsed)
current_version = parsed["version"]["current"]
git_message_template = parsed["git"]["message_template"]
git_tag_template = parsed["git"]["tag_template"]
version_regex = re.compile(parsed["version"]["regex"], re.VERBOSE)
files = []
for file_dict in parsed["file"]:
file_config = File(
src=file_dict["src"],
search=file_dict.get("search"),
version_template=file_dict.get("version_template"),
)
files.append(file_config)
hooks = []
for hook_type in ("hook", "before_push", "before_commit", "after_push"):
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)
_data["source"] = _data.get("source", []) + _data.get("sources", [])
_data = reorder_source_keys(_data)
if "source" not in _data:
if "sources" in _data:
_data["source"] = _data["sources"]
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)
instance = cls(data)
instance._data = dict(instance._data)
def as_data(self):
data = {
"source": [source.as_data() for source in self.sources],
"packages": {
k: v.as_pipfile()[k] for k, v in self.packages.items()
},
"dev-packages": {
k: v.as_pipfile()[k] for k, v in self.dev_packages.items()
},
"requires": self.requires.as_data(),
}
data.update({
k: tomlkit.loads(tomlkit.dumps(v))
for k, v in self._data.items()
if k not in data
})
return data
def _validate_engine_path():
'''
Validates path 'Engine Path' in settings.toml
'''
if not sys.platform.startswith('win'):
return ''
try:
# pylint: disable=import-error
import natlink
except ImportError:
return ''
if os.path.isfile(_SETTINGS_PATH):
with io.open(_SETTINGS_PATH, "rt", encoding="utf-8") as toml_file:
data = tomlkit.loads(toml_file.read()).value
engine_path = data["paths"]["ENGINE_PATH"]
if os.path.isfile(engine_path):
return engine_path
else:
engine_path = _find_natspeak()
data["paths"]["ENGINE_PATH"] = engine_path
try:
formatted_data = unicode(tomlkit.dumps(data))
with io.open(_SETTINGS_PATH, "w", encoding="utf-8") as toml_file:
toml_file.write(formatted_data)
print("Setting engine path to " + engine_path)
except Exception as e:
print("Error saving settings file ") + str(e) + _SETTINGS_PATH
return engine_path
else:
return _find_natspeak()