1
+ from inspect import cleandoc
2
+
1
3
import pytest
4
+ from jaraco import path
2
5
3
6
from setuptools .config .pyprojecttoml import apply_configuration
4
7
from setuptools .dist import Distribution
5
- from setuptools .tests .textwrap import DALS
6
8
7
9
8
10
def test_dynamic_dependencies (tmp_path ):
9
- (tmp_path / "requirements.txt" ).write_text ("six\n # comment\n " )
10
- pyproject = tmp_path / "pyproject.toml"
11
- pyproject .write_text (
12
- DALS (
11
+ files = {
12
+ "requirements.txt" : "six\n # comment\n " ,
13
+ "pyproject.toml" : cleandoc (
13
14
"""
14
- [project]
15
- name = "myproj"
16
- version = "1.0"
17
- dynamic = ["dependencies"]
15
+ [project]
16
+ name = "myproj"
17
+ version = "1.0"
18
+ dynamic = ["dependencies"]
18
19
19
- [build-system]
20
- requires = ["setuptools", "wheel"]
21
- build-backend = "setuptools.build_meta"
20
+ [build-system]
21
+ requires = ["setuptools", "wheel"]
22
+ build-backend = "setuptools.build_meta"
22
23
23
- [tool.setuptools.dynamic.dependencies]
24
- file = ["requirements.txt"]
25
- """
26
- )
27
- )
24
+ [tool.setuptools.dynamic.dependencies]
25
+ file = ["requirements.txt"]
26
+ """
27
+ ),
28
+ }
29
+ path .build (files , prefix = tmp_path )
28
30
dist = Distribution ()
29
- dist = apply_configuration (dist , pyproject )
31
+ dist = apply_configuration (dist , tmp_path / " pyproject.toml" )
30
32
assert dist .install_requires == ["six" ]
31
33
32
34
33
35
def test_dynamic_optional_dependencies (tmp_path ):
34
- (tmp_path / "requirements-docs.txt" ).write_text ("sphinx\n # comment\n " )
35
- pyproject = tmp_path / "pyproject.toml"
36
- pyproject .write_text (
37
- DALS (
36
+ files = {
37
+ "requirements-docs.txt" : "sphinx\n # comment\n " ,
38
+ "pyproject.toml" : cleandoc (
38
39
"""
39
- [project]
40
- name = "myproj"
41
- version = "1.0"
42
- dynamic = ["optional-dependencies"]
40
+ [project]
41
+ name = "myproj"
42
+ version = "1.0"
43
+ dynamic = ["optional-dependencies"]
43
44
44
- [tool.setuptools.dynamic.optional-dependencies.docs]
45
- file = ["requirements-docs.txt"]
45
+ [tool.setuptools.dynamic.optional-dependencies.docs]
46
+ file = ["requirements-docs.txt"]
46
47
47
- [build-system]
48
- requires = ["setuptools", "wheel"]
49
- build-backend = "setuptools.build_meta"
50
- """
51
- )
52
- )
48
+ [build-system]
49
+ requires = ["setuptools", "wheel"]
50
+ build-backend = "setuptools.build_meta"
51
+ """
52
+ ),
53
+ }
54
+ path .build (files , prefix = tmp_path )
53
55
dist = Distribution ()
54
- dist = apply_configuration (dist , pyproject )
56
+ dist = apply_configuration (dist , tmp_path / " pyproject.toml" )
55
57
assert dist .extras_require == {"docs" : ["sphinx" ]}
56
58
57
59
@@ -61,29 +63,32 @@ def test_mixed_dynamic_optional_dependencies(tmp_path):
61
63
configurations in the case of fields containing sub-fields (groups),
62
64
things would work out.
63
65
"""
64
- (tmp_path / "requirements-images.txt" ).write_text ("pillow~=42.0\n # comment\n " )
65
- pyproject = tmp_path / "pyproject.toml"
66
- pyproject .write_text (
67
- DALS (
66
+ files = {
67
+ "requirements-images.txt" : "pillow~=42.0\n # comment\n " ,
68
+ "pyproject.toml" : cleandoc (
68
69
"""
69
- [project]
70
- name = "myproj"
71
- version = "1.0"
72
- dynamic = ["optional-dependencies"]
70
+ [project]
71
+ name = "myproj"
72
+ version = "1.0"
73
+ dynamic = ["optional-dependencies"]
73
74
74
- [project.optional-dependencies]
75
- docs = ["sphinx"]
75
+ [project.optional-dependencies]
76
+ docs = ["sphinx"]
76
77
77
- [tool.setuptools.dynamic.optional-dependencies.images]
78
- file = ["requirements-images.txt"]
78
+ [tool.setuptools.dynamic.optional-dependencies.images]
79
+ file = ["requirements-images.txt"]
80
+
81
+ [build-system]
82
+ requires = ["setuptools", "wheel"]
83
+ build-backend = "setuptools.build_meta"
84
+ """
85
+ ),
86
+ }
87
+
88
+ path .build (files , prefix = tmp_path )
79
89
80
- [build-system]
81
- requires = ["setuptools", "wheel"]
82
- build-backend = "setuptools.build_meta"
83
- """
84
- )
85
- )
86
90
# Test that the mix-and-match doesn't currently validate.
91
+ pyproject = tmp_path / "pyproject.toml"
87
92
with pytest .raises (ValueError , match = "project.optional-dependencies" ):
88
93
apply_configuration (Distribution (), pyproject )
89
94
0 commit comments