Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- from pathlib import Path
- from tempfile import TemporaryDirectory
- def relpath(path_to: Path, path_from: Path) -> Path:
- path_to = Path(path_to).resolve()
- path_from = Path(path_from).resolve()
- try:
- for p in (*reversed(path_from.parents), path_from):
- head, tail = p, path_to.relative_to(p)
- except ValueError: # Stop when the paths diverge.
- pass
- return Path("../" * (len(path_from.parents) - len(head.parents))).joinpath(tail)
- a_package_name = "a_package"
- with TemporaryDirectory() as td:
- pypi_mirror_root = Path(td)
- web_root = pypi_mirror_root / "web"
- json_path = web_root / "json"
- pkg_json_path = json_path / a_package_name
- pkg_json_pypi_path = web_root / "pypi" / a_package_name / "json"
- json_path.mkdir(parents=True)
- pkg_json_path.touch()
- pkg_json_pypi_path.parent.mkdir(parents=True)
- rel_path = relpath(pkg_json_path, pkg_json_pypi_path)
- pkg_json_pypi_path.symlink_to(rel_path)
- print(f"Symlink made relative from {pkg_json_pypi_path} to {rel_path}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement