Skip to content

Call __func__ for AbstractSandbox's staticmethods #4227

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

Closed
Closed
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
18 changes: 12 additions & 6 deletions setuptools/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ def run_setup(setup_script, args):
class AbstractSandbox:
"""Wrap 'os' module and 'open()' builtin for virtualizing setup scripts"""

# Note: Calling __func__ on staticmethod for backwards compatibility with Python 3.9

_active = False

def __init__(self):
Expand Down Expand Up @@ -298,6 +300,7 @@ def run(self, func):
with self:
return func()

@staticmethod
def _mk_dual_path_wrapper(name):
original = getattr(_os, name)

Expand All @@ -310,8 +313,9 @@ def wrap(self, src, dst, *args, **kw):

for name in ["rename", "link", "symlink"]:
if hasattr(_os, name):
locals()[name] = _mk_dual_path_wrapper(name)
locals()[name] = _mk_dual_path_wrapper.__func__(name)

@staticmethod
def _mk_single_path_wrapper(name, original=None):
original = original or getattr(_os, name)

Expand All @@ -323,8 +327,8 @@ def wrap(self, path, *args, **kw):
return wrap

if _file:
_file = _mk_single_path_wrapper('file', _file)
_open = _mk_single_path_wrapper('open', _open)
_file = _mk_single_path_wrapper.__func__('file', _file)
_open = _mk_single_path_wrapper.__func__('open', _open)
for name in [
"stat",
"listdir",
Expand All @@ -347,8 +351,9 @@ def wrap(self, path, *args, **kw):
"access",
]:
if hasattr(_os, name):
locals()[name] = _mk_single_path_wrapper(name)
locals()[name] = _mk_single_path_wrapper.__func__(name)

@staticmethod
def _mk_single_with_return(name):
original = getattr(_os, name)

Expand All @@ -362,8 +367,9 @@ def wrap(self, path, *args, **kw):

for name in ['readlink', 'tempnam']:
if hasattr(_os, name):
locals()[name] = _mk_single_with_return(name)
locals()[name] = _mk_single_with_return.__func__(name)

@staticmethod
def _mk_query(name):
original = getattr(_os, name)

Expand All @@ -377,7 +383,7 @@ def wrap(self, *args, **kw):

for name in ['getcwd', 'tmpnam']:
if hasattr(_os, name):
locals()[name] = _mk_query(name)
locals()[name] = _mk_query.__func__(name)

def _validate_path(self, path):
"""Called to remap or validate any path, whether input or output"""
Expand Down