File tree Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Expand file tree Collapse file tree 3 files changed +52
-1
lines changed Original file line number Diff line number Diff line change @@ -95,7 +95,11 @@ def from_package(cls, package: ProjectPackage) -> Metadata:
95
95
elif package .python_versions != "*" :
96
96
meta .requires_python = format_python_constraint (package .python_constraint )
97
97
98
- meta .requires_dist = [d .to_pep_508 () for d in package .requires ]
98
+ meta .requires_dist = [
99
+ d .to_pep_508 ()
100
+ for d in package .requires
101
+ if not d .is_optional () or d .in_extras
102
+ ]
99
103
100
104
# Version 2.1
101
105
if package .readme_content_type :
Original file line number Diff line number Diff line change
1
+ [project ]
2
+ name = " my-packager"
3
+ description = " Something"
4
+ version = " 0.1"
5
+ classifiers = [
6
+ " Topic :: Software Development :: Build Tools" ,
7
+ " Topic :: Software Development :: Libraries :: Python Modules"
8
+ ]
9
+ dynamic = [" dependencies" ]
10
+
11
+ [tool .poetry .dependencies ]
12
+ requests = { version = " ^0.28.1" , optional = true }
13
+ httpx = { version = " ^0.28.1" , optional = true }
14
+ grpcio = { version = " ^0.2.0" }
15
+ pycowsay = { version = " ^0.1.0" }
16
+
17
+ [tool .poetry .extras ]
18
+ http = [" httpx" ]
19
+ grpc = [" grpcio" ]
Original file line number Diff line number Diff line change @@ -313,6 +313,34 @@ def test_prepare_metadata_for_build_wheel_with_local_version() -> None:
313
313
assert f .read () == metadata
314
314
315
315
316
+ def test_prepare_metadata_excludes_optional_without_extras () -> None :
317
+ with (
318
+ temporary_directory () as tmp_dir ,
319
+ cwd (fixtures / "with_optional_without_extras" ),
320
+ ):
321
+ dirname = api .prepare_metadata_for_build_wheel (str (tmp_dir ))
322
+ dist_info = Path (tmp_dir , dirname )
323
+ assert (dist_info / "METADATA" ).exists ()
324
+
325
+ with (dist_info / "METADATA" ).open (encoding = "utf-8" ) as f :
326
+ assert (
327
+ f .read ()
328
+ == """\
329
+ Metadata-Version: 2.3
330
+ Name: my-packager
331
+ Version: 0.1
332
+ Summary: Something
333
+ Classifier: Topic :: Software Development :: Build Tools
334
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
335
+ Provides-Extra: grpc
336
+ Provides-Extra: http
337
+ Requires-Dist: grpcio (>=0.2.0,<0.3.0) ; extra == "grpc"
338
+ Requires-Dist: httpx (>=0.28.1,<0.29.0) ; extra == "http"
339
+ Requires-Dist: pycowsay (>=0.1.0,<0.2.0)
340
+ """
341
+ )
342
+
343
+
316
344
def test_prepare_metadata_for_build_wheel_with_bad_path_dev_dep_succeeds () -> None :
317
345
with temporary_directory () as tmp_dir , cwd (fixtures / "with_bad_path_dev_dep" ):
318
346
api .prepare_metadata_for_build_wheel (str (tmp_dir ))
You can’t perform that action at this time.
0 commit comments