Skip to content

Commit e2180b2

Browse files
committed
Update implementation to consider new packaging exceptions
1 parent 0a4de62 commit e2180b2

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

setuptools/config/setupcfg.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from distutils.errors import DistutilsOptionError, DistutilsFileError
1818
from setuptools.extern.packaging.requirements import Requirement, InvalidRequirement
19+
from setuptools.extern.packaging.markers import default_environment as marker_env
1920
from setuptools.extern.packaging.version import Version, InvalidVersion
2021
from setuptools.extern.packaging.specifiers import SpecifierSet
2122
from setuptools._deprecation_warning import SetuptoolsDeprecationWarning
@@ -199,17 +200,21 @@ def _warn_accidental_env_marker_misconfig(label: str, orig_value: str, parsed: l
199200
if "\n" in orig_value or len(parsed) != 2:
200201
return
201202

202-
with contextlib.suppress(InvalidRequirement):
203-
original_requirements_str = ";".join(parsed)
204-
req = Requirement(original_requirements_str)
205-
if req.marker is not None:
206-
msg = (
207-
f"One of the parsed requirements in `{label}` "
208-
f"looks like a valid environment marker: '{parsed[1]}'\n"
209-
"Make sure that the config is correct and check "
210-
"https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#opt-2" # noqa: E501
211-
)
212-
warnings.warn(msg, UserWarning)
203+
markers = marker_env().keys()
204+
msg = (
205+
f"One of the parsed requirements in `{label}` "
206+
f"looks like a valid environment marker: '{parsed[1]}'\n"
207+
"Make sure that the config is correct and check "
208+
"https://setuptools.pypa.io/en/latest/userguide/declarative_config.html#opt-2" # noqa: E501
209+
)
210+
211+
try:
212+
req = Requirement(parsed[1])
213+
if req.name in markers:
214+
warnings.warn(msg)
215+
except InvalidRequirement as ex:
216+
if any(parsed[1].startswith(marker) for marker in markers):
217+
raise InvalidRequirement(msg) from ex
213218

214219

215220
class ConfigHandler(Generic[Target]):

0 commit comments

Comments
 (0)