Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow user to skip validation of pyproject.toml via env var #4611

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions setuptools/config/pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,19 @@ def load_file(filepath: StrPath) -> dict:


def validate(config: dict, filepath: StrPath) -> bool:
skip = os.getenv("SETUPTOOLS_DANGEROUSLY_SKIP_PYPROJECT_VALIDATION", "false")
if skip.lower() == "true": # https://github.com/pypa/setuptools/issues/4459
SetuptoolsWarning.emit(
"Skipping the validation of `pyproject.toml`.",
"""
Please note that some setuptools functionalities rely on the validation of
`pyproject.toml` against misconfiguration to ensure proper operation.
By skipping the automatic checks, you taking responsibility for making sure
the file is valid. Otherwise unexpected behaviours may occur.
""",
)
return True
Copy link
Contributor Author

@abravalheri abravalheri Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The warning and env var name are directed towards users unexperienced with setuptools.
Experienced users will be fine.

But I am also happy to change the variable name and warning text.


from . import _validate_pyproject as validator

trove_classifier = validator.FORMAT_FUNCTIONS.get("trove-classifier")
Expand Down
7 changes: 7 additions & 0 deletions setuptools/tests/config/test_pyprojecttoml.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
)
from setuptools.dist import Distribution
from setuptools.errors import OptionError
from setuptools.warnings import SetuptoolsWarning

import distutils.core

Expand Down Expand Up @@ -394,3 +395,9 @@ def test_warn_tools_typo(tmp_path):

with pytest.warns(_ToolsTypoInMetadata):
read_configuration(pyproject)


def test_warn_skipping_validation(monkeypatch):
monkeypatch.setenv("SETUPTOOLS_DANGEROUSLY_SKIP_PYPROJECT_VALIDATION", "true")
with pytest.warns(SetuptoolsWarning, match="Skipping the validation"):
assert validate({"completely-wrong": "data"}, "pyproject.toml") is True
Loading