fix: inside pdm venv pip is not a python module

This commit is contained in:
Daylin Morgan 2024-07-12 14:56:23 -05:00
parent bcad0e5696
commit 6ab83242e2
Signed by: daylin
GPG key ID: 950D13E9719334AD

View file

@ -3862,6 +3862,7 @@ class Cli:
self._validate_args(args) self._validate_args(args)
func = args.__dict__.pop("func") func = args.__dict__.pop("func")
_pip_check()
func( func(
**vars(args), **vars(args),
) )
@ -3873,9 +3874,27 @@ def _pip_check():
err_quit("viv requires pip to be installed") err_quit("viv requires pip to be installed")
# importing viv may have side effects I'm not aware of... # importing viv may have side effects I'm not aware of...
if Version((pip_version := __import__("pip").__version__)) not in SpecifierSet( try:
pip_version_requirement pip_version = __import__("pip").__version__
): except ModuleNotFoundError:
cmd = ["pip", "--version"]
p = subprocess.run(
cmd,
text=True,
stderr=subprocess.STDOUT,
stdout=subprocess.PIPE,
)
if p.returncode != 0:
a.subprocess(cmd, p.stdout)
err_quit("viv failed to get version from pip, see above")
if not p.stdout.startswith("pip"):
a.subprocess(cmd, p.stdout)
err_quit("unexpected output from pip, see above")
pip_version = p.stdout.split()[1]
if Version(pip_version) not in SpecifierSet(pip_version_requirement):
err_quit( err_quit(
f"viv requires pip version {pip_version_requirement} but got {pip_version}" f"viv requires pip version {pip_version_requirement} but got {pip_version}"
) )
@ -3892,7 +3911,6 @@ def _no_traceback_excepthook(
def main() -> None: def main() -> None:
try: try:
_pip_check()
viv = Viv() viv = Viv()
Cli(viv).run() Cli(viv).run()
except KeyboardInterrupt: except KeyboardInterrupt: