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(venv_bundler): install all deps as not editable #106

Merged
merged 6 commits into from
Jul 23, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/poetry_plugin_bundle/bundlers/venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from cleo.io.outputs.section_output import SectionOutput
from poetry.core.constraints.version import Version
from poetry.poetry import Poetry
from poetry.repositories.lockfile_repository import LockfileRepository


class VenvBundler(Bundler):
Expand Down Expand Up @@ -57,6 +58,7 @@ def bundle(self, poetry: Poetry, io: IO) -> bool:
from poetry.core.packages.package import Package
from poetry.installation.installer import Installer
from poetry.installation.operations.install import Install
from poetry.packages.locker import Locker
from poetry.utils.env import EnvManager
from poetry.utils.env import SystemEnv
from poetry.utils.env import VirtualEnv
Expand Down Expand Up @@ -118,11 +120,20 @@ def bundle(self, poetry: Poetry, io: IO) -> bool:

self._write(io, f"{message}: <info>Installing dependencies</info>")

class CustomLocker(Locker):
def locked_repository(self) -> LockfileRepository:
repo = super().locked_repository()
for package in repo.packages:
package.develop = False
return repo

custom_locker = CustomLocker(poetry.locker.lock, poetry.local_config)

installer = Installer(
NullIO() if not io.is_debug() else io,
env,
poetry.package,
poetry.locker,
custom_locker,
poetry.pool,
poetry.config,
)
Expand Down
41 changes: 41 additions & 0 deletions tests/bundlers/test_venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from cleo.io.buffered_io import BufferedIO
from poetry.core.packages.package import Package
from poetry.factory import Factory
from poetry.installation.operations.install import Install
from poetry.puzzle.exceptions import SolverProblemError
from poetry.repositories.repository import Repository
from poetry.repositories.repository_pool import RepositoryPool
Expand Down Expand Up @@ -268,3 +269,43 @@ def test_bundler_can_filter_dependency_groups(
• Bundled simple-project (1.2.3) into {path}
"""
assert expected == io.fetch_output()


def test_bundler_editable_deps(
io: BufferedIO, tmpdir: str, poetry: Poetry, mocker: MockerFixture, config: Config
) -> None:
poetry = Factory().create_poetry(
Path(__file__).parent.parent / "fixtures" / "simple_project_with_editable_dep"
)
poetry.set_config(config)

install_spy = mocker.spy(Install, "__init__")
mocker.patch("poetry.installation.executor.Executor._execute_operation")

bundler = VenvBundler()
bundler.set_path(Path(tmpdir))

io.clear_output()

bundler.bundle(poetry, io)

path = tmpdir
python_version = ".".join(str(v) for v in sys.version_info[:3])
expected = f"""\
• Bundling simple-project (1.2.3) into {path}
• Bundling simple-project (1.2.3) into {path}: Removing existing virtual environment
• Bundling simple-project (1.2.3) into {path}: Creating a virtual environment using Python {python_version}
• Bundling simple-project (1.2.3) into {path}: Installing dependencies
• Bundling simple-project (1.2.3) into {path}: Installing simple-project (1.2.3)
• Bundled simple-project (1.2.3) into {path}
"""
assert expected == io.fetch_output()

installed_packages = [call.args[1] for call in install_spy.call_args_list]
dep_installs = list(
filter(lambda package: package.name == "bar", installed_packages)
)
assert len(dep_installs) > 0

editable_installs = list(filter(lambda package: package.develop, dep_installs))
assert len(editable_installs) == 0
2 changes: 2 additions & 0 deletions tests/fixtures/simple_project_with_editable_dep/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
My Package
==========
Empty file.
25 changes: 25 additions & 0 deletions tests/fixtures/simple_project_with_editable_dep/bar/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[tool.poetry]
name = "bar"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <[email protected]>"
]
license = "MIT"

readme = "README.rst"

homepage = "https://python-poetry.org"
repository = "https://github.com/python-poetry/poetry"
documentation = "https://python-poetry.org/docs"

keywords = ["packaging", "dependency", "poetry"]

classifiers = [
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules"
]

# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.4"
16 changes: 16 additions & 0 deletions tests/fixtures/simple_project_with_editable_dep/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions tests/fixtures/simple_project_with_editable_dep/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[tool.poetry]
name = "simple-project"
version = "1.2.3"
description = "Some description."
authors = [
"Sébastien Eustace <[email protected]>"
]
license = "MIT"

readme = "README.rst"

homepage = "https://python-poetry.org"
repository = "https://github.com/python-poetry/poetry"
documentation = "https://python-poetry.org/docs"

keywords = ["packaging", "dependency", "poetry"]

classifiers = [
"Topic :: Software Development :: Build Tools",
"Topic :: Software Development :: Libraries :: Python Modules"
]

# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.4"
bar = { path = "bar", develop = true }

[tool.poetry.scripts]
foo = "foo:bar"
baz = "bar:baz.boom.bim"
Loading