Skip to content

Commit

Permalink
fix(packages): fix local plugin installation
Browse files Browse the repository at this point in the history
The most recent version of pip (23.1) removes support for the
`--install-option` parameter to `pip install`.  This breaks our
`install_local_package` function, which uses `--install-option`
because `pip install --target` didn't used to work with `pip install
--editable`.

As it turns out, recent versions of pip support the use of `--target`
with `--editable`.  So here we make use of that.

Note that this also relieves us of the need to parse our local
plugin requirements ourselves (thus, hopefully, fixing #865.)
  • Loading branch information
dairiki committed Apr 16, 2023
1 parent 1136db6 commit dca38f0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 37 deletions.
37 changes: 2 additions & 35 deletions lektor/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import shutil
import site
import sys
import tempfile
from subprocess import PIPE

import click
Expand Down Expand Up @@ -104,53 +103,21 @@ def download_and_install_package(
def install_local_package(package_root, path):
"""This installs a local dependency of a package."""
# XXX: windows
env = dict(os.environ)
env["PYTHONPATH"] = package_root

# Step 1: generate egg info and link us into the target folder.
rv = portable_popen(
[
sys.executable,
"-m",
"pip",
"install",
"--target",
package_root,
"--editable",
path,
"--install-option=--install-dir=%s" % package_root,
"--no-deps",
],
env=env,
).wait()
if rv != 0:
raise RuntimeError("Failed to install local package")

# Step 2: generate the egg info into a temp folder to find the
# requirements.
tmp = tempfile.mkdtemp()
try:
rv = portable_popen(
[
sys.executable,
"setup.py",
"--quiet",
"egg_info",
"--quiet",
"--egg-base",
tmp,
],
cwd=path,
).wait()
dirs = os.listdir(tmp)
if rv != 0 or len(dirs) != 1:
raise RuntimeError("Failed to create egg info for local package.")
requires = os.path.join(tmp, dirs[0], "requires.txt")

# We have dependencies, install them!
if os.path.isfile(requires):
download_and_install_package(package_root, requirements_file=requires)
finally:
shutil.rmtree(tmp)


def get_package_info(path):
"""Returns the name of a package at a path."""
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ install_requires =
Jinja2>=3.0
markupsafe
mistune>=0.7.0,<2
pip
pip>=21.1
python-slugify
pytz
requests
setuptools
setuptools>=45.2
watchdog
Werkzeug<3

Expand Down

0 comments on commit dca38f0

Please sign in to comment.