From 124a879e722d94d49cf5b4ea8a326eeec10737b2 Mon Sep 17 00:00:00 2001 From: Kurt McKee Date: Wed, 6 Jan 2021 20:53:25 -0600 Subject: [PATCH] Explicitly close the wheel temp file after it's written This resolves a crash that occurs on PyPy3 on Windows Closes python-poetry/poetry#3545 --- poetry/core/masonry/builders/wheel.py | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/poetry/core/masonry/builders/wheel.py b/poetry/core/masonry/builders/wheel.py index 1d0b13e18..969de059e 100644 --- a/poetry/core/masonry/builders/wheel.py +++ b/poetry/core/masonry/builders/wheel.py @@ -78,18 +78,19 @@ def build(self): new_mode = normalize_file_permissions(st_mode) os.chmod(temp_path, new_mode) - with zipfile.ZipFile( - os.fdopen(fd, "w+b"), mode="w", compression=zipfile.ZIP_DEFLATED - ) as zip_file: - if not self._poetry.package.build_should_generate_setup(): - self._build(zip_file) - self._copy_module(zip_file) - else: - self._copy_module(zip_file) - self._build(zip_file) - - self._write_metadata(zip_file) - self._write_record(zip_file) + with os.fdopen(fd, "w+b") as fd_file: + with zipfile.ZipFile( + fd_file, mode="w", compression=zipfile.ZIP_DEFLATED + ) as zip_file: + if not self._poetry.package.build_should_generate_setup(): + self._build(zip_file) + self._copy_module(zip_file) + else: + self._copy_module(zip_file) + self._build(zip_file) + + self._write_metadata(zip_file) + self._write_record(zip_file) wheel_path = dist_dir / self.wheel_filename if wheel_path.exists():