99
1010import logging
1111import os
12+ from pathlib import Path
13+ import subprocess
1214import sys
1315import tempfile
1416import shutil
@@ -64,7 +66,7 @@ def run_command(cmd, check_return_code=False, cwd=None):
6466 raise RuntimeError (f"{ cmd } failed" )
6567
6668
67- def test_extension ():
69+ def test_extension (whl_dir : Path ):
6870 for pkg_name , ext_path in ALL_TESTS :
6971 ext_name = ext_path .split ('/' )[- 1 ]
7072 logger .info (f'installing extension: { ext_name } ' )
@@ -86,22 +88,45 @@ def test_extension():
8688 cmd = ['azdev' , 'extension' , 'remove' , ext_name ]
8789 run_command (cmd , check_return_code = True )
8890
89-
90- def test_source_wheels ():
91+ logger .info (f'installing extension wheel: { ext_name } ' )
92+ wheel_path = next (whl_dir .glob (f"{ ext_name } *.whl" ))
93+ subprocess .run (
94+ f"az extension add -y -s { wheel_path } " .split (" " ),
95+ check = True ,
96+ )
97+ subprocess .run (
98+ f"az { ext_name } --help" .split (" " ),
99+ check = True ,
100+ stdout = subprocess .DEVNULL ,
101+ stderr = subprocess .DEVNULL ,
102+ )
103+ subprocess .run (
104+ f"az extension remove -n { ext_name } " .split (" " ),
105+ check = True ,
106+ )
107+
108+
109+ def test_source_wheels (whl_dir : Path ):
91110 # Test we can build all sources into wheels and that metadata from the wheel is valid
92111 built_whl_dir = tempfile .mkdtemp ()
93112 source_extensions = [os .path .join (SRC_PATH , n ) for n in os .listdir (SRC_PATH )
94113 if os .path .isdir (os .path .join (SRC_PATH , n ))]
95114 for s in source_extensions :
115+ ext_name = s .split ('/' )[- 1 ]
96116 if not os .path .isfile (os .path .join (s , 'setup.py' )):
97117 continue
98118 try :
99- check_output (['python ' , 'setup.py ' , 'bdist_wheel ' , '-q' , '-d ' , built_whl_dir ], cwd = s )
119+ check_output (['azdev ' , 'extension ' , 'build ' , ext_name , '--dist-dir ' , built_whl_dir ])
100120 except CalledProcessError as err :
101121 raise ("Unable to build extension {} : {}" .format (s , err ))
102122 # Export built wheels so CI can publish them as artifacts
103- wheels_out_dir = os .environ .get ('WHEELS_OUTPUT_DIR' )
104- if wheels_out_dir :
123+ wheels_out_dirs = [
124+ os .environ .get ('WHEELS_OUTPUT_DIR' ),
125+ str (whl_dir ),
126+ ]
127+ for wheels_out_dir in wheels_out_dirs :
128+ if not wheels_out_dir :
129+ continue
105130 try :
106131 os .makedirs (wheels_out_dir , exist_ok = True )
107132 for fname in os .listdir (built_whl_dir ):
@@ -115,5 +140,7 @@ def test_source_wheels():
115140
116141
117142if __name__ == '__main__' :
118- test_extension ()
119- test_source_wheels ()
143+ with tempfile .TemporaryDirectory () as whl_dir :
144+ whl_dir = Path (whl_dir )
145+ test_source_wheels (whl_dir = whl_dir )
146+ test_extension (whl_dir = whl_dir )
0 commit comments