MCPcopy Index your code
hub / github.com/pex-tool/pex / _resolve_pyvenv_canonical_python_binary

Method _resolve_pyvenv_canonical_python_binary

pex/interpreter.py:862–896  ·  view source on GitHub ↗
(
        cls,
        maybe_venv_python_binary,  # type: str
    )

Source from the content-addressed store, hash-verified

860
861 @classmethod
862 def _resolve_pyvenv_canonical_python_binary(
863 cls,
864 maybe_venv_python_binary, # type: str
865 ):
866 # type: (...) -> Optional[str]
867 maybe_venv_python_binary = os.path.abspath(maybe_venv_python_binary)
868 if not os.path.islink(maybe_venv_python_binary):
869 return None
870
871 pyvenv_cfg = PyVenvCfg.find(maybe_venv_python_binary)
872 if pyvenv_cfg is None:
873 return None
874
875 while os.path.islink(maybe_venv_python_binary):
876 resolved = os.readlink(maybe_venv_python_binary)
877 if not os.path.isabs(resolved):
878 resolved = os.path.abspath(
879 os.path.join(os.path.dirname(maybe_venv_python_binary), resolved)
880 )
881 if os.path.dirname(resolved) == os.path.dirname(maybe_venv_python_binary):
882 maybe_venv_python_binary = resolved
883 else:
884 # We've escaped the venv bin dir; so the last resolved link was the
885 # canonical venv Python binary.
886 #
887 # For example, for:
888 # ./venv/bin/
889 # python -> python3.8
890 # python3 -> python3.8
891 # python3.8 -> /usr/bin/python3.8
892 #
893 # We want to resolve each of ./venv/bin/python{,3{,.8}} to the canonical
894 # ./venv/bin/python3.8 which is the symlink that points to the home binary.
895 break
896 return maybe_venv_python_binary
897
898 @classmethod
899 def canonicalize_path(cls, path):

Callers 1

canonicalize_pathMethod · 0.80

Calls 2

findMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected