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

Remove package pyproject line if package is module to resolve #7609 #8218

Merged
merged 6 commits into from
Aug 1, 2023
Merged
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
2 changes: 1 addition & 1 deletion src/poetry/layouts/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def get_package_include(self) -> InlineTable | None:
if self.basedir != Path():
package.append("from", self.basedir.as_posix())
else:
if include == self._project:
if module_name(self._project) == include:
# package include and package name are the same,
# packages table is redundant here.
return None
Expand Down
23 changes: 4 additions & 19 deletions tests/console/commands/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from cleo.testers.command_tester import CommandTester
from packaging.utils import canonicalize_name
from poetry.core.utils.helpers import module_name

from poetry.console.application import Application
from poetry.console.commands.init import InitCommand
Expand Down Expand Up @@ -86,7 +87,6 @@ def init_basic_toml() -> str:
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -169,7 +169,6 @@ def test_interactive_with_dependencies(
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -218,7 +217,6 @@ def test_interactive_with_dependencies_and_no_selection(
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -249,7 +247,6 @@ def test_empty_license(tester: CommandTester) -> None:
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"
packages = [{{include = "my_package"}}]

[tool.poetry.dependencies]
python = "^{python}"
Expand Down Expand Up @@ -290,7 +287,6 @@ def test_interactive_with_git_dependencies(
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -383,7 +379,6 @@ def test_interactive_with_git_dependencies_with_reference(
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -429,7 +424,6 @@ def test_interactive_with_git_dependencies_and_other_name(
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -481,7 +475,6 @@ def test_interactive_with_directory_dependency(
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -532,7 +525,6 @@ def test_interactive_with_directory_dependency_and_other_name(
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -584,7 +576,6 @@ def test_interactive_with_file_dependency(
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -629,7 +620,6 @@ def test_interactive_with_wrong_dependency_inputs(
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "^3.8"
Expand Down Expand Up @@ -664,7 +654,6 @@ def test_python_option(tester: CommandTester) -> None:
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -697,7 +686,6 @@ def test_predefined_dependency(tester: CommandTester, repo: TestRepository) -> N
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -739,7 +727,6 @@ def test_predefined_and_interactive_dependencies(
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -775,7 +762,6 @@ def test_predefined_dev_dependency(tester: CommandTester, repo: TestRepository)
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -819,7 +805,6 @@ def test_predefined_and_interactive_dev_dependencies(
authors = ["Your Name <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
Expand Down Expand Up @@ -866,7 +851,6 @@ def test_predefined_all_options(tester: CommandTester, repo: TestRepository) ->
authors = ["Foo Bar <[email protected]>"]
license = "MIT"
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "^3.8"
Expand Down Expand Up @@ -959,7 +943,6 @@ def test_init_non_interactive_existing_pyproject_add_dependency(
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"
packages = [{include = "my_package"}]

[tool.poetry.dependencies]
python = "^3.6"
Expand Down Expand Up @@ -1043,7 +1026,9 @@ def test_package_include(
),
)

packages = "" if include is None else f'packages = [{{include = "{include}"}}]\n'
packages = ""
if include and module_name(package_name) != include:
packages = f'packages = [{{include = "{include}"}}]\n'

expected = (
f"[tool.poetry]\n"
Expand Down
5 changes: 4 additions & 1 deletion tests/console/commands/test_new.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import pytest

from poetry.core.utils.helpers import module_name

from poetry.factory import Factory


Expand Down Expand Up @@ -55,10 +57,11 @@ def verify_project_directory(
else:
package_include = {"include": package_path.parts[0]}

name = poetry.local_config.get("name", "")
packages = poetry.local_config.get("packages")

if not packages:
assert poetry.local_config.get("name") == package_include.get("include")
wdonofrio marked this conversation as resolved.
Show resolved Hide resolved
assert module_name(name) == package_include.get("include")
else:
assert len(packages) == 1
assert packages[0] == package_include
Expand Down
Loading