Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Correctly remove bk dir when re-signing macOS Python 2.x executable #2272

Merged
merged 2 commits into from
Jan 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/changelog/bugfix.2269.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ``AttributeError: 'bool' object has no attribute 'error'`` when creating a
Python 2.x virtualenv on macOS - by ``moreati``
2 changes: 2 additions & 0 deletions docs/changelog/bugfix.2271.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ``PermissionError: [Errno 1] Operation not permitted`` when creating a
Python 2.x virtualenv on macOS/arm64 - by ``moreati``
10 changes: 7 additions & 3 deletions src/virtualenv/create/via_global_ref/builtin/cpython/mac_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()
Expand All @@ -132,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)
Expand Down