Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1ec101c

Browse files
radoeringsdispater
andcommittedMay 19, 2024
add support for PEP 621): parse new fields (python-poetry#708)
- introduce schema for [project] section - soften schema for [tool.poetry] section so that there are no mandatory fields - deprecate fields in [tool.poetry] that can be completely replaced by fields in [project] - add possibility to add supplementary dependency information in [tool.poetry.dependencies] - add warnings for deprecated and duplicated fields in Factory.validate() Co-authored-by: Sébastien Eustace <[email protected]>
1 parent 94f933f commit 1ec101c

File tree

19 files changed

+1375
-268
lines changed

19 files changed

+1375
-268
lines changed
 

‎src/poetry/core/factory.py

+412-149
Large diffs are not rendered by default.

‎src/poetry/core/json/schemas/poetry-schema.json

+54-40
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,6 @@
33
"name": "Package",
44
"type": "object",
55
"additionalProperties": true,
6-
"anyOf": [
7-
{
8-
"required": [
9-
"package-mode"
10-
],
11-
"properties": {
12-
"package-mode": {
13-
"enum": [
14-
false
15-
]
16-
}
17-
}
18-
},
19-
{
20-
"required": [
21-
"name",
22-
"version",
23-
"description",
24-
"authors"
25-
]
26-
}
27-
],
286
"properties": {
297
"package-mode": {
308
"type": "boolean",
@@ -33,54 +11,56 @@
3311
},
3412
"name": {
3513
"type": "string",
36-
"description": "Package name."
14+
"description": "Package name (legacy)."
3715
},
3816
"version": {
3917
"type": "string",
40-
"description": "Package version."
18+
"description": "Package version (legacy)."
4119
},
4220
"description": {
4321
"type": "string",
44-
"description": "Short package description.",
22+
"description": "Short package description (legacy).",
4523
"pattern": "\\A[^\\n]*\\Z"
4624
},
4725
"keywords": {
4826
"type": "array",
4927
"items": {
5028
"type": "string",
51-
"description": "A tag/keyword that this package relates to."
29+
"description": "A tag/keyword that this package relates to (legacy)."
5230
}
5331
},
5432
"homepage": {
5533
"type": "string",
56-
"description": "Homepage URL for the project.",
34+
"description": "Homepage URL for the project (legacy).",
5735
"format": "uri"
5836
},
5937
"repository": {
6038
"type": "string",
61-
"description": "Repository URL for the project.",
39+
"description": "Repository URL for the project (legacy).",
6240
"format": "uri"
6341
},
6442
"documentation": {
6543
"type": "string",
66-
"description": "Documentation URL for the project.",
44+
"description": "Documentation URL for the project (legacy).",
6745
"format": "uri"
6846
},
6947
"license": {
7048
"type": "string",
71-
"description": "License name."
49+
"description": "License name (legacy)."
7250
},
7351
"authors": {
74-
"$ref": "#/definitions/authors"
52+
"$ref": "#/definitions/authors",
53+
"description": "Authors (legacy)."
7554
},
7655
"maintainers": {
77-
"$ref": "#/definitions/maintainers"
56+
"$ref": "#/definitions/maintainers",
57+
"description": "Maintainers (legacy)."
7858
},
7959
"readme": {
8060
"anyOf": [
8161
{
8262
"type": "string",
83-
"description": "The path to the README file."
63+
"description": "The path to the README file (legacy)."
8464
},
8565
{
8666
"type": "array",
@@ -93,7 +73,7 @@
9373
},
9474
"classifiers": {
9575
"type": "array",
96-
"description": "A list of trove classifiers."
76+
"description": "A list of trove classifiers (legacy)."
9777
},
9878
"packages": {
9979
"type": "array",
@@ -156,9 +136,6 @@
156136
"dependencies": {
157137
"type": "object",
158138
"description": "This is a hash of package name (keys) and version constraints (values) that are required to run this package.",
159-
"required": [
160-
"python"
161-
],
162139
"properties": {
163140
"python": {
164141
"type": "string",
@@ -176,6 +153,7 @@
176153
},
177154
"extras": {
178155
"type": "object",
156+
"description": "Extras (legacy).",
179157
"patternProperties": {
180158
"^[a-zA-Z-_.0-9]+$": {
181159
"type": "array",
@@ -250,22 +228,22 @@
250228
"patternProperties": {
251229
"^.+$": {
252230
"type": "string",
253-
"description": "The full url of the custom url."
231+
"description": "The full url of the custom url (Legacy)."
254232
}
255233
}
256234
}
257235
},
258236
"definitions": {
259237
"authors": {
260238
"type": "array",
261-
"description": "List of authors that contributed to the package. This is typically the main maintainers, not the full list.",
239+
"description": "List of authors that contributed to the package. This is typically the main maintainers, not the full list (legacy).",
262240
"items": {
263241
"type": "string"
264242
}
265243
},
266244
"maintainers": {
267245
"type": "array",
268-
"description": "List of maintainers, other than the original author(s), that upkeep the package.",
246+
"description": "List of maintainers, other than the original author(s), that upkeep the package (legacy).",
269247
"items": {
270248
"type": "string"
271249
}
@@ -321,6 +299,9 @@
321299
},
322300
{
323301
"$ref": "#/definitions/multiple-constraints-dependency"
302+
},
303+
{
304+
"$ref": "#/definitions/dependency-options"
324305
}
325306
]
326307
}
@@ -566,6 +547,36 @@
566547
}
567548
}
568549
},
550+
"dependency-options": {
551+
"type": "object",
552+
"additionalProperties": false,
553+
"properties": {
554+
"python": {
555+
"type": "string",
556+
"description": "The python versions for which the dependency should be installed."
557+
},
558+
"platform": {
559+
"type": "string",
560+
"description": "The platform(s) for which the dependency should be installed."
561+
},
562+
"markers": {
563+
"type": "string",
564+
"description": "The PEP 508 compliant environment markers for which the dependency should be installed."
565+
},
566+
"allow-prereleases": {
567+
"type": "boolean",
568+
"description": "Whether the dependency allows prereleases or not."
569+
},
570+
"source": {
571+
"type": "string",
572+
"description": "The exclusive source used to search for this dependency."
573+
},
574+
"develop": {
575+
"type": "boolean",
576+
"description": "Whether to install the dependency in development mode."
577+
}
578+
}
579+
},
569580
"multiple-constraints-dependency": {
570581
"type": "array",
571582
"minItems": 1,
@@ -588,6 +599,9 @@
588599
},
589600
{
590601
"$ref": "#/definitions/url-dependency"
602+
},
603+
{
604+
"$ref": "#/definitions/dependency-options"
591605
}
592606
]
593607
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"name": "Package",
4+
"type": "object",
5+
"additionalProperties": true,
6+
"required": [
7+
"name"
8+
],
9+
"properties": {
10+
"name": {
11+
"type": "string",
12+
"description": "The name of the project."
13+
},
14+
"version": {
15+
"type": "string",
16+
"description": "The version of the project."
17+
},
18+
"description": {
19+
"type": "string",
20+
"description": "The summary description of the project.",
21+
"pattern": "^[^\n]*$"
22+
},
23+
"readme": {
24+
"$ref": "#/definitions/readme",
25+
"description": "The full description of the project (i.e. the README)."
26+
},
27+
"requires-python": {
28+
"type": "string",
29+
"description": "The Python version requirements of the project."
30+
},
31+
"license": {
32+
"$ref": "#/definitions/license",
33+
"description": "The license of the project (file or string)."
34+
},
35+
"authors": {
36+
"$ref": "#/definitions/authors",
37+
"description": "The authors of the project."
38+
},
39+
"maintainers": {
40+
"$ref": "#/definitions/maintainers",
41+
"description": "The maintainers of the project."
42+
},
43+
"keywords": {
44+
"type": "array",
45+
"items": {
46+
"type": "string",
47+
"description": "A tag/keyword that this project relates to."
48+
}
49+
},
50+
"classifiers": {
51+
"type": "array",
52+
"description": "Trove classifiers which apply to the project."
53+
},
54+
"urls": {
55+
"type": "object",
56+
"patternProperties": {
57+
"^.+$": {
58+
"type": "string",
59+
"description": "The full url of the custom url."
60+
}
61+
}
62+
},
63+
"scripts": {
64+
"type": "object",
65+
"description": "Names and object references of console scripts.",
66+
"patternProperties": {
67+
"^[a-zA-Z-_.0-9]+$": {
68+
"type": "string"
69+
}
70+
}
71+
},
72+
"gui-scripts": {
73+
"type": "object",
74+
"description": "Names and object references of gui scripts.",
75+
"patternProperties": {
76+
"^[a-zA-Z-_.0-9]+$": {
77+
"type": "string"
78+
}
79+
}
80+
},
81+
"entry-points": {
82+
"type": "object",
83+
"description": "Entry point groups. Each group is like scripts or gui-scripts.",
84+
"patternProperties": {
85+
"^[a-zA-Z-_.0-9]+$": {
86+
"type": "object",
87+
"patternProperties": {
88+
"^[a-zA-Z-_.0-9]+$": {
89+
"type": "string"
90+
}
91+
}
92+
}
93+
}
94+
},
95+
"dependencies": {
96+
"type": "array",
97+
"description": "A list of runtime dependencies in the PEP 508 format.",
98+
"items": {
99+
"type": "string"
100+
}
101+
},
102+
"optional-dependencies": {
103+
"type": "object",
104+
"description": "Extras and their dependencies.",
105+
"patternProperties": {
106+
"^[a-zA-Z-_.0-9]+$": {
107+
"type": "array",
108+
"items": {
109+
"type": "string"
110+
}
111+
}
112+
}
113+
},
114+
"dynamic": {
115+
"type": "array",
116+
"description": "Keys that are defined dynamically or in a tool specific section.",
117+
"items": {
118+
"type": "string"
119+
}
120+
}
121+
},
122+
"definitions": {
123+
"license": {
124+
"oneOf": [
125+
{
126+
"type": "object",
127+
"additionalProperties": false,
128+
"properties": {
129+
"file": {
130+
"type": "string"
131+
}
132+
}
133+
},
134+
{
135+
"type": "object",
136+
"additionalProperties": false,
137+
"properties": {
138+
"text": {
139+
"type": "string"
140+
}
141+
}
142+
}
143+
]
144+
},
145+
"authors": {
146+
"type": "array",
147+
"description": "List of authors that contributed to the package. This is typically the main maintainers, not the full list.",
148+
"items": {
149+
"type": "object",
150+
"properties": {
151+
"name": {
152+
"type": "string"
153+
},
154+
"email": {
155+
"type": "string"
156+
}
157+
}
158+
}
159+
},
160+
"maintainers": {
161+
"type": "array",
162+
"description": "List of maintainers, other than the original author(s), that upkeep the package.",
163+
"items": {
164+
"type": "object",
165+
"properties": {
166+
"name": {
167+
"type": "string"
168+
},
169+
"email": {
170+
"type": "string"
171+
}
172+
}
173+
}
174+
},
175+
"readme": {
176+
"oneOf": [
177+
{
178+
"type": "string",
179+
"description": "Relative path to the README file"
180+
},
181+
{
182+
"oneOf": [
183+
{
184+
"type": "object",
185+
"description": "Readme with file and content type",
186+
"properties": {
187+
"file": {
188+
"type": "string",
189+
"description": "The relative path to the readme file"
190+
},
191+
"content-type": {
192+
"type": "string",
193+
"description": "The content type of the README file content"
194+
}
195+
}
196+
},
197+
{
198+
"type": "object",
199+
"description": "Readme with full description and content type",
200+
"properties": {
201+
"file": {
202+
"type": "string",
203+
"description": "The full content of the description"
204+
},
205+
"content-type": {
206+
"type": "string",
207+
"description": "The content type of the description"
208+
}
209+
}
210+
}
211+
]
212+
}
213+
]
214+
}
215+
}
216+
}

‎src/poetry/core/masonry/metadata.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@ def from_package(cls, package: Package) -> Metadata:
5454
meta.name = package.pretty_name
5555
meta.version = package.version.to_string()
5656
meta.summary = package.description
57-
if package.readmes:
57+
if package.readme_content:
58+
meta.description = package.readme_content
59+
elif package.readmes:
5860
descriptions = []
5961
for readme in package.readmes:
6062
with readme.open(encoding="utf-8") as f:
@@ -82,14 +84,16 @@ def from_package(cls, package: Package) -> Metadata:
8284
meta.requires_dist = [d.to_pep_508() for d in package.requires]
8385

8486
# Version 2.1
85-
if package.readmes:
87+
if package.readme_content_type:
88+
meta.description_content_type = package.readme_content_type
89+
elif package.readmes:
8690
meta.description_content_type = readme_content_type(package.readmes[0])
8791

8892
meta.provides_extra = list(package.extras)
8993

9094
if package.urls:
9195
for name, url in package.urls.items():
92-
if name == "Homepage" and meta.home_page == url:
96+
if name.lower() == "homepage" and meta.home_page == url:
9397
continue
9498

9599
meta.project_urls += (f"{name}, {url}",)

‎src/poetry/core/packages/package.py

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def __init__(
110110
self.keywords: Sequence[str] = []
111111
self._license: License | None = None
112112
self.readmes: tuple[Path, ...] = ()
113+
self.readme_content_type: str | None = None
114+
self.readme_content: str | None = None
113115

114116
self.extras: Mapping[NormalizedName, Sequence[Dependency]] = {}
115117

‎src/poetry/core/pyproject/toml.py

+12
Original file line numberDiff line numberDiff line change
@@ -74,4 +74,16 @@ def is_poetry_project(self) -> bool:
7474
_ = self.poetry_config
7575
return True
7676

77+
# Even if there is no [tool.poetry] section, a project can still be a
78+
# valid Poetry project if there is a name and a version in [project]
79+
# and there are no dynamic fields.
80+
with suppress(KeyError):
81+
project = self.data["project"]
82+
if (
83+
project["name"]
84+
and project["version"]
85+
and not project.get("dynamic")
86+
):
87+
return True
88+
7789
return False

‎tests/fixtures/complete.toml

+13-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ description = "Python dependency management and packaging made easy."
55
authors = [
66
"Sébastien Eustace <sebastien@eustace.io>"
77
]
8+
maintainers = [
9+
"Sébastien Eustace <sebastien@eustace.io>"
10+
]
811
license = "MIT"
912

1013
readme = "README.rst"
@@ -14,17 +17,21 @@ repository = "https://github.com/python-poetry/poetry"
1417
documentation = "https://python-poetry.org/docs"
1518

1619
keywords = ["packaging", "dependency", "poetry"]
20+
classifiers = [
21+
"Topic :: Software Development :: Build Tools",
22+
"Topic :: Software Development :: Libraries :: Python Modules"
23+
]
1724

1825
# Requirements
1926
[tool.poetry.dependencies]
20-
python = "~2.7 || ^3.2" # Compatible python versions must be declared here
27+
python = "^3.8" # Compatible python versions must be declared here
2128
toml = "^0.9"
2229
# Dependencies with extras
2330
requests = { version = "^2.13", extras = [ "security" ] }
2431
# Python specific dependencies with prereleases allowed
25-
pathlib2 = { version = "^2.2", python = "~2.7", allows-prereleases = true }
32+
pathlib2 = { version = "^2.2", python = "~3.8", allow-prereleases = true }
2633
# Git dependencies
27-
cleo = { git = "https://github.com/sdispater/cleo.git", branch = "master" }
34+
cleo = { git = "https://github.com/sdispater/cleo.git", branch = "main" }
2835

2936
# Optional dependencies (extras)
3037
pendulum = { version = "^1.4", optional = true }
@@ -41,6 +48,9 @@ my-script = 'my_package:main'
4148
sample_pyscript = { reference = "script-files/sample_script.py", type= "file" }
4249
sample_shscript = { reference = "script-files/sample_script.sh", type= "file" }
4350

51+
[tool.poetry.plugins."poetry.application.plugin"]
52+
my-command = "my_package.plugins:MyApplicationPlugin"
53+
4454

4555
[[tool.poetry.source]]
4656
name = "foo"
+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
[project]
2+
name = "poetry"
3+
version = "0.5.0"
4+
description = "Python dependency management and packaging made easy."
5+
readme = "README.rst"
6+
requires-python = ">=3.8"
7+
license = { "text" = "MIT" }
8+
authors = [
9+
{ "name" = "Sébastien Eustace", "email" = "sebastien@eustace.io" }
10+
]
11+
maintainers = [
12+
{ name = "Sébastien Eustace", email = "sebastien@eustace.io" }
13+
]
14+
keywords = ["packaging", "dependency", "poetry"]
15+
classifiers = [
16+
"Topic :: Software Development :: Build Tools",
17+
"Topic :: Software Development :: Libraries :: Python Modules"
18+
]
19+
dependencies = [
20+
"toml>=0.9",
21+
"requests[security]>=2.13,<3.0",
22+
"pathlib2 ~=2.2 ; python_version == '3.8'",
23+
"cleo @ git+https://github.com/sdispater/cleo.git@main",
24+
]
25+
26+
[project.urls]
27+
homepage = "https://python-poetry.org/"
28+
repository = "https://github.com/python-poetry/poetry"
29+
documentation = "https://python-poetry.org/docs"
30+
31+
[project.optional-dependencies]
32+
time = [ "pendulum>1.4,<2.0" ]
33+
34+
[project.scripts]
35+
my-script = "my_package:main"
36+
37+
[project.entry-points."poetry.application.plugin"]
38+
my-command = "my_package.plugins:MyApplicationPlugin"
39+
40+
[tool.poetry]
41+
name = "poetry"
42+
version = "0.5.0"
43+
description = "Python dependency management and packaging made easy."
44+
authors = [
45+
"Sébastien Eustace <sebastien@eustace.io>"
46+
]
47+
maintainers = [
48+
"Sébastien Eustace <sebastien@eustace.io>"
49+
]
50+
license = "MIT"
51+
52+
readme = "README.rst"
53+
54+
homepage = "https://python-poetry.org/"
55+
repository = "https://github.com/python-poetry/poetry"
56+
documentation = "https://python-poetry.org/docs"
57+
58+
keywords = ["packaging", "dependency", "poetry"]
59+
classifiers = [
60+
"Topic :: Software Development :: Build Tools",
61+
"Topic :: Software Development :: Libraries :: Python Modules"
62+
]
63+
64+
# Requirements
65+
[tool.poetry.dependencies]
66+
python = "^3.8" # Compatible python versions must be declared here
67+
toml = "^0.9"
68+
# Dependencies with extras
69+
requests = { version = "^2.13", extras = [ "security" ] }
70+
# Python specific dependencies with prereleases allowed
71+
pathlib2 = { version = "^2.2", python = "~3.8", allow-prereleases = true }
72+
# Git dependencies
73+
cleo = { git = "https://github.com/sdispater/cleo.git", branch = "master" }
74+
75+
# Optional dependencies (extras)
76+
pendulum = { version = "^1.4", optional = true }
77+
78+
[tool.poetry.extras]
79+
time = [ "pendulum" ]
80+
81+
[tool.poetry.dev-dependencies]
82+
pytest = "^3.0"
83+
pytest-cov = "^2.4"
84+
85+
[tool.poetry.scripts]
86+
my-script = 'my_package:main'
87+
sample_pyscript = { reference = "script-files/sample_script.py", type= "file" }
88+
sample_shscript = { reference = "script-files/sample_script.sh", type= "file" }
89+
90+
[tool.poetry.plugins."poetry.application.plugin"]
91+
my-command = "my_package.plugins:MyApplicationPlugin"
92+
93+
94+
[[tool.poetry.source]]
95+
name = "foo"
96+
url = "https://bar.com"

‎tests/fixtures/complete_new.toml

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
[project]
2+
name = "poetry"
3+
version = "0.5.0"
4+
description = "Python dependency management and packaging made easy."
5+
readme = "README.rst"
6+
requires-python = ">=3.8"
7+
license = { "text" = "MIT" }
8+
authors = [
9+
{ "name" = "Sébastien Eustace", "email" = "sebastien@eustace.io" }
10+
]
11+
maintainers = [
12+
{ name = "Sébastien Eustace", email = "sebastien@eustace.io" }
13+
]
14+
keywords = ["packaging", "dependency", "poetry"]
15+
classifiers = [
16+
"Topic :: Software Development :: Build Tools",
17+
"Topic :: Software Development :: Libraries :: Python Modules"
18+
]
19+
dependencies = [
20+
"toml>=0.9",
21+
"requests[security]>=2.13,<3.0",
22+
"pathlib2 ~=2.2 ; python_version == '3.8'",
23+
"cleo @ git+https://github.com/sdispater/cleo.git@main",
24+
]
25+
26+
[project.urls]
27+
homepage = "https://python-poetry.org/"
28+
repository = "https://github.com/python-poetry/poetry"
29+
documentation = "https://python-poetry.org/docs"
30+
31+
[project.optional-dependencies]
32+
time = [ "pendulum>1.4,<2.0" ]
33+
34+
[project.scripts]
35+
my-script = "my_package:main"
36+
37+
[project.entry-points."poetry.application.plugin"]
38+
my-command = "my_package.plugins:MyApplicationPlugin"
39+
40+
# Requirements
41+
[tool.poetry.dependencies]
42+
python = "^3.8" # Compatible python versions must be declared here
43+
toml = "^0.9"
44+
# Dependencies with extras
45+
requests = { version = "^2.13", extras = [ "security" ] }
46+
# Python specific dependencies with prereleases allowed
47+
pathlib2 = { version = "^2.2", python = "~3.8", allow-prereleases = true }
48+
# Git dependencies
49+
cleo = { git = "https://github.com/sdispater/cleo.git", branch = "master" }
50+
51+
[tool.poetry.dev-dependencies]
52+
pytest = "^3.0"
53+
pytest-cov = "^2.4"
54+
55+
[tool.poetry.scripts]
56+
sample_pyscript = { reference = "script-files/sample_script.py", type= "file" }
57+
sample_shscript = { reference = "script-files/sample_script.sh", type= "file" }
58+
59+
60+
[[tool.poetry.source]]
61+
name = "foo"
62+
url = "https://bar.com"
+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
[project]
2+
dynamic = [
3+
"name",
4+
"version",
5+
"description",
6+
"readme",
7+
"requires-python",
8+
"license",
9+
"authors",
10+
"maintainers",
11+
"keywords",
12+
"classifiers",
13+
"urls",
14+
"dependencies",
15+
"optional-dependencies",
16+
"scripts",
17+
]
18+
19+
[tool.poetry]
20+
name = "poetry"
21+
version = "0.5.0"
22+
description = "Python dependency management and packaging made easy."
23+
authors = [
24+
"Sébastien Eustace <sebastien@eustace.io>"
25+
]
26+
maintainers = [
27+
"Sébastien Eustace <sebastien@eustace.io>"
28+
]
29+
license = "MIT"
30+
31+
readme = "README.rst"
32+
33+
homepage = "https://python-poetry.org/"
34+
repository = "https://github.com/python-poetry/poetry"
35+
documentation = "https://python-poetry.org/docs"
36+
37+
keywords = ["packaging", "dependency", "poetry"]
38+
classifiers = [
39+
"Topic :: Software Development :: Build Tools",
40+
"Topic :: Software Development :: Libraries :: Python Modules"
41+
]
42+
43+
# Requirements
44+
[tool.poetry.dependencies]
45+
python = "^3.8" # Compatible python versions must be declared here
46+
toml = "^0.9"
47+
# Dependencies with extras
48+
requests = { version = "^2.13", extras = [ "security" ] }
49+
# Python specific dependencies with prereleases allowed
50+
pathlib2 = { version = "^2.2", python = "~3.8", allow-prereleases = true }
51+
# Git dependencies
52+
cleo = { git = "https://github.com/sdispater/cleo.git", branch = "master" }
53+
54+
# Optional dependencies (extras)
55+
pendulum = { version = "^1.4", optional = true }
56+
57+
[tool.poetry.extras]
58+
time = [ "pendulum" ]
59+
60+
[tool.poetry.dev-dependencies]
61+
pytest = "^3.0"
62+
pytest-cov = "^2.4"
63+
64+
[tool.poetry.scripts]
65+
my-script = 'my_package:main'
66+
sample_pyscript = { reference = "script-files/sample_script.py", type= "file" }
67+
sample_shscript = { reference = "script-files/sample_script.sh", type= "file" }
68+
69+
[project.entry-points."poetry.application.plugin"]
70+
my-command = "my_package.plugins:MyApplicationPlugin"
71+
72+
73+
[[tool.poetry.source]]
74+
name = "foo"
75+
url = "https://bar.com"

‎tests/fixtures/invalid_pyproject/pyproject.toml

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
[tool.poetry]
2-
name = "invalid"
3-
version = "1.0.0"
4-
authors = [
5-
"Foo <foo@bar.com>"
6-
]
7-
license = "INVALID"
2+
# name missing
3+
# version missing
84

95
[tool.poetry.dependencies]
106
python = "*"

‎tests/fixtures/sample_project/pyproject.toml

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ description = "Some description."
55
authors = [
66
"Sébastien Eustace <sebastien@eustace.io>"
77
]
8+
maintainers = [
9+
"Sébastien Eustace <sebastien@eustace.io>"
10+
]
811
license = "MIT"
912

1013
readme = "README.rst"
@@ -22,11 +25,11 @@ classifiers = [
2225

2326
# Requirements
2427
[tool.poetry.dependencies]
25-
python = "~2.7 || ^3.6"
28+
python = ">=3.6"
2629
cleo = "^0.6"
2730
pendulum = { git = "https://github.com/sdispater/pendulum.git", branch = "2.0" }
2831
tomlkit = { git = "https://github.com/sdispater/tomlkit.git", rev = "3bff550", develop = false }
29-
requests = { version = "^2.18", optional = true, extras=[ "security" ] }
32+
requests = { version = "^2.18", optional = true, extras = [ "security" ] }
3033
pathlib2 = { version = "^2.2", python = "~2.7" }
3134

3235
orator = { version = "^0.9", optional = true }
@@ -44,11 +47,12 @@ simple-project = { path = "../simple_project/" }
4447
functools32 = { version = "^3.2.3", markers = "python_version ~= '2.7' and sys_platform == 'win32' or python_version in '3.4 3.5'" }
4548

4649
# Dependency with python constraint
47-
dataclasses = {version = "^0.7", python = ">=3.6.1,<3.7"}
50+
dataclasses = { version = "^0.7", python = ">=3.6.1,<3.7" }
4851

4952

5053
[tool.poetry.extras]
5154
db = [ "orator" ]
55+
network = [ "requests" ]
5256

5357
# Non-regression test for https://github.com/python-poetry/poetry-core/pull/492.
5458
# The underlying issue occurred because `tomlkit` can either return a TOML table as `Table` instance or an
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
My Package
2+
==========
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
16+
classifiers = [
17+
"Topic :: Software Development :: Build Tools",
18+
"Topic :: Software Development :: Libraries :: Python Modules"
19+
]
20+
21+
# Requirements
22+
dependencies = [
23+
"cleo ~=0.6",
24+
"pendulum @ git+https://github.com/sdispater/pendulum.git@2.0",
25+
"tomlkit @ git+https://github.com/sdispater/tomlkit.git@3bff550",
26+
"pathlib2 ~=2.2 ; python_version == '2.7'",
27+
# File dependency
28+
"demo @ ../distributions/demo-0.1.0-py2.py3-none-any.whl",
29+
# Dir dependency with setup.py
30+
"my-package @ ../project_with_setup/",
31+
# Dir dependency with pyproject.toml
32+
"simple-project @ ../simple_project/",
33+
# Dependency with markers
34+
"functools32 ~=3.2.3 ; python_version ~= '2.7' and sys_platform == 'win32' or python_version in '3.4 3.5'",
35+
# Dependency with python constraint
36+
"dataclasses ~=0.7 ; python_full_version >= '3.6.1' and python_version < '3.7'"
37+
]
38+
39+
[project.optional-dependencies]
40+
db = [
41+
"orator ~=0.9"
42+
]
43+
network = [
44+
"requests[security] ~=2.18"
45+
]
46+
47+
[project.urls]
48+
homepage = "https://python-poetry.org"
49+
repository = "https://github.com/python-poetry/poetry"
50+
documentation = "https://python-poetry.org/docs"
51+
52+
[project.scripts]
53+
my-script = "my_package:main"
54+
55+
[project.entry-points."blogtool.parsers"]
56+
".rst" = "some_module::SomeClass"
57+
58+
[tool.poetry.dependencies]
59+
tomlkit = { develop = true }
60+
61+
[tool.poetry.group.dev.dependencies]
62+
pytest = "~3.4"
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
[tool.poetry]
1+
[project]
22
name = "my-package"
33
version = "0.1"
4-
description = "Some description."
5-
authors = [
6-
"Wagner Macedo <wagnerluis1982@gmail.com>"
7-
]
8-
license = "MIT"
4+
dynamic = ["readme"]
95

6+
[tool.poetry]
107
readme = [
118
"README-1.rst",
129
"README-2.rst"
1310
]
14-
15-
homepage = "https://python-poetry.org/"
16-
17-
18-
[tool.poetry.dependencies]
19-
python = "^2.7"

‎tests/json/test_poetry_schema.py

-16
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,6 @@ def multi_url_object() -> dict[str, Any]:
3939
}
4040

4141

42-
@pytest.mark.parametrize("explicit", [True, False])
43-
@pytest.mark.parametrize(
44-
"missing_required", ["", "name", "version", "description", "authors"]
45-
)
46-
def test_package_mode(
47-
base_object: dict[str, Any], explicit: bool, missing_required: str
48-
) -> None:
49-
if explicit:
50-
base_object["package-mode"] = True
51-
if missing_required:
52-
del base_object[missing_required]
53-
assert len(validate_object(base_object, "poetry-schema")) == 1
54-
else:
55-
assert len(validate_object(base_object, "poetry-schema")) == 0
56-
57-
5842
def test_non_package_mode_no_metadata() -> None:
5943
assert len(validate_object({"package-mode": False}, "poetry-schema")) == 0
6044

‎tests/pyproject/conftest.py

+25
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,28 @@ def poetry_section(pyproject_toml: Path) -> str:
4141
with pyproject_toml.open(mode="a", encoding="utf-8") as f:
4242
f.write(content)
4343
return content
44+
45+
46+
@pytest.fixture
47+
def project_section(pyproject_toml: Path) -> str:
48+
content = """
49+
[project]
50+
name = "poetry"
51+
version = "1.0.0"
52+
"""
53+
with pyproject_toml.open(mode="a", encoding="utf-8") as f:
54+
f.write(content)
55+
return content
56+
57+
58+
@pytest.fixture
59+
def project_section_dynamic(pyproject_toml: Path) -> str:
60+
content = """
61+
[project]
62+
name = "not-poetry"
63+
version = "1.0.0"
64+
dynamic = ["description"]
65+
"""
66+
with pyproject_toml.open(mode="a", encoding="utf-8") as f:
67+
f.write(content)
68+
return content

‎tests/pyproject/test_pyproject_toml.py

+30
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,36 @@ def test_pyproject_toml_no_poetry_config(pyproject_toml: Path) -> None:
3030
)
3131

3232

33+
def test_pyproject_toml_no_poetry_config_but_project_section(
34+
pyproject_toml: Path, project_section: str
35+
) -> None:
36+
pyproject = PyProjectTOML(pyproject_toml)
37+
38+
assert pyproject.is_poetry_project()
39+
40+
with pytest.raises(PyProjectException) as excval:
41+
_ = pyproject.poetry_config
42+
43+
assert f"[tool.poetry] section not found in {pyproject_toml.as_posix()}" in str(
44+
excval.value
45+
)
46+
47+
48+
def test_pyproject_toml_no_poetry_config_but_project_section_but_dynamic(
49+
pyproject_toml: Path, project_section_dynamic: str
50+
) -> None:
51+
pyproject = PyProjectTOML(pyproject_toml)
52+
53+
assert not pyproject.is_poetry_project()
54+
55+
with pytest.raises(PyProjectException) as excval:
56+
_ = pyproject.poetry_config
57+
58+
assert f"[tool.poetry] section not found in {pyproject_toml.as_posix()}" in str(
59+
excval.value
60+
)
61+
62+
3363
def test_pyproject_toml_poetry_config(
3464
pyproject_toml: Path, poetry_section: str
3565
) -> None:

‎tests/test_factory.py

+295-36
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.