From c3c8e80e9281e054506135ff0fedc5d6206d17d7 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 31 Dec 2021 14:16:26 +0000 Subject: [PATCH 1/2] fix: AttributeError on macOS creating a Python 2.x virtualenv Fixes #2269 > AttributeError: 'bool' object has no attribute 'error' when creating a Python 2.x environment on macOS with virtualenv 20.12.0. Refs #2233 --- docs/changelog/bugfix.2269.rst | 2 ++ .../create/via_global_ref/builtin/cpython/mac_os.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 docs/changelog/bugfix.2269.rst diff --git a/docs/changelog/bugfix.2269.rst b/docs/changelog/bugfix.2269.rst new file mode 100644 index 000000000..fdedc778a --- /dev/null +++ b/docs/changelog/bugfix.2269.rst @@ -0,0 +1,2 @@ +Fix ``AttributeError: 'bool' object has no attribute 'error'`` when creating a +Python 2.x virtualenv on macOS - 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 4f7f646c5..812ec589c 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 @@ -70,7 +70,9 @@ def image_ref(cls, interpreter): class CPython2macOsFramework(CPythonmacOsFramework, CPython2PosixBase): @classmethod def can_create(cls, interpreter): - return not IS_MAC_ARM64 and super(CPython2macOsFramework, cls).can_describe(interpreter) + if not IS_MAC_ARM64 and super(CPython2macOsFramework, cls).can_describe(interpreter): + return super(CPython2macOsFramework, cls).can_create(interpreter) + return False @classmethod def image_ref(cls, interpreter): @@ -111,7 +113,9 @@ def reload_code(self): class CPython2macOsArmFramework(CPython2macOsFramework, CPythonmacOsFramework, CPython2PosixBase): @classmethod def can_create(cls, interpreter): - return IS_MAC_ARM64 and super(CPythonmacOsFramework, cls).can_describe(interpreter) + if IS_MAC_ARM64 and super(CPythonmacOsFramework, cls).can_describe(interpreter): + return super(CPythonmacOsFramework, cls).can_create(interpreter) + return False def create(self): super(CPython2macOsFramework, self).create() From edf01aea9dd944d01cbcb4a9606fd8a7fd5c5cc1 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Fri, 31 Dec 2021 15:30:55 +0000 Subject: [PATCH 2/2] fix: Correctly remove bk dir when re-signing macOS Python 2.x executable Fixes #2271 > PermissionError: [Errno 1] Operation not permitted: '/Users/alex/src/virtualenv/v27/bin/bk' Requires #2270 Refs #2233 --- 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)