Skip to content

Commit

Permalink
fix: use site.addsitedir to add installed plugins to path
Browse files Browse the repository at this point in the history
  • Loading branch information
wu-vincent committed Aug 27, 2024
1 parent 5e09452 commit ebc51f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
7 changes: 1 addition & 6 deletions python/src/endstone/_internal/bootstrap/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import logging
import os
import platform
import shutil
import site
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -219,11 +217,8 @@ def _create_process(self, *args, **kwargs) -> None:
**kwargs: Arbitrary keyword arguments.
"""
prefix = str((self.plugin_path / ".local").resolve().absolute())
shutil.rmtree(prefix, ignore_errors=True)

env = kwargs.pop("env", os.environ.copy())
env["PATH"] = os.pathsep.join(site.getsitepackages(prefixes=[prefix]) + sys.path)
env["PATH"] = os.pathsep.join(sys.path)
env["PYTHONPATH"] = os.pathsep.join(sys.path)
env["PYTHONIOENCODING"] = "UTF-8"
self._process = subprocess.Popen(
Expand Down
11 changes: 7 additions & 4 deletions python/src/endstone/_internal/plugin_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import importlib
import os
import os.path
import shutil
import site
import subprocess
import sys
Expand Down Expand Up @@ -74,6 +75,9 @@ def load_plugins(self, directory) -> List[Plugin]:
env = os.environ.copy()
env.pop("LD_PRELOAD", "")

prefix = os.path.join(directory, ".local")
shutil.rmtree(prefix, ignore_errors=True)

for file in glob.glob(os.path.join(directory, "*.whl")):
subprocess.run(
[
Expand All @@ -83,17 +87,16 @@ def load_plugins(self, directory) -> List[Plugin]:
"install",
file,
"--prefix",
os.path.join(directory, ".local"),
prefix,
"--quiet",
"--no-warn-script-location",
"--disable-pip-version-check",
],
env=env,
)

user_site_packages = site.getusersitepackages()
if user_site_packages not in sys.path:
sys.path.insert(0, user_site_packages)
for site_dir in site.getsitepackages(prefixes=[prefix]):
site.addsitedir(site_dir)

loaded_plugins = []
eps = entry_points(group="endstone")
Expand Down

0 comments on commit ebc51f9

Please sign in to comment.