1313# limitations under the License.
1414"""Release script to publish release module to pipy."""
1515
16+ import glob
1617import io
1718import os
19+ import shutil
20+ import subprocess
1821import sys
22+ from typing import List
1923
2024VERSION_FILE_PATH = os .path .join (os .path .dirname ('__file__' ), 'appium' , 'version.py' )
2125CHANGELOG_PATH = os .path .join (os .path .dirname ('__file__' ), 'CHANGELOG.rst' )
2226
27+ APPIUM_DIR_PATH = os .path .join (os .path .dirname ('__file__' ), 'appium' )
28+ BUILT_APPIUM_DIR_PATH = os .path .join (os .path .dirname ('__file__' ), 'build' , 'lib' , 'appium' )
29+
2330MESSAGE_RED = '\033 [1;31m{}\033 [0m'
2431MESSAGE_GREEN = '\033 [1;32m{}\033 [0m'
2532MESSAGE_YELLOW = '\033 [1;33m{}\033 [0m'
@@ -101,6 +108,41 @@ def validate_release_env():
101108 exit ("Please get twine via 'pip install gitchangelog' or 'pip install git+git://github.com/vaab/gitchangelog.git' for Python 3.7" )
102109
103110
111+ def build () -> None :
112+ shutil .rmtree (BUILT_APPIUM_DIR_PATH , ignore_errors = True )
113+ status , output = subprocess .getstatusoutput ('{} setup.py install' .format (os .getenv ('PYTHON_BIN_PATH' )))
114+ if status != 0 :
115+ exit (f'Failed to build the package:\n { output } ' )
116+
117+
118+ def get_py_files_in_dir (root_dir : str ) -> List [str ]:
119+ return [
120+ file_path [len (root_dir ):]
121+ for file_path in glob .glob (f"{ root_dir } /**/*.py" , recursive = True ) + glob .glob (f"{ root_dir } /**/*.typed" , recursive = True )
122+ ]
123+
124+
125+ def assert_files_count_in_package () -> None :
126+ original_files = get_py_files_in_dir (APPIUM_DIR_PATH )
127+ built_files = get_py_files_in_dir (BUILT_APPIUM_DIR_PATH )
128+
129+ if len (original_files ) != len (built_files ):
130+ print (f"The count of files in '{ APPIUM_DIR_PATH } ' and '{ BUILT_APPIUM_DIR_PATH } ' were different." )
131+
132+ original_files_set = set (original_files )
133+ built_files_set = set (built_files )
134+
135+ diff = original_files_set .difference (built_files_set )
136+ if diff :
137+ print (f"'{ APPIUM_DIR_PATH } ' has '{ diff } ' files than { BUILT_APPIUM_DIR_PATH } " )
138+ diff = built_files_set .difference (original_files_set )
139+ if diff :
140+ print (f"{ BUILT_APPIUM_DIR_PATH } has { diff } files than { APPIUM_DIR_PATH } " )
141+
142+ exit (f"Python files in '{ BUILT_APPIUM_DIR_PATH } ' may differ from '{ APPIUM_DIR_PATH } '. "
143+ "Please make sure setup.py is configured properly." )
144+
145+
104146def main ():
105147 validate_release_env ()
106148
@@ -109,6 +151,9 @@ def main():
109151
110152 update_version_file (new_version )
111153
154+ build ()
155+ assert_files_count_in_package ()
156+
112157 ensure_publication (new_version )
113158
114159 commit_version_code (new_version )
0 commit comments