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
32c396c0
Commit
32c396c0
authored
Mar 20, 2013
by
Jason R. Coombs
Browse files
Options
Browse Files
Download
Plain Diff
Merged sandbox module
--HG-- branch : Setuptools-Distribute merge
parents
d54b82ff
6b9f1df3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
9 deletions
+38
-9
setuptools/sandbox.py
setuptools/sandbox.py
+38
-9
No files found.
setuptools/sandbox.py
View file @
32c396c0
...
...
@@ -9,9 +9,40 @@ except NameError:
_file
=
None
_open
=
open
from
distutils.errors
import
DistutilsError
from
pkg_resources
import
working_set
__all__
=
[
"AbstractSandbox"
,
"DirectorySandbox"
,
"SandboxViolation"
,
"run_setup"
,
]
def
run_setup
(
setup_script
,
args
):
"""Run a distutils setup script, sandboxed in its directory"""
old_dir
=
os
.
getcwd
()
...
...
@@ -29,6 +60,9 @@ def run_setup(setup_script, args):
try
:
sys
.
argv
[:]
=
[
setup_script
]
+
list
(
args
)
sys
.
path
.
insert
(
0
,
setup_dir
)
# reset to include setup dir, w/clean callback list
working_set
.
__init__
()
working_set
.
callbacks
.
append
(
lambda
dist
:
dist
.
activate
())
DirectorySandbox
(
setup_dir
).
run
(
lambda
:
execfile
(
"setup.py"
,
...
...
@@ -55,6 +89,8 @@ def run_setup(setup_script, args):
sys
.
argv
[:]
=
save_argv
tempfile
.
tempdir
=
save_tmp
class
AbstractSandbox
:
"""Wrap 'os' module and 'open()' builtin for virtualizing setup scripts"""
...
...
@@ -86,7 +122,6 @@ class AbstractSandbox:
__builtin__
.
open
=
_open
self
.
_copy
(
_os
)
def
_mk_dual_path_wrapper
(
name
):
original
=
getattr
(
_os
,
name
)
def
wrap
(
self
,
src
,
dst
,
*
args
,
**
kw
):
...
...
@@ -95,7 +130,6 @@ class AbstractSandbox:
return
original
(
src
,
dst
,
*
args
,
**
kw
)
return
wrap
for
name
in
[
"rename"
,
"link"
,
"symlink"
]:
if
hasattr
(
_os
,
name
):
locals
()[
name
]
=
_mk_dual_path_wrapper
(
name
)
...
...
@@ -118,7 +152,6 @@ class AbstractSandbox:
]:
if
hasattr
(
_os
,
name
):
locals
()[
name
]
=
_mk_single_path_wrapper
(
name
)
def
_mk_single_with_return
(
name
):
original
=
getattr
(
_os
,
name
)
def
wrap
(
self
,
path
,
*
args
,
**
kw
):
...
...
@@ -208,6 +241,7 @@ class DirectorySandbox(AbstractSandbox):
self
.
_violation
(
"tmpnam"
)
def
_ok
(
self
,
path
):
if
hasattr
(
_os
,
'devnull'
)
and
path
==
_os
.
devnull
:
return
True
active
=
self
.
_active
try
:
self
.
_active
=
False
...
...
@@ -240,16 +274,11 @@ class DirectorySandbox(AbstractSandbox):
self
.
_violation
(
"os.open"
,
file
,
flags
,
mode
)
return
_os
.
open
(
file
,
flags
,
mode
)
WRITE_FLAGS
=
reduce
(
operator
.
or_
,
[
getattr
(
_os
,
a
,
0
)
for
a
in
operator
.
or_
,
[
getattr
(
_os
,
a
,
0
)
for
a
in
"O_WRONLY O_RDWR O_APPEND O_CREAT O_TRUNC O_TEMPORARY"
.
split
()]
)
class
SandboxViolation
(
DistutilsError
):
"""A setup script attempted to modify the filesystem outside the sandbox"""
...
...
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