77# "packaging==25.0",
88# ]
99# ///
10- import json
1110import os
1211import warnings
1312from pathlib import Path
2120
2221@click .command ()
2322@click .option ("--source" , default = None )
24- @click .option ("--flags " , default = None )
23+ @click .option ("--factors " , default = None )
2524@click .option ("--no-eoas" , is_flag = True , default = False )
26- def load_supported_python_toxenvs (
25+ @click .option ("--platforms" , default = None )
26+ def supported_python_envs_block (
2727 source : Path = None ,
28- flags : list [str ] = None ,
28+ factors : list [str ] = None ,
2929 no_eoas : bool = False ,
30+ platforms : list [str ] = None ,
3031):
3132 """enumerate toxenvs Python from a package source"""
3233
33- toxenvs = supported_python_toxenvs (source , flags , no_eoas )
34- print (json .dumps (toxenvs , indent = 2 ))
34+ if platforms is None :
35+ platforms = ["linux" ]
36+ elif isinstance (platforms , str ):
37+ platforms = platforms .split ("," )
38+
39+ toxenvs = supported_python_toxenvs (source , factors , no_eoas )
40+ envs_block = "\\ n" .join (
41+ f"- { platform } : { toxenv } " for platform in platforms for toxenv in toxenvs
42+ )
43+
44+ print (envs_block )
3545 with open (os .environ ["GITHUB_OUTPUT" ], "a" ) as f :
36- f .write (f"envs={ json . dumps ( toxenvs ) } \n " )
46+ f .write (f"envs={ envs_block } \n " )
3747
3848
3949def supported_python_toxenvs (
4050 source : Path = None ,
41- flags : list [str ] = None ,
51+ factors : list [str ] = None ,
4252 no_eoas : bool = False ,
4353) -> list [str ]:
54+ if isinstance (factors , str ):
55+ factors = factors .split ("," )
56+
4457 current_pythons = current_python_versions (no_eoas = no_eoas )
4558
4659 if source is None or source == "" :
@@ -50,15 +63,17 @@ def supported_python_toxenvs(
5063 try :
5164 python_requirements = SpecifierSet (configuration ["project" ]["requires-python" ])
5265
53- supported_pythons = [python for python in current_pythons if python in python_requirements ]
66+ supported_pythons = [
67+ python for python in current_pythons if python in python_requirements
68+ ]
5469 except (KeyError , TypeError ):
5570 warnings .warn (
5671 "could not find `requires-python` in metadata; falling back to current Python versions..."
5772 )
5873 supported_pythons = current_pythons
5974
6075 return [
61- f"py{ str (python ).replace ('.' , '' )} { '-' + '-' .join (flags ) if flags is not None and len (flags ) > 0 else '' } "
76+ f"py{ str (python ).replace ('.' , '' )} { '-' + '-' .join (factors ) if factors is not None and len (factors ) > 0 else '' } "
6277 for python in supported_pythons
6378 ]
6479
@@ -77,4 +92,4 @@ def current_python_versions(no_eoas: bool = False) -> list[Version]:
7792
7893
7994if __name__ == "__main__" :
80- load_supported_python_toxenvs ()
95+ supported_python_envs_block ()
0 commit comments