def dumps(self, data, sort=False): # type: (...) -> str if not isinstance(data, TOMLFile): data = toml.dumps(data, sort_keys=sort) else: data = dumps(data) return data
def write(self, data) -> None: if not isinstance(data, TOMLFile): data = toml.dumps(data) else: data = dumps(data) self._path.write_text(data)
def write(self, data): # type: (...) -> None if not isinstance(data, TOMLFile): data = toml.dumps(data) else: data = dumps(data) with self._path.open("w") as f: f.write(data)
def write(self, data) -> None: if not isinstance(data, TOMLFile): data = toml.dumps(data) else: data = dumps(data) with self._path.open('w') as f: f.write(data)
def _write_poetry(self, path): content = loads(POETRY_DEFAULT) poetry_content = content['tool']['poetry'] poetry_content['name'] = self._project poetry_content['version'] = self._version poetry_content['authors'].append(self._author) poetry = path / 'pyproject.toml' with poetry.open('w') as f: f.write(dumps(content))
def test_set_elements(): t = """\ [tool.poetry] name = "poetry" version = "0.1.0" [tool.poetry.dependencies] python = "^3.6" """ parsed = loads(t) content = parsed['tool']['poetry'] assert content['name'] == 'poetry' assert content['version'] == '0.1.0' content['version'] = '0.2.0' t = dumps(parsed) parsed = loads(t) content = parsed['tool']['poetry'] assert content['name'] == 'poetry' assert content['version'] == '0.2.0'
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 return dumps(content)
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 return dumps(content)
def test_set_elements(): t = """\ [tool.poetry] name = "poetry" version = "0.1.0" [tool.poetry.dependencies] python = "^3.6" """ parsed = loads(t) content = parsed["tool"]["poetry"] assert content["name"] == "poetry" assert content["version"] == "0.1.0" content["version"] = "0.2.0" t = dumps(parsed) parsed = loads(t) content = parsed["tool"]["poetry"] assert content["name"] == "poetry" assert content["version"] == "0.2.0"