From fe6248acb25750a584e153b57caba4074adbd71a Mon Sep 17 00:00:00 2001 From: Sviatoslav Sydorenko Date: Thu, 12 Dec 2024 03:26:01 +0100 Subject: [PATCH] fixup! `delete` for compat --- piptools/build.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/piptools/build.py b/piptools/build.py index 78d8b069..23fc6c1f 100644 --- a/piptools/build.py +++ b/piptools/build.py @@ -217,16 +217,24 @@ def _temporary_constraints_file_set_for_pip( ) -> Iterator[None]: with tempfile.NamedTemporaryFile( mode="w+t", - delete_on_close=False, + delete=False, # FIXME: switch to `delete_on_close` in Python 3.12+ ) as tmpfile: # Write packages to upgrade to a temporary file to set as # constraints for the installation to the builder environment, # in case build requirements are among them tmpfile.write("\n".join(upgrade_packages)) - tmpfile.flush() - with _env_var("PIP_CONSTRAINT", tmpfile.name): - yield + # FIXME: replace `delete` with `delete_on_close` in Python 3.12+ + # FIXME: and replace `.close()` with `.flush()` + tmpfile.close() + + try: + with _env_var("PIP_CONSTRAINT", tmpfile.name): + yield + finally: + # FIXME: replace `delete` with `delete_on_close` in Python 3.12+ + # FIXME: and drop this manual deletion + os.unlink(tmpfile.name) @contextlib.contextmanager