Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
version = safe_version(new_version)
pyproject_toml = tomlkit.parse(pyproject_toml_path.read_text())
if 'tool' not in pyproject_toml:
tool_table = tomlkit.table()
pyproject_toml['tool'] = tool_table
if 'poetry' not in pyproject_toml['tool']:
poetry_table = tomlkit.table()
pyproject_toml['tool'].add('poetry', poetry_table)
pyproject_toml['tool']['poetry']['version'] = version
pyproject_toml_path.write_text(tomlkit.dumps(pyproject_toml))
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()
def write_toml(self, data, path=None):
"""Writes the given data structure out as TOML."""
if path is None:
path = self.pipfile_location
data = convert_toml_outline_tables(data)
try:
formatted_data = tomlkit.dumps(data).rstrip()
except Exception:
document = tomlkit.document()
for section in ("packages", "dev-packages"):
document[section] = tomlkit.container.Table()
# Convert things to inline tables — fancy :)
for package in data.get(section, {}):
if hasattr(data[section][package], "keys"):
table = tomlkit.inline_table()
table.update(data[section][package])
document[section][package] = table
else:
document[section][package] = tomlkit.string(data[section][package])
formatted_data = tomlkit.dumps(document).rstrip()
if (
vistir.compat.Path(path).absolute()
def serialize(cls, data):
import tomlkit
return tomlkit.dumps(data)
data = convert_toml_outline_tables(data)
try:
formatted_data = tomlkit.dumps(data).rstrip()
except Exception:
document = tomlkit.document()
for section in ("packages", "dev-packages"):
document[section] = tomlkit.container.Table()
# Convert things to inline tables — fancy :)
for package in data.get(section, {}):
if hasattr(data[section][package], "keys"):
table = tomlkit.inline_table()
table.update(data[section][package])
document[section][package] = table
else:
document[section][package] = tomlkit.string(data[section][package])
formatted_data = tomlkit.dumps(document).rstrip()
if (
vistir.compat.Path(path).absolute()
== vistir.compat.Path(self.pipfile_location).absolute()
):
newlines = self._pipfile_newlines
else:
newlines = DEFAULT_NEWLINES
formatted_data = cleanup_toml(formatted_data)
with io.open(path, "w", newline=newlines) as f:
f.write(formatted_data)
# pipfile is mutated!
self.clear_pipfile_cache()