@@ -82,18 +82,19 @@ def copy_to_layout(target, rel_sources):
8282 target .unlink ()
8383
8484 with ZipFile (str (target ), 'w' , ZIP_DEFLATED ) as f :
85- for s , rel in rel_sources :
86- if rel .suffix .lower () == '.py' :
87- pyc = Path (tempfile .gettempdir ()) / rel .with_suffix ('.pyc' ).name
88- try :
89- py_compile .compile (str (s ), str (pyc ), str (rel ), doraise = True , optimize = 2 )
90- except py_compile .PyCompileError :
91- f .write (str (s ), str (rel ))
85+ with tempfile .TemporaryDirectory () as tmpdir :
86+ for s , rel in rel_sources :
87+ if rel .suffix .lower () == '.py' :
88+ pyc = Path (tmpdir ) / rel .with_suffix ('.pyc' ).name
89+ try :
90+ py_compile .compile (str (s ), str (pyc ), str (rel ), doraise = True , optimize = 2 )
91+ except py_compile .PyCompileError :
92+ f .write (str (s ), str (rel ))
93+ else :
94+ f .write (str (pyc ), str (rel .with_suffix ('.pyc' )))
9295 else :
93- f .write (str (pyc ), str (rel .with_suffix ('.pyc' )))
94- else :
95- f .write (str (s ), str (rel ))
96- count += 1
96+ f .write (str (s ), str (rel ))
97+ count += 1
9798
9899 else :
99100 for s , rel in rel_sources :
0 commit comments