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

Avoid import contextlib in _virtualenv #1406

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Avoid import contextlib in _virtualenv
No need to pay 3ms on basically every Python invocation.
I opened a PR upstream last week: pypa/virtualenv#2688
  • Loading branch information
hauntsaninja committed Feb 16, 2024
commit 1c93a1f3edb36d9175fcd7fa9aef945e1c232024
5 changes: 3 additions & 2 deletions crates/gourgeist/src/_virtualenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import os
import sys
from contextlib import suppress

VIRTUALENV_PATCH_FILE = os.path.join(__file__)

Expand Down Expand Up @@ -78,8 +77,10 @@ def find_spec(self, fullname, path, target=None): # noqa: ARG002
old = getattr(spec.loader, func_name)
func = self.exec_module if is_new_api else self.load_module
if old is not func:
with suppress(AttributeError): # C-Extension loaders are r/o such as zipimporter with <3.7
try: # noqa: SIM105
setattr(spec.loader, func_name, partial(func, old))
except AttributeError:
pass # C-Extension loaders are r/o such as zipimporter with <3.7
return spec
finally:
self.fullname = None
Expand Down