def get_pipfile_libs(repopath: Path) -> dict[PackageName, list[ImportName]]: """Collect info from Pipfile with additions from site-packages The dict has as key the Pipfile package name and as value a list with all import names from top_level.txt packagenames may differ from the import names, also the site-package folder can be different.""" site_packages = packagenames_to_libnames(repopath) pipfile_to_libs: dict[PackageName, list[ImportName]] = {} parsed_pipfile = Pipfile.load(filename=repopath / "Pipfile") for name, details in parsed_pipfile.data["default"].items(): if "path" in details: # Ignoring some of our own sub-packages e.g. agent-receiver continue if name in site_packages: pipfile_to_libs[name] = site_packages[name] continue for char_to_be_replaced, replacement in permutations(PACKAGE_REPLACEMENTS, 2): fuzzy_name = PackageName(name.replace(char_to_be_replaced, replacement)) if fuzzy_name in site_packages: pipfile_to_libs[name] = site_packages[fuzzy_name] break else: raise NotImplementedError("Could not find package %s in site_packages" % name) return pipfile_to_libs
def _get_import_names_from_pipfile() -> List[str]: parsed_pipfile = Pipfile.load(filename=repo_path() + "/Pipfile") import_names = [] for dist_name in parsed_pipfile.data["default"].keys(): import_names.extend(_get_import_names_from_dist_name(dist_name)) assert import_names return import_names
def get_dependencies(self, scope: str = "default") -> List[str]: """Get dependencies of object""" deps: dict = Pipfile.load(filename="./Pipfile").data if scope == "default": return list(deps["default"]) elif scope == "dev": return list(deps["develop"]) return []
def test_all_deployment_packages_pinned() -> None: parsed_pipfile = Pipfile.load(filename=repo_path() + "/Pipfile") unpinned_packages = [ f"'{n}'" for n, v in parsed_pipfile.data["default"].items() if v == "*" ] assert not unpinned_packages, ( "The following packages are not pinned: %s. " "For the sake of reproducibility, all deployment packages must be pinned to a version!" ) % " ,".join(unpinned_packages)
def get_packages_from_pipfile(path_sources_dir) -> Dict[str, str]: pipfile_path: Path = Path(path_sources_dir / "Pipfile") pipfile = Pipfile.load(filename=pipfile_path) data: Dict[str, str] = pipfile.data["default"] delete_keys: List[str] = [] for k, d in data.items(): if isinstance(d, str) and d.startswith("=="): data[k] = re.sub("^==", "", d) else: delete_keys.append(k) for k in delete_keys: del data[k] return data
def build(ctx): print_header("Running build", icon="🔨") print("Cleanup the 'build' directory") shutil.rmtree("build", ignore_errors=True) print_header("Generate requirements.txt file", icon="⚙", level=2) parsed_pipfile = Pipfile.load("Pipfile") requirements_file = "\n".join([ "# DON'T CHANGE THIS FILE! It is generated by `inv build`.\n", *list(parsed_pipfile.data["default"].keys()) ]) print(requirements_file) with open("requirements.txt", "w") as fd: fd.write(requirements_file) print_header("Build packages", icon="🔨", level=2) ctx.run("python setup.py sdist bdist_wheel", pty=True, env={"PYTHONPATH": PROJECT_INFO.source_directory}) print_header("Check PyPI description", icon="👀", level=2) ctx.run("twine check dist/*")
def load_pipfile(): return Pipfile.load(filename=repo_path() + "/Pipfile")