Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save tddschn/3f4f80fdcc385beabd68434087b5c6eb to your computer and use it in GitHub Desktop.
Save tddschn/3f4f80fdcc385beabd68434087b5c6eb to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
"""
Author: Teddy Xinyuan Chen
Date: 2020-08-17
"""
from functools import cache
from pathlib import Path
from subprocess import run
import re
PIPX_VIRTUALENV_DIR = Path('~/.local/pipx/venvs').expanduser()
@cache
def get_pipx_version() -> str:
version = run(['pipx', '--version'], capture_output=True).stdout.decode().strip()
return version
def re_symlink_python(src: Path) -> str:
pipx_version = get_pipx_version()
orig_target = str(src.readlink())
new_target, subs_made = re.subn(
r'/pipx/[^/]+/', f'/pipx/{pipx_version}/', orig_target, count=1
)
if subs_made == 1:
src.unlink()
src.symlink_to(new_target)
return new_target
else:
return orig_target
def main() -> None:
link_src = list(PIPX_VIRTUALENV_DIR.rglob('*/bin/python3.*'))
for src in link_src:
new_target = re_symlink_python(src)
print(f'symlinked {str(src)} to {new_target}')
if __name__ == '__main__':
main()
@tddschn
Copy link
Author

tddschn commented Aug 17, 2022

My script to resolve pipx upgrade from 1.0.0 to 1.1.0 breaks python executable symlinks and breaks all installed apps issue by re-symlinking to the correct python executables, see pypa/pipx#886.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment