File tree Expand file tree Collapse file tree 2 files changed +35
-12
lines changed
poetry/core/masonry/builders Expand file tree Collapse file tree 2 files changed +35
-12
lines changed Original file line number Diff line number Diff line change @@ -78,18 +78,19 @@ def build(self):
7878 new_mode = normalize_file_permissions (st_mode )
7979 os .chmod (temp_path , new_mode )
8080
81- with zipfile .ZipFile (
82- os .fdopen (fd , "w+b" ), mode = "w" , compression = zipfile .ZIP_DEFLATED
83- ) as zip_file :
84- if not self ._poetry .package .build_should_generate_setup ():
85- self ._build (zip_file )
86- self ._copy_module (zip_file )
87- else :
88- self ._copy_module (zip_file )
89- self ._build (zip_file )
90-
91- self ._write_metadata (zip_file )
92- self ._write_record (zip_file )
81+ with os .fdopen (fd , "w+b" ) as fd_file :
82+ with zipfile .ZipFile (
83+ fd_file , mode = "w" , compression = zipfile .ZIP_DEFLATED
84+ ) as zip_file :
85+ if not self ._poetry .package .build_should_generate_setup ():
86+ self ._build (zip_file )
87+ self ._copy_module (zip_file )
88+ else :
89+ self ._copy_module (zip_file )
90+ self ._build (zip_file )
91+
92+ self ._write_metadata (zip_file )
93+ self ._write_record (zip_file )
9394
9495 wheel_path = dist_dir / self .wheel_filename
9596 if wheel_path .exists ():
Original file line number Diff line number Diff line change 11# -*- coding: utf-8 -*-
2+ import os
23import shutil
34import zipfile
45
@@ -284,3 +285,24 @@ def test_default_src_with_excluded_data(mocker):
284285 assert "my_package/data/data1.txt" in names
285286 assert "my_package/data/sub_data/data2.txt" not in names
286287 assert "my_package/data/sub_data/data3.txt" in names
288+
289+
290+ def test_wheel_file_is_closed (monkeypatch ):
291+ """Confirm that wheel zip files are explicitly closed."""
292+
293+ # Using a list is a hack for Python 2.7 compatibility.
294+ fd_file = [None ]
295+
296+ real_fdopen = os .fdopen
297+
298+ def capturing_fdopen (* args , ** kwargs ):
299+ fd_file [0 ] = real_fdopen (* args , ** kwargs )
300+ return fd_file [0 ]
301+
302+ monkeypatch .setattr (os , "fdopen" , capturing_fdopen )
303+
304+ module_path = fixtures_dir / "module1"
305+ WheelBuilder .make (Factory ().create_poetry (module_path ))
306+
307+ assert fd_file [0 ] is not None
308+ assert fd_file [0 ].closed
You can’t perform that action at this time.
0 commit comments