def format_lockfile( mapping: Dict[str, Candidate], fetched_dependencies: Dict[str, List[Requirement]], summary_collection: Dict[str, str], ) -> Dict: """Format lock file from a dict of resolved candidates, a mapping of dependencies and a collection of package summaries. """ packages = tomlkit.aot() file_hashes = tomlkit.table() for k, v in sorted(mapping.items()): base = tomlkit.table() base.update(v.as_lockfile_entry()) base.add("summary", summary_collection[strip_extras(k)[0]]) deps = make_array([r.as_line() for r in fetched_dependencies[k]], True) if len(deps) > 0: base.add("dependencies", deps) packages.append(base) if v.hashes: key = f"{k} {v.version}" array = tomlkit.array() array.multiline(True) for filename, hash_value in v.hashes.items(): inline = make_inline_table({"file": filename, "hash": hash_value}) array.append(inline) if array: file_hashes.add(key, array) doc = tomlkit.document() doc.add("package", packages) metadata = tomlkit.table() metadata.add("files", file_hashes) doc.add("metadata", metadata) return doc
def do_init( project: Project, name: str = "", version: str = "", license: str = "MIT", author: str = "", email: str = "", python_requires: str = "", ) -> None: """Bootstrap the project and create a pyproject.toml""" data = { "project": { "name": name, "version": version, "description": "", "authors": array_of_inline_tables([{"name": author, "email": email}]), "license": make_inline_table({"text": license}), "urls": {"homepage": ""}, "dependencies": make_array([], True), "dev-dependencies": make_array([], True), "requires-python": python_requires, "dynamic": ["classifiers"], }, "build-system": {"requires": ["pdm-pep517"], "build-backend": "pdm.pep517.api"}, } if python_requires and python_requires != "*": get_specifier(python_requires) if not project.pyproject: project._pyproject = data else: project._pyproject["project"] = data["project"] project._pyproject["build-system"] = data["build-system"] project.write_pyproject()
def format_lockfile(mapping, fetched_dependencies, summary_collection): """Format lock file from a dict of resolved candidates, a mapping of dependencies and a collection of package summaries. """ packages = tomlkit.aot() file_hashes = tomlkit.table() for k, v in sorted(mapping.items()): base = tomlkit.table() base.update(v.as_lockfile_entry()) base.add("summary", summary_collection[strip_extras(k)[0]]) deps = tomlkit.table() for r in fetched_dependencies[k].values(): name, req = r.as_req_dict() if getattr(req, "items", None) is not None: deps.add(name, make_inline_table(req)) else: deps.add(name, req) if len(deps) > 0: base.add("dependencies", deps) packages.append(base) if v.hashes: key = f"{k} {v.version}" array = tomlkit.array() array.multiline(True) for filename, hash_value in v.hashes.items(): inline = make_inline_table({ "file": filename, "hash": hash_value }) array.append(inline) if array: file_hashes.add(key, array) doc = tomlkit.document() doc.add("package", packages) metadata = tomlkit.table() metadata.add("files", file_hashes) doc.add("metadata", metadata) return doc
def name(self, metadata: Dict[str, Any]) -> str: # name module = metadata.pop("module") self._data["name"] = metadata.pop("dist-name", module) # version and description if (Path(module) / "__init__.py").exists(): source = Path(module) / "__init__.py" else: source = Path(f"{module}.py") version = self._data.get("version") description = self._data.get("description") description_in_ast, version_in_ast = get_docstring_and_version_via_ast( source) self._data["version"] = version or version_in_ast or "" self._data["description"] = description or description_in_ast or "" self.warn_against_dynamic_version_or_docstring( source, self._data["version"], self._data["description"]) # author and maintainer if "author" in metadata: self._data["authors"] = _get_author(metadata) if "maintainer" in metadata: self._data["maintainers"] = _get_author(metadata, "maintainer") if "license" in metadata: self._data["license"] = make_inline_table( {"text": metadata.pop("license")}) self._data["dynamic"] = ["classifiers"] if "urls" in metadata: self._data["urls"] = metadata.pop("urls") if "home-page" in metadata: self._data.setdefault("urls", {})["homepage"] = metadata.pop("home-page") if "description-file" in metadata: self._data["readme"] = metadata.pop("description-file") if "requires-python" in metadata: self._data["requires-python"] = metadata.pop("requires-python") self._data["dynamic"] = ["classifiers"] # requirements self._data["dependencies"] = make_array(metadata.pop("requires", []), True) self._data["optional-dependencies"] = metadata.pop( "requires-extra", {}) # Add remaining metadata as the same key self._data.update(metadata) return self._data["name"]
def do_init( project: Project, name: str = "", version: str = "", description: str = "", license: str = "MIT", author: str = "", email: str = "", python_requires: str = "", ) -> None: """Bootstrap the project and create a pyproject.toml""" data = { "project": { "name": name, "version": version, "description": description, "authors": array_of_inline_tables([{"name": author, "email": email}]), "license": make_inline_table({"text": license}), "dependencies": make_array([], True), }, "build-system": { "requires": ["pdm-pep517>=0.12.0"], "build-backend": "pdm.pep517.api", }, } if python_requires and python_requires != "*": data["project"]["requires-python"] = python_requires # type: ignore if name and version: readme = next(project.root.glob("README*"), None) if readme is None: readme = project.root.joinpath("README.md") readme.write_text(f"# {name}\n\n{description}\n") data["project"]["readme"] = readme.name # type: ignore get_specifier(python_requires) if not project.pyproject: project._pyproject = data else: project._pyproject["project"] = data["project"] # type: ignore project._pyproject["build-system"] = data["build-system"] # type: ignore project.write_pyproject() signals.post_init.send(project)
def name(self, metadata): # name module = metadata.pop("module") self._data["name"] = metadata.pop("dist-name", module) # version parent_dir = Path(self.filename).parent if (parent_dir / module / "__init__.py").exists(): source = parent_dir / module / "__init__.py" else: source = parent_dir / f"{module}.py" self._data["version"] = self.VERSION_RE.findall( source.read_text(encoding="utf-8"))[0] # author and maintainer if "author" in metadata: self._data["authors"] = _get_author(metadata) if "maintainer" in metadata: self._data["maintainers"] = _get_author(metadata, "maintainer") if "license" in metadata: self._data["license"] = make_inline_table( {"text", metadata.pop("license")}) self._data["dynamic"] = ["classifiers"] if "urls" in metadata: self._data["urls"] = metadata.pop("urls") if "home-page" in metadata: self._data.setdefault("urls", {})["homepage"] = metadata.pop("home-page") if "description-file" in metadata: self._data["readme"] = metadata.pop("description-file") if "requires-python" in metadata: self._data["requires-python"] = metadata.pop("requires-python") self._data["dynamic"] = ["classifiers"] # requirements self._data["dependencies"] = make_array(metadata.pop("requires", []), True) self._data["optional-dependencies"] = metadata.pop( "requires-extra", {}) # Add remaining metadata as the same key self._data.update(metadata) return self._data["name"]
def format_lockfile( mapping: dict[str, Candidate], fetched_dependencies: dict[str, list[Requirement]], summary_collection: dict[str, str], ) -> dict: """Format lock file from a dict of resolved candidates, a mapping of dependencies and a collection of package summaries. """ packages = atoml.aot() file_hashes = atoml.table() for k, v in sorted(mapping.items()): base = atoml.table() base.update(v.as_lockfile_entry()) # type: ignore base.add("summary", summary_collection[strip_extras(k)[0]]) deps = make_array(sorted(r.as_line() for r in fetched_dependencies[k]), True) if len(deps) > 0: base.add("dependencies", deps) packages.append(base) # type: ignore if v.hashes: key = f"{strip_extras(k)[0]} {v.version}" if key in file_hashes: continue array = atoml.array().multiline(True) for filename, hash_value in v.hashes.items(): inline = make_inline_table({ "file": filename, "hash": hash_value }) array.append(inline) # type: ignore if array: file_hashes.add(key, array) doc = atoml.document() doc.add("package", packages) # type: ignore metadata = atoml.table() metadata.add("files", file_hashes) doc.add("metadata", metadata) # type: ignore return cast(dict, doc)
def license(self, value): self._data["dynamic"] = ["classifiers"] return make_inline_table({"text": value})
def license(self, value: str) -> Dict[str, str]: if "classifiers" not in self._data.setdefault("dynamic", []): self._data["dynamic"].append("classifiers") return cast(Dict[str, str], make_inline_table({"text": value}))
def license(self, value: str) -> Dict[str, str]: self._data["dynamic"] = ["classifiers"] return make_inline_table({"text": value})
def license(self, value): if "classifiers" not in self._data.setdefault("dynamic", []): self._data["dynamic"].append("classifiers") return make_inline_table({"text": value})