MCPcopy Create free account
hub / github.com/EndstoneMC/endstone / find_python

Function find_python

endstone/plugin/plugin_loader.py:28–55  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

26
27
28def find_python() -> Path:
29 paths = []
30 if os.environ.get("ENDSTONE_PYTHON_EXECUTABLE", None) is not None:
31 paths.append(os.environ["ENDSTONE_PYTHON_EXECUTABLE"])
32
33 if sys.platform == "win32":
34 paths.append(os.path.join(sys.base_prefix, "python.exe"))
35 else:
36 paths.append(
37 os.path.join(sys.base_prefix, "bin", "python" + f"{sys.version_info.major}.{sys.version_info.minor}")
38 )
39 paths.append(os.path.join(sys.base_prefix, "bin", "python" + f"{sys.version_info.major}"))
40 paths.append(os.path.join(sys.base_prefix, "bin", "python"))
41
42 # Dedup while preserving order
43 seen = set()
44 ordered = []
45 for path in paths:
46 path = Path(path).resolve()
47 if path not in seen:
48 seen.add(path)
49 ordered.append(path)
50
51 for path in ordered:
52 if path.is_file():
53 return path
54
55 raise RuntimeError(f"Unable to find Python executable. Attempted paths: {ordered}")
56
57
58def _build_commands(commands: dict) -> list[Command]:

Callers 1

plugin_loader.pyFile · 0.85

Calls 4

addMethod · 0.80
PathClass · 0.50
getMethod · 0.45
resolveMethod · 0.45

Tested by

no test coverage detected