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

Allow root package non-editable installation #5174

Closed
wants to merge 5 commits into from
Closed
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
7 changes: 7 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ poetry install --no-root
Installation of your project's package is also skipped when the `--only`
option is used.

If you do not want to install the current project in [editable](https://pip.pypa.io/en/stable/cli/pip_install/#install-editable) mode, run the `install` command with the `--no-editable` flag:

```bash
poetry install --no-editable
```

### Options

* `--without`: The dependency groups to ignore for installation.
Expand All @@ -223,6 +229,7 @@ option is used.
* `--no-root`: Do not install the root package (your project).
* `--dry-run`: Output the operations but do not execute anything (implicitly enables --verbose).
* `--extras (-E)`: Features to install (multiple values allowed).
* `--no-editable`: Do not install the root package in editable mode.
* `--no-dev`: Do not install dev dependencies. (**Deprecated**)
* `--dev-only`: Only install dev dependencies. (**Deprecated**)
* `--remove-untracked`: Remove dependencies not presented in the lock file. (**Deprecated**)
Expand Down
37 changes: 29 additions & 8 deletions src/poetry/console/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ class InstallCommand(InstallerCommand):
flag=False,
multiple=True,
),
option(
"--no-editable",
None,
"Do not install the root package in editable mode.",
flag=True,
),
]

help = """The <info>install</info> command reads the <comment>poetry.lock</> file from
Expand All @@ -89,9 +95,11 @@ class InstallCommand(InstallerCommand):
_loggers = ["poetry.repositories.pypi_repository", "poetry.inspection.info"]

def handle(self) -> int:
from poetry.core.masonry.builders.sdist import SdistBuilder
from poetry.core.masonry.utils.module import ModuleOrPackageNotFound

from poetry.masonry.builders import EditableBuilder
from poetry.utils.pip import pip_install

self._installer.use_executor(
self.poetry.config.get("experimental.new-installer", False)
Expand Down Expand Up @@ -174,13 +182,17 @@ def handle(self) -> int:
if self.option("no-root") or self.option("only"):
return 0

try:
builder = EditableBuilder(self.poetry, self._env, self._io)
except ModuleOrPackageNotFound:
# This is likely due to the fact that the project is an application
# not following the structure expected by Poetry
# If this is a true error it will be picked up later by build anyway.
return 0
if self.option("no-editable"):
builder = SdistBuilder(self.poetry)
else:
try:
builder = EditableBuilder(self.poetry, self._env, self._io)
except ModuleOrPackageNotFound:
# This is likely due to the fact that the project is an
# application not following the structure expected by Poetry
# If this is a true error it will be picked up later by build
# anyway.
return 0

log_install = (
"<b>Installing</> the current project:"
Expand All @@ -197,7 +209,16 @@ def handle(self) -> int:
self.line("")
return 0

builder.build()
if self.option("no-editable"):
with builder.setup_py():
pip_install(
path=self.poetry.package.root_dir,
environment=self._env,
deps=False,
upgrade=True,
)
else:
builder.build()

if overwrite:
self.overwrite(log_install.format(tag="success"))
Expand Down
19 changes: 19 additions & 0 deletions tests/console/commands/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,22 @@ def test_sync_option_is_passed_to_the_installer(
tester.execute("--sync")

assert tester.command.installer._requires_synchronization


def test_no_editable_option(tester: "CommandTester", mocker: "MockerFixture"):
mocker.patch.object(tester.command.installer, "run", return_value=0)
pip_install_mock = mocker.patch("poetry.utils.pip.pip_install")
builder_mock = mocker.patch("poetry.core.masonry.builders.sdist.SdistBuilder")
editable_builder_mock = mocker.patch("poetry.masonry.builders.EditableBuilder")

tester.execute("--no-editable")

pip_install_mock.assert_called_once_with(
path=tester.command.poetry.package.root_dir,
environment=tester.command.env,
deps=False,
upgrade=True,
)
builder_mock.assert_called_once_with(tester.command.poetry)
builder_mock.return_value.setup_py.assert_called_once()
editable_builder_mock.assert_not_called()