test_pyprojecttoml_dynamic_deps.py 3.2 KB

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