def __init__(self, path): self.path = path self.document = tomlkit.document() self.document["sources"] = tomlkit.aot() self.document["requires"] = tomlkit.table() self.document["packages"] = tomlkit.table() self.document["dev_packages"] = tomlkit.table()
def __init__(self, path): self.path = path if self.path.exists(): self.loads() else: self.document = tomlkit.document() self.document["source"] = self.document.get("source", tomlkit.aot()) self.document["requires"] = self.document.get("requires", tomlkit.table()) self.document["packages"] = self.document.get("packages", tomlkit.table()) self.document["dev_packages"] = self.document.get("dev_packages", tomlkit.table()) super().__init__()
def dumps(self): source_table = tomlkit.table() source_table["url"] = os.environ.get("PIPENV_TEST_INDEX") source_table["verify_ssl"] = False source_table["name"] = "pipenv_test_index" self.document["sources"].append(source_table) return tomlkit.dumps(self.document)
def dumps(self): source_table = tomlkit.table() pypi_url = os.environ.get("PIPENV_PYPI_URL", "https://pypi.org/simple") source_table["url"] = os.environ.get("PIPENV_TEST_INDEX", pypi_url) source_table["verify_ssl"] = False source_table["name"] = "pipenv_test_index" self.document["source"].append(source_table) return tomlkit.dumps(self.document)
def _get_pipfile_section(self, develop, insert=True): name = "dev-packages" if develop else "packages" try: section = self.pipfile[name] except KeyError: section = plette.models.PackageCollection(tomlkit.table()) if insert: self.pipfile[name] = section return section
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
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