Skip to content

Commit c8e90d9

Browse files
committed
Expose mac_platforms() publicly
Along the way, make all platform-related functions generators.
1 parent 11b9bed commit c8e90d9

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

packaging/tags.py

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,12 @@ def _cpython_abis(py_version, warn=False):
173173

174174

175175
def cpython_tags(
176-
python_version=sys.version_info[:2], abis=None, platforms=None, **kwargs
176+
python_version=sys.version_info[:2], # type: PythonVersion
177+
abis=None, # type: Optional[Iterable[str]]
178+
platforms=None, # type: Optional[Iterable[str]]
179+
**kwargs # type: bool
177180
):
178-
# type: (PythonVersion, Optional[Iterable[str]], Optional[Iterable[str]], bool) -> Iterator[Tag] # noqa
181+
# type: (...) -> Iterator[Tag]
179182
"""
180183
Yield the tags for a CPython interpreter.
181184
@@ -192,9 +195,7 @@ def cpython_tags(
192195
interpreter = "cp{}{}".format(*python_version)
193196
if not abis:
194197
abis = _cpython_abis(python_version, warn)
195-
if not platforms:
196-
platforms = _platforms()
197-
platforms = list(platforms)
198+
platforms = list(platforms or _platforms())
198199
abis = list(abis)
199200
# 'abi3' and 'none' are explicitly handled later.
200201
try:
@@ -283,10 +284,7 @@ def generic_tags(interpreter=None, abis=None, platforms=None, **kwargs):
283284
interpreter = _generic_interpreter(warn=warn)
284285
if not abis:
285286
abis = [_generic_abi()]
286-
if not platforms:
287-
platforms = _platforms()
288-
else:
289-
platforms = list(platforms)
287+
platforms = list(platforms or _platforms())
290288
abis = list(abis)
291289
for abi in abis:
292290
for platform_ in platforms:
@@ -372,11 +370,16 @@ def _mac_binary_formats(version, cpu_arch):
372370
return formats
373371

374372

375-
def _mac_platforms(
376-
version=None, # type: Optional[MacVersion]
377-
arch=None, # type: Optional[str]
378-
):
379-
# type: (...) -> List[str]
373+
def mac_platforms(version=None, arch=None):
374+
# type: (Optional[MacVersion], Optional[str]) -> Iterator[str]
375+
"""
376+
Yield the platform tags for a macOS system.
377+
378+
The *version* parameter is a two-item tuple specifying the macOS version to
379+
generate platform tags for. The *arch* parameter is the CPU architecture to
380+
generate platform tags for. Both parameters default to the appropriate value
381+
for the current system.
382+
"""
380383
version_str, _, cpu_arch = platform.mac_ver() # type: ignore
381384
if version is None:
382385
version = cast("MacVersion", tuple(map(int, version_str.split(".")[:2])))
@@ -386,19 +389,15 @@ def _mac_platforms(
386389
arch = _mac_arch(cpu_arch)
387390
else:
388391
arch = arch
389-
platforms = []
390392
for minor_version in range(version[1], -1, -1):
391393
compat_version = version[0], minor_version
392394
binary_formats = _mac_binary_formats(compat_version, arch)
393395
for binary_format in binary_formats:
394-
platforms.append(
395-
"macosx_{major}_{minor}_{binary_format}".format(
396+
yield "macosx_{major}_{minor}_{binary_format}".format(
396397
major=compat_version[0],
397398
minor=compat_version[1],
398399
binary_format=binary_format,
399400
)
400-
)
401-
return platforms
402401

403402

404403
# From PEP 513.
@@ -508,7 +507,7 @@ def _have_compatible_glibc(required_major, minimum_minor):
508507

509508

510509
def _linux_platforms(is_32bit=_32_BIT_INTERPRETER):
511-
# type: (bool) -> List[str]
510+
# type: (bool) -> Iterator[str]
512511
linux = _normalize_string(distutils.util.get_platform())
513512
if linux == "linux_x86_64" and is_32bit:
514513
linux = "linux_i686"
@@ -520,29 +519,26 @@ def _linux_platforms(is_32bit=_32_BIT_INTERPRETER):
520519
manylinux_support_iter = iter(manylinux_support)
521520
for name, glibc_version in manylinux_support_iter:
522521
if _is_manylinux_compatible(name, glibc_version):
523-
platforms = [linux.replace("linux", name)]
522+
yield linux.replace("linux", name)
524523
break
525-
else:
526-
platforms = []
527524
# Support for a later manylinux implies support for an earlier version.
528-
platforms += [linux.replace("linux", name) for name, _ in manylinux_support_iter]
529-
platforms.append(linux)
530-
return platforms
525+
for name, _ in manylinux_support_iter:
526+
yield linux.replace("linux", name)
527+
yield linux
531528

532529

533530
def _generic_platforms():
534-
# type: () -> List[str]
535-
platform = _normalize_string(distutils.util.get_platform())
536-
return [platform]
531+
# type: () -> Iterator[str]
532+
yield _normalize_string(distutils.util.get_platform())
537533

538534

539535
def _platforms():
540-
# type: () -> List[str]
536+
# type: () -> Iterator[str]
541537
"""
542538
Provide the platform tags for this installation.
543539
"""
544540
if platform.system() == "Darwin":
545-
return _mac_platforms()
541+
return mac_platforms()
546542
elif platform.system() == "Linux":
547543
return _linux_platforms()
548544
else:

0 commit comments

Comments
 (0)