Skip to content

Commit 8b66b86

Browse files
committed
fix: do not ignore dynamic project dependencies via tool.poetry.dependencies if project.optional-dependencies are defined
1 parent 6243e3f commit 8b66b86

File tree

23 files changed

+290
-37
lines changed

23 files changed

+290
-37
lines changed

src/poetry/core/packages/dependency_group.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,20 @@ def name(self) -> str:
2626

2727
@property
2828
def dependencies(self) -> list[Dependency]:
29-
return self._dependencies or self._poetry_dependencies
29+
if not self._dependencies:
30+
return self._poetry_dependencies
31+
if self._poetry_dependencies:
32+
if all(dep.is_optional() for dep in self._dependencies):
33+
return [
34+
*self._dependencies,
35+
*(d for d in self._poetry_dependencies if not d.is_optional()),
36+
]
37+
if all(not dep.is_optional() for dep in self._dependencies):
38+
return [
39+
*self._dependencies,
40+
*(d for d in self._poetry_dependencies if d.is_optional()),
41+
]
42+
return self._dependencies
3043

3144
@property
3245
def dependencies_for_locking(self) -> list[Dependency]:
@@ -40,7 +53,7 @@ def dependencies_for_locking(self) -> list[Dependency]:
4053
poetry_dependencies_by_name[dep.name].append(dep)
4154

4255
dependencies = []
43-
for dep in self._dependencies:
56+
for dep in self.dependencies:
4457
if dep.name in poetry_dependencies_by_name:
4558
enriched = False
4659
dep_marker = dep.marker
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
My Package
2+
==========
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
[project]
2+
name = "my-package"
3+
version = "1.2.3"
4+
description = "Some description."
5+
readme = "README.rst"
6+
requires-python = ">=3.6"
7+
license = { text = "MIT" }
8+
keywords = ["packaging", "dependency", "poetry"]
9+
authors = [
10+
{ name = "Sébastien Eustace", email = "sebastien@eustace.io" }
11+
]
12+
maintainers = [
13+
{ name = "Sébastien Eustace", email = "sebastien@eustace.io" }
14+
]
15+
dynamic = [ "version", "readme", "dependencies", "classifiers" ]
16+
17+
[project.optional-dependencies]
18+
db = [
19+
"orator ~=0.9"
20+
]
21+
network = [
22+
"requests[security] ~=2.18"
23+
]
24+
25+
[project.urls]
26+
homepage = "https://python-poetry.org"
27+
repository = "https://github.com/python-poetry/poetry"
28+
documentation = "https://python-poetry.org/docs"
29+
30+
[project.scripts]
31+
my-script = "my_package:main"
32+
33+
[tool.poetry]
34+
version = "1.2.3"
35+
readme = "README.rst"
36+
classifiers = [
37+
"Topic :: Software Development :: Build Tools",
38+
"Topic :: Software Development :: Libraries :: Python Modules"
39+
]
40+
41+
# Requirements
42+
[tool.poetry.dependencies]
43+
python = ">=3.6"
44+
cleo = "^0.6"
45+
pendulum = { git = "https://github.com/sdispater/pendulum.git", branch = "2.0" }
46+
tomlkit = { git = "https://github.com/sdispater/tomlkit.git", rev = "3bff550", develop = true }
47+
pathlib2 = { version = "^2.2", python = "~2.7" }
48+
49+
# File dependency
50+
demo = { path = "../distributions/demo-0.1.0-py2.py3-none-any.whl" }
51+
52+
# Dir dependency with setup.py
53+
my-package = { path = "../project_with_setup/" }
54+
55+
# Dir dependency with pyproject.toml
56+
simple-project = { path = "../simple_project/" }
57+
58+
# Dependency with markers
59+
functools32 = { version = "^3.2.3", markers = "python_version ~= '2.7' and sys_platform == 'win32' or python_version in '3.4 3.5'" }
60+
61+
# Dependency with python constraint
62+
dataclasses = { version = "^0.7", python = ">=3.6.1,<3.7" }
63+
64+
65+
# Non-regression test for https://github.com/python-poetry/poetry-core/pull/492.
66+
# The underlying issue occurred because `tomlkit` can either return a TOML table as `Table` instance or an
67+
# `OutOfOrderProxy` one, if a table is discontinuous and multiple sections of a table are separated by a non-related
68+
# table, but we were too strict in our type check assertions.
69+
# So adding `tool.black` here ensure that we have discontinuous tables, so that we don't re-introduce the issue caused
70+
# by the type check assertion that ended up being reverted.
71+
[tool.black]
72+
preview = true
73+
74+
[tool.poetry.group.dev.dependencies]
75+
pytest = "~3.4"
76+
77+
78+
[tool.poetry.scripts]
79+
my-script = "my_package:main"
80+
81+
82+
[tool.poetry.plugins."blogtool.parsers"]
83+
".rst" = "some_module::SomeClass"

tests/masonry/builders/fixtures/complete_dynamic/AUTHORS

Whitespace-only changes.

tests/masonry/builders/fixtures/complete_dynamic/COPYING

Whitespace-only changes.

tests/masonry/builders/fixtures/complete_dynamic/LICENCE

Whitespace-only changes.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2018 Sébastien Eustace
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
My Package
2+
==========
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/usr/bin/env bash
2+
3+
echo "Hello World!"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "1.2.3"

0 commit comments

Comments
 (0)