@@ -32,7 +32,7 @@ def _venv_create(venv_dir):
3232 return venv_context
3333
3434
35- def install_to_dir (target_dir , requirements ):
35+ def _install_to_dir (target_dir , requirements ):
3636 """ Use pip to install the requirements into a specific directory
3737 """
3838 # pip is not usable as a library, so it is much simpler and safer to just
@@ -48,9 +48,7 @@ def install_to_dir(target_dir, requirements):
4848 subprocess .run (command )
4949
5050
51- def build_zipapp (source_dir , entry_point , output_file ):
52- """ Build the 'zipapp' file
53- """
51+ def _create_zipapp_archive (source_dir , entry_point , output_file ):
5452 zipapp .create_archive (
5553 source_dir ,
5654 interpreter = '/usr/bin/env python3' ,
@@ -59,6 +57,15 @@ def build_zipapp(source_dir, entry_point, output_file):
5957 )
6058
6159
60+ def build_zapp (requirements , entry_point , output_file ):
61+ """ Build a zapp binary archive
62+ """
63+ with tempfile .TemporaryDirectory () as install_dir :
64+ if requirements :
65+ _install_to_dir (install_dir , requirements )
66+ _create_zipapp_archive (install_dir , entry_point , output_file )
67+
68+
6269class bdist_zapp (setuptools .Command ): # pylint: disable=invalid-name
6370 """ Custom 'setuptools' command to build a zipapp
6471 """
@@ -93,12 +100,12 @@ class bdist_zapp(setuptools.Command): # pylint: disable=invalid-name
93100 'keep-temp' ,
94101 ]
95102
96- def __init__ (self , * argv , ** kwargs ):
103+ def __init__ (self , * args , ** kwargs ):
97104 self .bdist_dir = None
98105 self .dist_dir = None
99106 self .entry_point = None
100107 self .keep_temp = 0
101- super ().__init__ (* argv , ** kwargs )
108+ super ().__init__ (* args , ** kwargs )
102109
103110 def initialize_options (self ):
104111 """ Override """
@@ -153,9 +160,13 @@ def run(self):
153160 raise distutils .errors .DistutilsInternalError (
154161 "can not find bdist_wheel" ,
155162 )
156- install_to_dir (self .bdist_dir , [dist_file ])
163+ _install_to_dir (self .bdist_dir , [dist_file ])
157164 self .mkpath (self .dist_dir )
158- build_zipapp (self .bdist_dir , self .entry_point , output_file )
165+ _create_zipapp_archive (
166+ self .bdist_dir ,
167+ self .entry_point ,
168+ output_file ,
169+ )
159170 if not self .keep_temp :
160171 distutils .dir_util .remove_tree (
161172 self .bdist_dir ,
0 commit comments