From 856933e30fb573f966150d6e2d568a81761b165b Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sun, 2 Jan 2022 14:58:57 +0000 Subject: [PATCH] fix: Correctly remove bk dir when re-signing macOS Python 2.x executable (#2272) --- docs/changelog/bugfix.2271.rst | 2 ++ src/virtualenv/create/via_global_ref/builtin/cpython/mac_os.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/bugfix.2271.rst diff --git a/docs/changelog/bugfix.2271.rst b/docs/changelog/bugfix.2271.rst new file mode 100644 index 000000000..89c0410c6 --- /dev/null +++ b/docs/changelog/bugfix.2271.rst @@ -0,0 +1,2 @@ +Fix ``PermissionError: [Errno 1] Operation not permitted`` when creating a +Python 2.x virtualenv on macOS/arm64 - by ``moreati`` diff --git a/src/virtualenv/create/via_global_ref/builtin/cpython/mac_os.py b/src/virtualenv/create/via_global_ref/builtin/cpython/mac_os.py index 812ec589c..5e06de2be 100644 --- a/src/virtualenv/create/via_global_ref/builtin/cpython/mac_os.py +++ b/src/virtualenv/create/via_global_ref/builtin/cpython/mac_os.py @@ -136,7 +136,7 @@ def fix_signature(self): bak_dir.mkdir(parents=True, exist_ok=True) subprocess.check_call(["cp", exe, bak_dir]) subprocess.check_call(["mv", bak_dir / exe.name, exe]) - bak_dir.unlink() + bak_dir.rmdir() cmd = ["codesign", "-s", "-", "--preserve-metadata=identifier,entitlements,flags,runtime", "-f", exe] logging.debug("Changing Signature: %s", cmd) subprocess.check_call(cmd)