Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix local plugin installation #1129

Merged
merged 3 commits into from
Apr 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,20 @@ These are all the changes in Lektor since the first public release.

## 3.3.9 (unreleased)

### Bit-Rot

- Fix installation of local plugins (from the `packages/`
subdirectory). This was broken by release 23.1 of `pip` which
dropped support for the `--install-option` flag to `pip install`.
([#1129], [#1127])

### Bugs

- Implement better input validation for the date/time-formatting jinja
filters. Prior to this, passing a `jinja2.Undefined` value to the
`date`, `time`, or `datetime` filters would elicit an assertion
error. ([#1122], [#1121])

- Fix for spurious rebuilds. Recent versions of watchdog (>=2.3.0)
enabled tracking of IN_OPEN events. These fire when a file is opened
— even just for reading. Now we're pickier about only responding to
Expand All @@ -18,6 +26,8 @@ These are all the changes in Lektor since the first public release.
[#1117]: https://github.com/lektor/lektor/pull/1117
[#1121]: https://github.com/lektor/lektor/issues/1121
[#1122]: https://github.com/lektor/lektor/pull/1122
[#1127]: https://github.com/lektor/lektor/issues/1127
[#1129]: https://github.com/lektor/lektor/pull/1129

## 3.3.8 (2023-02-28)

Expand Down
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
9 changes: 9 additions & 0 deletions tests/setup_py-dummy-plugin/lektor_dummy_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
"""Dummy test plugin"""
from lektor.pluginsystem import Plugin


class DummyPlugin(Plugin):
"""Dummy test plugin."""

# pylint: disable=too-few-public-methods
name = "dummy"
13 changes: 13 additions & 0 deletions tests/setup_py-dummy-plugin/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from setuptools import setup

setup(
name="lektor-dummy-plugin",
description="setup.py test plugin",
version="0.1a42",
py_modules=["lektor_dummy_plugin"],
entry_points={
"lektor.plugins": [
"dummy-plugin = lektor_dummy_plugin:DummyPlugin",
]
},
)
18 changes: 18 additions & 0 deletions tests/test_packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import os
from pathlib import Path

import pytest

from lektor.packages import add_site
from lektor.packages import install_local_package
from lektor.pluginsystem import load_plugins


@pytest.mark.usefixtures("save_sys_path")
def test_install_local_package(tmp_path):
package_root = os.fspath(tmp_path / "package_root")
dummy_plugin_path = os.fspath(Path(__file__).parent / "setup_py-dummy-plugin")
install_local_package(package_root, dummy_plugin_path)
add_site(package_root)
plugins = load_plugins()
assert plugins["dummy-plugin"].name == "dummy"