13
13
# limitations under the License.
14
14
"""Release script to publish release module to pipy."""
15
15
16
+ import glob
16
17
import io
17
18
import os
19
+ import shutil
20
+ import subprocess
18
21
import sys
22
+ from typing import List
19
23
20
24
VERSION_FILE_PATH = os .path .join (os .path .dirname ('__file__' ), 'appium' , 'version.py' )
21
25
CHANGELOG_PATH = os .path .join (os .path .dirname ('__file__' ), 'CHANGELOG.rst' )
22
26
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
+
23
30
MESSAGE_RED = '\033 [1;31m{}\033 [0m'
24
31
MESSAGE_GREEN = '\033 [1;32m{}\033 [0m'
25
32
MESSAGE_YELLOW = '\033 [1;33m{}\033 [0m'
@@ -101,6 +108,41 @@ def validate_release_env():
101
108
exit ("Please get twine via 'pip install gitchangelog' or 'pip install git+git://github.com/vaab/gitchangelog.git' for Python 3.7" )
102
109
103
110
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
+
104
146
def main ():
105
147
validate_release_env ()
106
148
@@ -109,6 +151,9 @@ def main():
109
151
110
152
update_version_file (new_version )
111
153
154
+ build ()
155
+ assert_files_count_in_package ()
156
+
112
157
ensure_publication (new_version )
113
158
114
159
commit_version_code (new_version )
0 commit comments