@@ -50,6 +50,16 @@ def _write_file_prefix(f, interpreter):
5050 f .write (shebang )
5151
5252
53+ def _make_executable (path ):
54+ mode = os .stat (path ).st_mode
55+ executable = (
56+ (mode & stat .S_IRUSR ) >> 2
57+ | (mode & stat .S_IRGRP ) >> 2
58+ | (mode & stat .S_IROTH ) >> 2
59+ )
60+ os .chmod (path , mode | executable )
61+
62+
5363def _copy_archive (archive , new_archive , interpreter = None ):
5464 """Copy an application archive, modifying the shebang line."""
5565 with _maybe_open (archive , 'rb' ) as src :
@@ -70,7 +80,7 @@ def _copy_archive(archive, new_archive, interpreter=None):
7080 shutil .copyfileobj (src , dst )
7181
7282 if interpreter and isinstance (new_archive , str ):
73- os . chmod (new_archive , os . stat ( new_archive ). st_mode | stat . S_IEXEC )
83+ _make_executable (new_archive )
7484
7585
7686def create_archive (source , target = None , interpreter = None , main = None ,
@@ -169,7 +179,7 @@ def create_archive(source, target=None, interpreter=None, main=None,
169179 z .writestr ('__main__.py' , main_py .encode ('utf-8' ))
170180
171181 if interpreter and not hasattr (target , 'write' ):
172- target . chmod (target . stat (). st_mode | stat . S_IEXEC )
182+ _make_executable (target )
173183
174184
175185def get_interpreter (archive ):
0 commit comments