Commit c264bc0f by Arun Babu Neelicattu

editable builder: handle package includes correctly

Previously, the editable builder contained a regression that only
included poetry root when generating .pth files. This change ensure
that all package or module sources are included as per configuration.

Resolves: #2657
parent d5a99f00
...@@ -8,6 +8,7 @@ from base64 import urlsafe_b64encode ...@@ -8,6 +8,7 @@ from base64 import urlsafe_b64encode
from poetry.core.masonry.builders.builder import Builder from poetry.core.masonry.builders.builder import Builder
from poetry.core.masonry.builders.sdist import SdistBuilder from poetry.core.masonry.builders.sdist import SdistBuilder
from poetry.core.masonry.utils.package_include import PackageInclude
from poetry.core.semver.version import Version from poetry.core.semver.version import Version
from poetry.utils._compat import WINDOWS from poetry.utils._compat import WINDOWS
from poetry.utils._compat import Path from poetry.utils._compat import Path
...@@ -91,8 +92,17 @@ class EditableBuilder(Builder): ...@@ -91,8 +92,17 @@ class EditableBuilder(Builder):
pth.name, self._env.site_packages, self._poetry.file.parent pth.name, self._env.site_packages, self._poetry.file.parent
) )
) )
paths = set()
for include in self._module.includes:
if isinstance(include, PackageInclude) and (
include.is_module() or include.is_package()
):
paths.add(include.base.resolve().as_posix())
with pth.open("w", encoding="utf-8") as f: with pth.open("w", encoding="utf-8") as f:
f.write(decode(str(self._poetry.file.parent.resolve()))) for path in paths:
f.write(decode(path + os.linesep))
return [pth] return [pth]
......
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import os
import shutil import shutil
import pytest import pytest
...@@ -24,6 +25,15 @@ def simple_poetry(): ...@@ -24,6 +25,15 @@ def simple_poetry():
@pytest.fixture() @pytest.fixture()
def project_with_include():
poetry = Factory().create_poetry(
Path(__file__).parent.parent.parent / "fixtures" / "with-include"
)
return poetry
@pytest.fixture()
def extended_poetry(): def extended_poetry():
poetry = Factory().create_poetry( poetry = Factory().create_poetry(
Path(__file__).parent.parent.parent / "fixtures" / "extended_project" Path(__file__).parent.parent.parent / "fixtures" / "extended_project"
...@@ -56,9 +66,10 @@ def test_builder_installs_proper_files_for_standard_packages(simple_poetry, tmp_ ...@@ -56,9 +66,10 @@ def test_builder_installs_proper_files_for_standard_packages(simple_poetry, tmp_
assert tmp_venv._bin_dir.joinpath("foo").exists() assert tmp_venv._bin_dir.joinpath("foo").exists()
assert tmp_venv.site_packages.joinpath("simple_project.pth").exists() assert tmp_venv.site_packages.joinpath("simple_project.pth").exists()
assert ( assert simple_poetry.file.parent.resolve().as_posix() == tmp_venv.site_packages.joinpath(
str(simple_poetry.file.parent.resolve()) "simple_project.pth"
== tmp_venv.site_packages.joinpath("simple_project.pth").read_text() ).read_text().strip(
os.linesep
) )
dist_info = tmp_venv.site_packages.joinpath("simple_project-1.2.3.dist-info") dist_info = tmp_venv.site_packages.joinpath("simple_project-1.2.3.dist-info")
...@@ -159,3 +170,26 @@ def test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts( ...@@ -159,3 +170,26 @@ def test_builder_falls_back_on_setup_and_pip_for_packages_with_build_scripts(
"--no-deps", "--no-deps",
] ]
] == env.executed ] == env.executed
def test_builder_installs_proper_files_when_packages_configured(
project_with_include, tmp_venv
):
builder = EditableBuilder(project_with_include, tmp_venv, NullIO())
builder.build()
pth_file = tmp_venv.site_packages.joinpath("with_include.pth")
assert pth_file.is_file()
paths = set()
with pth_file.open() as f:
for line in f.readlines():
line = line.strip(os.linesep)
if line:
paths.add(line)
project_root = project_with_include.file.parent.resolve()
expected = {project_root.as_posix(), project_root.joinpath("src").as_posix()}
assert paths.issubset(expected)
assert len(paths) == len(expected)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment