@@ -134,7 +134,11 @@ def create_archive(source, target=None, interpreter=None, main=None,
134134 # Create the list of files to add to the archive now, in case
135135 # the target is being created in the source directory - we
136136 # don't want the target being added to itself
137- files_to_add = sorted (source .rglob ('*' ))
137+ files_to_add = {}
138+ for path in sorted (source .rglob ('*' )):
139+ relative_path = path .relative_to (source )
140+ if filter is None or filter (relative_path ):
141+ files_to_add [path ] = relative_path
138142
139143 # The target cannot be in the list of files to add. If it were, we'd
140144 # end up overwriting the source file and writing the archive into
@@ -159,10 +163,8 @@ def create_archive(source, target=None, interpreter=None, main=None,
159163 compression = (zipfile .ZIP_DEFLATED if compressed else
160164 zipfile .ZIP_STORED )
161165 with zipfile .ZipFile (fd , 'w' , compression = compression ) as z :
162- for child in files_to_add :
163- arcname = child .relative_to (source )
164- if filter is None or filter (arcname ):
165- z .write (child , arcname .as_posix ())
166+ for path , relative_path in files_to_add .items ():
167+ z .write (path , relative_path .as_posix ())
166168 if main_py :
167169 z .writestr ('__main__.py' , main_py .encode ('utf-8' ))
168170
0 commit comments