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

Add support to Poetry's non_package mode #119

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
53 changes: 30 additions & 23 deletions src/poetry_plugin_bundle/bundlers/venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,30 +165,37 @@ def locked_repository(self) -> LockfileRepository:
)
return False

self._write(
io,
f"{message}: <info>Installing <c1>{poetry.package.pretty_name}</c1>"
f" (<b>{poetry.package.pretty_version}</b>)</info>",
)
# Skip building the wheel if is_package_mode exists and is set to false
if hasattr(poetry, "is_package_mode") and not poetry.is_package_mode:
self._write(
io,
f"{message}: <info>Skipping installation for non package project <c1>{poetry.package.pretty_name}</c1>",
)
else:
self._write(
io,
f"{message}: <info>Installing <c1>{poetry.package.pretty_name}</c1>"
f" (<b>{poetry.package.pretty_version}</b>)</info>",
)

# Build a wheel of the project in a temporary directory
# and install it in the newly create virtual environment
with TemporaryDirectory() as directory:
try:
wheel_name = WheelBuilder.make_in(poetry, directory=Path(directory))
wheel = Path(directory).joinpath(wheel_name)
package = Package(
poetry.package.name,
poetry.package.version,
source_type="file",
source_url=str(wheel),
)
installer.executor.execute([Install(package)])
except ModuleOrPackageNotFound:
warnings.append(
"The root package was not installed because no matching module or"
" package was found."
)
# Build a wheel of the project in a temporary directory
# and install it in the newly create virtual environment
with TemporaryDirectory() as directory:
try:
wheel_name = WheelBuilder.make_in(poetry, directory=Path(directory))
wheel = Path(directory).joinpath(wheel_name)
package = Package(
poetry.package.name,
poetry.package.version,
source_type="file",
source_url=str(wheel),
)
installer.executor.execute([Install(package)])
except ModuleOrPackageNotFound:
warnings.append(
"The root package was not installed because no matching module or"
" package was found."
)

self._write(io, self._get_message(poetry, self._path, done=True))

Expand Down
27 changes: 27 additions & 0 deletions tests/bundlers/test_venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,30 @@ def test_bundler_should_build_a_venv_at_specified_path_if_centralized_venv_exist
• Bundled simple-project (1.2.3) into {path}
"""
assert expected == io.fetch_output()


def test_bundler_non_package_mode(
io: BufferedIO, tmp_venv: VirtualEnv, mocker: MockerFixture, config: Config
) -> None:
poetry = Factory().create_poetry(
Path(__file__).parent.parent / "fixtures" / "non_package_mode"
)
poetry.set_config(config)

mocker.patch("poetry.installation.executor.Executor._execute_operation")

bundler = VenvBundler()
bundler.set_path(tmp_venv.path)
bundler.set_remove(True)

assert bundler.bundle(poetry, io)

path = str(tmp_venv.path)
expected = f"""\
• Bundling simple-project-non-package-mode (1.2.3) into {path}
• Bundling simple-project-non-package-mode (1.2.3) into {path}: Creating a virtual environment using Poetry-determined Python
• Bundling simple-project-non-package-mode (1.2.3) into {path}: Installing dependencies
• Bundling simple-project-non-package-mode (1.2.3) into {path}: Skipping installation for non package project simple-project-non-package-mode
• Bundled simple-project-non-package-mode (1.2.3) into {path}
"""
assert expected == io.fetch_output()
11 changes: 11 additions & 0 deletions tests/fixtures/non_package_mode/poetry.lock

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

17 changes: 17 additions & 0 deletions tests/fixtures/non_package_mode/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "simple-project-non-package-mode"
version = "1.2.3"
package-mode = false

# Requirements
[tool.poetry.dependencies]
python = "~2.7 || ^3.4"


[tool.poetry.group.dev]
optional = true
dependencies = {}

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