Skip to content

Commit

Permalink
install: add warning if current project cannot be installed (#8369)
Browse files Browse the repository at this point in the history
  • Loading branch information
radoering authored Sep 11, 2023
1 parent 0bdb796 commit 144951f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
29 changes: 20 additions & 9 deletions src/poetry/console/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,6 @@ def handle(self) -> int:
if self.option("no-root"):
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

log_install = (
"<b>Installing</> the current project:"
f" <c1>{self.poetry.package.pretty_name}</c1>"
Expand All @@ -178,7 +170,26 @@ def handle(self) -> int:
self.line("")
return 0

builder.build()
# Prior to https://github.com/python-poetry/poetry-core/pull/629
# the existence of a module/package was checked when creating the
# EditableBuilder. Afterwards, the existence is checked after
# executing the build script (if there is one),
# i.e. during EditableBuilder.build().
try:
builder = EditableBuilder(self.poetry, self.env, self.io)
builder.build()
except (ModuleOrPackageNotFound, FileNotFoundError) as e:
# This is likely due to the fact that the project is an application
# not following the structure expected by Poetry.
# No need for an editable install in this case.
self.line("")
self.line_error(
f"The current project could not be installed: <error>{e}</error>\n"
"If you do not want to install the current project"
" use <c1>--no-root</c1>",
style="warning",
)
return 0

if overwrite:
self.overwrite(log_install.format(tag="success"))
Expand Down
37 changes: 34 additions & 3 deletions tests/console/commands/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"Python Poetry <tests@python-poetry.org>"
]
license = "MIT"
readme = "README.rst"
[tool.poetry.dependencies]
python = "~2.7 || ^3.4"
Expand Down Expand Up @@ -348,9 +347,9 @@ def test_remove_untracked_outputs_deprecation_warning(

assert tester.status_code == 0
assert (
tester.io.fetch_error()
== "The `--remove-untracked` option is deprecated, use the `--sync` option"
"The `--remove-untracked` option is deprecated, use the `--sync` option"
" instead.\n"
in tester.io.fetch_error()
)


Expand Down Expand Up @@ -417,6 +416,38 @@ def test_install_logs_output_decorated(
assert tester.io.fetch_output() == expected


@pytest.mark.parametrize("with_root", [True])
@pytest.mark.parametrize("error", ["module", "readme", ""])
def test_install_warning_corrupt_root(
command_tester_factory: CommandTesterFactory,
project_factory: ProjectFactory,
with_root: bool,
error: str,
) -> None:
name = "corrupt"
content = f"""\
[tool.poetry]
name = "{name}"
version = "1.2.3"
description = ""
authors = []
"""
if error == "readme":
content += 'readme = "missing_readme.md"\n'
poetry = project_factory(name=name, pyproject_content=content)
if error != "module":
(poetry.pyproject_path.parent / f"{name}.py").touch()

tester = command_tester_factory("install", poetry=poetry)
tester.execute("" if with_root else "--no-root")

assert tester.status_code == 0
if with_root and error:
assert "The current project could not be installed: " in tester.io.fetch_error()
else:
assert tester.io.fetch_error() == ""


@pytest.mark.parametrize("options", ["", "--without dev"])
@pytest.mark.parametrize(
"project", ["missing_directory_dependency", "missing_file_dependency"]
Expand Down

0 comments on commit 144951f

Please sign in to comment.