This commit is contained in:
Eric Froemling 2024-04-23 15:19:34 -07:00
parent 50c70ff850
commit 83bbca6ffe
No known key found for this signature in database
GPG Key ID: 89C93F0F8D6D5A98

View File

@ -65,30 +65,33 @@ def pcommand_main(globs: dict[str, Any]) -> None:
# So let's go ahead and set up PATH here so tools/pcommand by itself # So let's go ahead and set up PATH here so tools/pcommand by itself
# *does* do the right thing. # *does* do the right thing.
abs_exe_path = Path(sys.executable).absolute() # Don't do this on Windows; we're not currently using virtual-envs
pathparts = abs_exe_path.parts # there for the little bit of tools stuff we support.
if ( if not sys.platform.startswith('win'):
len(pathparts) < 3 abs_exe_path = Path(sys.executable).absolute()
or pathparts[-3] != '.venv' pathparts = abs_exe_path.parts
or pathparts[-2] != 'bin' if (
or not pathparts[-1].startswith('python') len(pathparts) < 3
): or pathparts[-3] != '.venv'
raise RuntimeError( or pathparts[-2] != 'bin'
'Unexpected Python environment;' or not pathparts[-1].startswith('python')
' we expect to be running using .venv/bin/pythonX.Y' ):
) raise RuntimeError(
'Unexpected Python environment;'
' we expect to be running using .venv/bin/pythonX.Y'
)
cur_paths_str = os.environ.get('PATH') cur_paths_str = os.environ.get('PATH')
if cur_paths_str is None: if cur_paths_str is None:
raise RuntimeError("'PATH' is not currently set; unexpected.") raise RuntimeError("'PATH' is not currently set; unexpected.")
venv_bin_dir = str(abs_exe_path.parent) venv_bin_dir = str(abs_exe_path.parent)
# Only add our entry if it's not already there; don't want PATH to # Only add our entry if it's not already there; don't want PATH to
# get out of control if we're doing recursive stuff. # get out of control if we're doing recursive stuff.
cur_paths = cur_paths_str.split(':') cur_paths = cur_paths_str.split(':')
if venv_bin_dir not in cur_paths: if venv_bin_dir not in cur_paths:
os.environ['PATH'] = ':'.join([venv_bin_dir] + cur_paths) os.environ['PATH'] = ':'.join([venv_bin_dir] + cur_paths)
# Build our list of available command functions. # Build our list of available command functions.
_g_funcs = dict( _g_funcs = dict(