Skip to content

Commit

Permalink
Improve the init layout to use dependency groups
Browse files Browse the repository at this point in the history
  • Loading branch information
sdispater committed Jul 7, 2021
1 parent 4a4c43f commit 6099eea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
11 changes: 8 additions & 3 deletions poetry/layouts/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
[tool.poetry.dependencies]
[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
"""

BUILD_SYSTEM_MIN_VERSION: Optional[str] = None
Expand Down Expand Up @@ -143,8 +143,13 @@ def generate_poetry_content(
for dep_name, dep_constraint in self._dependencies.items():
poetry_content["dependencies"][dep_name] = dep_constraint

for dep_name, dep_constraint in self._dev_dependencies.items():
poetry_content["dev-dependencies"][dep_name] = dep_constraint
if self._dev_dependencies:
for dep_name, dep_constraint in self._dev_dependencies.items():
poetry_content["group"]["dev"]["dependencies"][
dep_name
] = dep_constraint
else:
del poetry_content["group"]

# Add build system
build_system = table()
Expand Down
28 changes: 9 additions & 19 deletions tests/console/commands/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ def init_basic_toml():
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
[tool.poetry.dev-dependencies]
"""


Expand Down Expand Up @@ -143,7 +141,7 @@ def test_interactive_with_dependencies(tester, repo):
python = "~2.7 || ^3.6"
pendulum = "^2.0.0"
[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
pytest = "^3.6.0"
"""

Expand Down Expand Up @@ -175,8 +173,6 @@ def test_empty_license(tester):
[tool.poetry.dependencies]
python = "^{python}"
[tool.poetry.dev-dependencies]
""".format(
python=".".join(str(c) for c in sys.version_info[:2])
)
Expand Down Expand Up @@ -220,7 +216,7 @@ def test_interactive_with_git_dependencies(tester, repo):
python = "~2.7 || ^3.6"
demo = {git = "https://github.com/demo/demo.git"}
[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
pytest = "^3.6.0"
"""

Expand Down Expand Up @@ -264,7 +260,7 @@ def test_interactive_with_git_dependencies_with_reference(tester, repo):
python = "~2.7 || ^3.6"
demo = {git = "https://github.com/demo/demo.git", rev = "develop"}
[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
pytest = "^3.6.0"
"""

Expand Down Expand Up @@ -308,7 +304,7 @@ def test_interactive_with_git_dependencies_and_other_name(tester, repo):
python = "~2.7 || ^3.6"
demo = {git = "https://github.com/demo/pyproject-demo.git"}
[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
pytest = "^3.6.0"
"""

Expand Down Expand Up @@ -355,7 +351,7 @@ def test_interactive_with_directory_dependency(tester, repo, source_dir, fixture
python = "~2.7 || ^3.6"
demo = {path = "demo"}
[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
pytest = "^3.6.0"
"""
assert expected in tester.io.fetch_output()
Expand Down Expand Up @@ -403,7 +399,7 @@ def test_interactive_with_directory_dependency_and_other_name(
python = "~2.7 || ^3.6"
demo = {path = "pyproject-demo"}
[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
pytest = "^3.6.0"
"""

Expand Down Expand Up @@ -450,7 +446,7 @@ def test_interactive_with_file_dependency(tester, repo, source_dir, fixture_dir)
python = "~2.7 || ^3.6"
demo = {path = "demo-0.1.0-py2.py3-none-any.whl"}
[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
pytest = "^3.6.0"
"""

Expand Down Expand Up @@ -482,8 +478,6 @@ def test_python_option(tester):
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
[tool.poetry.dev-dependencies]
"""

assert expected in tester.io.fetch_output()
Expand Down Expand Up @@ -518,8 +512,6 @@ def test_predefined_dependency(tester, repo):
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
pendulum = "^2.0.0"
[tool.poetry.dev-dependencies]
"""

assert expected in tester.io.fetch_output()
Expand Down Expand Up @@ -596,7 +588,7 @@ def test_predefined_dev_dependency(tester, repo):
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
pytest = "^3.6.0"
"""

Expand Down Expand Up @@ -638,7 +630,7 @@ def test_predefined_and_interactive_dev_dependencies(tester, repo):
[tool.poetry.dependencies]
python = "~2.7 || ^3.6"
[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
pytest = "^3.6.0"
pytest-requests = "^0.2.0"
"""
Expand Down Expand Up @@ -705,8 +697,6 @@ def test_init_non_interactive_existing_pyproject_add_dependency(
[tool.poetry.dependencies]
python = "^3.6"
foo = "^1.19.2"
[tool.poetry.dev-dependencies]
"""
assert "{}\n{}".format(existing_section, expected) in pyproject_file.read_text()

Expand Down

0 comments on commit 6099eea

Please sign in to comment.