|
16 | 16 |
|
17 | 17 | from distutils.errors import DistutilsOptionError, DistutilsFileError
|
18 | 18 | from setuptools.extern.packaging.requirements import Requirement, InvalidRequirement
|
| 19 | +from setuptools.extern.packaging.markers import default_environment as marker_env |
19 | 20 | from setuptools.extern.packaging.version import Version, InvalidVersion
|
20 | 21 | from setuptools.extern.packaging.specifiers import SpecifierSet
|
21 | 22 | from setuptools._deprecation_warning import SetuptoolsDeprecationWarning
|
@@ -199,17 +200,21 @@ def _warn_accidental_env_marker_misconfig(label: str, orig_value: str, parsed: l
|
199 | 200 | if "\n" in orig_value or len(parsed) != 2:
|
200 | 201 | return
|
201 | 202 |
|
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 |
213 | 218 |
|
214 | 219 |
|
215 | 220 | class ConfigHandler(Generic[Target]):
|
|
0 commit comments