Skip to content

Commit e14cfec

Browse files
authored
Allow user to skip validation of pyproject.toml via env var (#4611)
2 parents 8d518af + b7f7768 commit e14cfec

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

newsfragments/4611.feature.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Added support for the environment variable
2+
``SETUPTOOLS_DANGEROUSLY_SKIP_PYPROJECT_VALIDATION=true``, allowing users to bypass
3+
the validation of ``pyproject.toml``.
4+
This option should be used only as a last resort when resolving dependency
5+
issues, as it may lead to improper functioning.
6+
Users who enable this setting are responsible for ensuring that ``pyproject.toml``
7+
complies with setuptools requirements.

setuptools/config/pyprojecttoml.py

+13
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ def load_file(filepath: StrPath) -> dict:
4141

4242

4343
def validate(config: dict, filepath: StrPath) -> bool:
44+
skip = os.getenv("SETUPTOOLS_DANGEROUSLY_SKIP_PYPROJECT_VALIDATION", "false")
45+
if skip.lower() == "true": # https://github.com/pypa/setuptools/issues/4459
46+
SetuptoolsWarning.emit(
47+
"Skipping the validation of `pyproject.toml`.",
48+
"""
49+
Please note that some setuptools functionalities rely on the validation of
50+
`pyproject.toml` against misconfiguration to ensure proper operation.
51+
By skipping the automatic checks, you taking responsibility for making sure
52+
the file is valid. Otherwise unexpected behaviours may occur.
53+
""",
54+
)
55+
return True
56+
4457
from . import _validate_pyproject as validator
4558

4659
trove_classifier = validator.FORMAT_FUNCTIONS.get("trove-classifier")

setuptools/tests/config/test_pyprojecttoml.py

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
)
1818
from setuptools.dist import Distribution
1919
from setuptools.errors import OptionError
20+
from setuptools.warnings import SetuptoolsWarning
2021

2122
import distutils.core
2223

@@ -394,3 +395,9 @@ def test_warn_tools_typo(tmp_path):
394395

395396
with pytest.warns(_ToolsTypoInMetadata):
396397
read_configuration(pyproject)
398+
399+
400+
def test_warn_skipping_validation(monkeypatch):
401+
monkeypatch.setenv("SETUPTOOLS_DANGEROUSLY_SKIP_PYPROJECT_VALIDATION", "true")
402+
with pytest.warns(SetuptoolsWarning, match="Skipping the validation"):
403+
assert validate({"completely-wrong": "data"}, "pyproject.toml") is True

0 commit comments

Comments
 (0)