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

feat: add extras, no-directory, no-root options #78

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
24 changes: 24 additions & 0 deletions src/poetry_plugin_bundle/bundlers/venv_bundler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def __init__(self) -> None:
self._executable: str | None = None
self._remove: bool = False
self._activated_groups: set[str] | None = None
self._extras: set[str] | None = None
self._no_directory: bool = False
self._no_root: bool = False

def set_path(self, path: Path) -> VenvBundler:
self._path = path
Expand All @@ -46,6 +49,21 @@ def set_remove(self, remove: bool = True) -> VenvBundler:

return self

def set_extras(self, extras: set[str]) -> VenvBundler:
self._extras = extras

return self

def set_no_directory(self, no_directory: bool = True) -> VenvBundler:
self._no_directory = no_directory

return self

def set_no_root(self, no_root: bool = True) -> VenvBundler:
self._no_root = no_root

return self

def bundle(self, poetry: Poetry, io: IO) -> bool:
from pathlib import Path
from tempfile import TemporaryDirectory
Expand Down Expand Up @@ -128,6 +146,9 @@ def bundle(self, poetry: Poetry, io: IO) -> bool:
)
if self._activated_groups is not None:
installer.only_groups(self._activated_groups)
if self._extras is not None:
installer.extras(list(self._extras))
installer.skip_directory(self._no_directory)
installer.requires_synchronization()

return_code = installer.run()
Expand All @@ -139,6 +160,9 @@ def bundle(self, poetry: Poetry, io: IO) -> bool:
)
return False

if self._no_root:
return True

self._write(
io,
f"{message}: <info>Installing <c1>{poetry.package.pretty_name}</c1>"
Expand Down
19 changes: 19 additions & 0 deletions src/poetry_plugin_bundle/console/commands/bundle/venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from cleo.helpers import argument
from cleo.helpers import option
from poetry.console.commands.install import InstallCommand

from poetry_plugin_bundle.console.commands.bundle.bundle_command import BundleCommand

Expand All @@ -23,6 +24,11 @@ class BundleVenvCommand(BundleCommand):

options = [ # noqa: RUF012
*BundleCommand._group_dependency_options(),
*(
opt
for opt in InstallCommand.options
if opt.name in ("all-extras", "extras", "no-directory", "no-root")
),
option(
"python",
"p",
Expand All @@ -41,8 +47,21 @@ class BundleVenvCommand(BundleCommand):

bundler_name = "venv"

@property
def activated_extras(self) -> set[str]:
extras: set[str] = set()
# NOTE: simplified version of InstallCommand option handling
if self.option("all-extras"):
extras.update(self.poetry.package.extras)
for extra in self.option("extras", []):
extras.update(extra.split())
Comment on lines +54 to +57
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

poetry install does not accept both flags at the same time. Maybe, we should print the same error for consistency?

return extras

def configure_bundler(self, bundler: VenvBundler) -> None: # type: ignore[override]
bundler.set_path(Path(self.argument("path")))
bundler.set_executable(self.option("python"))
bundler.set_remove(self.option("clear"))
bundler.set_activated_groups(self.activated_groups)
bundler.set_extras(self.activated_extras)
bundler.set_no_directory(self.option("no-directory"))
bundler.set_no_root(self.option("no-root"))