diff --git a/src/poetry_plugin_bundle/bundlers/venv_bundler.py b/src/poetry_plugin_bundle/bundlers/venv_bundler.py index 2abb1c5..91db630 100644 --- a/src/poetry_plugin_bundle/bundlers/venv_bundler.py +++ b/src/poetry_plugin_bundle/bundlers/venv_bundler.py @@ -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 @@ -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 @@ -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() @@ -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}: Installing {poetry.package.pretty_name}" diff --git a/src/poetry_plugin_bundle/console/commands/bundle/venv.py b/src/poetry_plugin_bundle/console/commands/bundle/venv.py index 514f8a7..31b75fd 100644 --- a/src/poetry_plugin_bundle/console/commands/bundle/venv.py +++ b/src/poetry_plugin_bundle/console/commands/bundle/venv.py @@ -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 @@ -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", @@ -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()) + 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"))