1616
1717DIR = Path (__file__ ).parent .parent .resolve ()
1818
19+ BuildBackend = typing .Literal ["setuptools" , "meson" ]
20+
1921
2022def shell (cmd : str , * , check : bool , ** kwargs : object ) -> subprocess .CompletedProcess [str ]:
2123 return subprocess .run ([cmd ], shell = True , check = check , ** kwargs ) # type: ignore[call-overload, no-any-return]
@@ -27,22 +29,25 @@ def git_repo_has_changes() -> bool:
2729 return unstaged_changes or staged_changes
2830
2931
30- def generate_basic_project (path : Path ) -> None :
32+ def generate_project (path : Path , build_backend : BuildBackend ) -> None :
3133 sys .path .insert (0 , "" )
32- from test .test_projects .c import new_c_project # noqa: PLC0415
34+ if build_backend == "meson" :
35+ from test .test_projects .meson import new_meson_project as new_project # noqa: PLC0415
36+ else :
37+ from test .test_projects .setuptools import new_c_project as new_project # noqa: PLC0415
3338
34- project = new_c_project ()
39+ project = new_project ()
3540 project .generate (path )
3641
3742
3843class CIService (typing .NamedTuple ):
3944 name : str
4045 dst_config_path : str
4146 badge_md : str
42- config_file_transform : typing .Callable [[str ], str ] = lambda x : x # identity by default
47+ config_file_transform : typing .Callable [[str , str ], str ] = lambda x , _ : x # identity by default
4348
4449
45- def github_config_file_transform (content : str ) -> str :
50+ def github_config_file_transform (content : str , git_ref : str ) -> str :
4651 # one of the the github configs only builds on main, so we need to remove that restriction
4752 # so our example build will run on the test branch.
4853 #
@@ -61,6 +66,22 @@ def github_config_file_transform(content: str) -> str:
6166 "push:" ,
6267 content ,
6368 )
69+
70+ # use the version of cibuildwheel from the current commit, not the latest
71+ # release
72+ # replace:
73+ # """
74+ 75+ # """
76+ # with:
77+ # """
78+ # uses: pypa/cibuildwheel@<latest commit hash>
79+ # """
80+ content = re .sub (
81+ r"uses: pypa/cibuildwheel@v.*" ,
82+ f"uses: pypa/cibuildwheel@{ git_ref } " ,
83+ content ,
84+ )
6485 return content
6586
6687
@@ -110,20 +131,23 @@ def ci_service_for_config_file(config_file: Path) -> CIService:
110131
111132@click .command ()
112133@click .argument ("config_files" , nargs = - 1 , type = click .Path ())
113- def run_example_ci_configs (config_files = None ):
134+ @click .option ("--build-backend" , type = click .Choice (["setuptools" , "meson" ]), default = "setuptools" )
135+ def run_example_ci_configs (
136+ config_files : list [str ], build_backend : BuildBackend = "setuptools"
137+ ) -> None :
114138 """
115139 Test the example configs. If no files are specified, will test
116140 examples/*-minimal.yml
117141 """
118142
119143 if len (config_files ) == 0 :
120- config_files = Path ("examples" ).glob ("*-minimal.yml" )
144+ config_file_paths = list ( Path ("examples" ).glob ("*-minimal.yml" ) )
121145 else :
122- config_files = [Path (f ) for f in config_files ]
146+ config_file_paths = [Path (f ) for f in config_files ]
123147
124148 # check each CI service has at most 1 config file
125149 configs_by_service = set ()
126- for config_file in config_files :
150+ for config_file in config_file_paths :
127151 service = ci_service_for_config_file (config_file )
128152 if service .name in configs_by_service :
129153 msg = "You cannot specify more than one config per CI service"
@@ -137,6 +161,9 @@ def run_example_ci_configs(config_files=None):
137161 previous_branch = shell (
138162 "git rev-parse --abbrev-ref HEAD" , check = True , capture_output = True , encoding = "utf8"
139163 ).stdout .strip ()
164+ git_ref = shell (
165+ "git rev-parse HEAD" , check = True , capture_output = True , encoding = "utf8"
166+ ).stdout .strip ()
140167
141168 timestamp = time .strftime ("%Y-%m-%dT%H-%M-%S" , time .gmtime ())
142169 branch_name = f"example-config-test---{ previous_branch } -{ timestamp } "
@@ -145,16 +172,16 @@ def run_example_ci_configs(config_files=None):
145172 shell (f"git checkout --orphan { branch_name } " , check = True )
146173
147174 example_project = Path ("example_root" )
148- generate_basic_project (example_project )
175+ generate_project (example_project , build_backend = build_backend )
149176
150- for config_file in config_files :
177+ for config_file in config_file_paths :
151178 service = ci_service_for_config_file (config_file )
152179 dst_config_file = example_project / service .dst_config_path
153180
154181 dst_config_file .parent .mkdir (parents = True , exist_ok = True )
155182
156183 contents = config_file .read_text (encoding = "utf8" )
157- contents = service .config_file_transform (contents )
184+ contents = service .config_file_transform (contents , git_ref )
158185 dst_config_file .write_text (contents , encoding = "utf8" )
159186
160187 subprocess .run (["git" , "add" , example_project ], check = True )
@@ -178,14 +205,14 @@ def run_example_ci_configs(config_files=None):
178205 print ("> " )
179206 print ("> | Service | Config | Status |" )
180207 print ("> |---|---|---|" )
181- for config_file in config_files :
208+ for config_file in config_file_paths :
182209 service = ci_service_for_config_file (config_file )
183210 badge = service .badge_md .format (
184211 branch = branch_name , branch_escaped = quote (branch_name , safe = "" )
185212 )
186213 print (f"> | { service .name } | `{ config_file } ` | { badge } |" )
187214 print ("> " )
188- print ("> Generated by `bin/run_example_ci_config.py `" )
215+ print (f "> Generated by `{ ' ' . join ( sys . argv ) } `" )
189216 print ()
190217 print ("---" )
191218 finally :
0 commit comments