Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
setuptools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jérome Perrin
setuptools
Commits
20567bef
Commit
20567bef
authored
May 21, 2017
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement AbstractSandbox as a context manager.
parent
d48cb39b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
17 deletions
+18
-17
setuptools/sandbox.py
setuptools/sandbox.py
+16
-15
setuptools/tests/test_sandbox.py
setuptools/tests/test_sandbox.py
+2
-2
No files found.
setuptools/sandbox.py
View file @
20567bef
...
...
@@ -249,11 +249,9 @@ def run_setup(setup_script, args):
setup_script.encode(sys.getfilesystemencoding())
)
def runner(
):
with DirectorySandbox(setup_dir
):
ns = dict(__file__=dunder_file, __name__='__main__')
_execfile(setup_script, ns)
DirectorySandbox(setup_dir).run(runner)
except SystemExit as v:
if v.args and v.args[0]:
raise
...
...
@@ -275,22 +273,25 @@ class AbstractSandbox:
for name in self._attrs:
setattr(os, name, getattr(source, name))
def run(self, func):
"""
Run
'func'
under
os
sandboxing
"""
try:
def __enter__(self):
self._copy(self)
if _file:
builtins.file = self._file
builtins.open = self._open
self._active = True
return func()
finally
:
def __exit__(self, exc_type, exc_value, traceback)
:
self._active = False
if _file:
builtins.file = _file
builtins.open = _open
self._copy(_os)
def run(self, func):
"""
Run
'func'
under
os
sandboxing
"""
with self:
return func()
def _mk_dual_path_wrapper(name):
original = getattr(_os, name)
...
...
setuptools/tests/test_sandbox.py
View file @
20567bef
...
...
@@ -12,8 +12,8 @@ from setuptools.sandbox import DirectorySandbox
class
TestSandbox
:
def
test_devnull
(
self
,
tmpdir
):
sandbox
=
DirectorySandbox
(
str
(
tmpdir
))
sandbox
.
run
(
self
.
_file_writer
(
os
.
devnull
)
)
with
DirectorySandbox
(
str
(
tmpdir
)):
self
.
_file_writer
(
os
.
devnull
)
@
staticmethod
def
_file_writer
(
path
):
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment