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
962664bb
Commit
962664bb
authored
Feb 15, 2014
by
Arfrever Frehtes Taifersar Arahesis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use tempfile.TemporaryDirectory() with Python >=3.2.
parent
0daefd2b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
25 deletions
+31
-25
setuptools/py31compat.py
setuptools/py31compat.py
+26
-0
setuptools/svn_utils.py
setuptools/svn_utils.py
+5
-25
No files found.
setuptools/py31compat.py
View file @
962664bb
...
...
@@ -9,3 +9,29 @@ except ImportError:
if
name
not
in
(
'platlib'
,
'purelib'
):
raise
ValueError
(
"Name must be purelib or platlib"
)
return
get_python_lib
(
name
==
'platlib'
)
try
:
# Python >=3.2
from
tempfile
import
TemporaryDirectory
except
ImportError
:
import
shutil
import
tempfile
class
TemporaryDirectory
(
object
):
""""
Very simple temporary directory context manager.
Will try to delete afterward, but will also ignore OS and similar
errors on deletion.
"""
def
__init__
(
self
):
self
.
name
=
None
# Handle mkdtemp raising an exception
self
.
name
=
tempfile
.
mkdtemp
()
def
__enter__
(
self
):
return
self
.
name
def
__exit__
(
self
,
exctype
,
excvalue
,
exctrace
):
try
:
shutil
.
rmtree
(
self
.
name
,
True
)
except
OSError
:
#removal errors are not the only possible
pass
self
.
name
=
None
setuptools/svn_utils.py
View file @
962664bb
...
...
@@ -5,12 +5,12 @@ from distutils import log
import
xml.dom.pulldom
import
shlex
import
shutil
import
tempfile
import
locale
import
codecs
import
unicodedata
import
warnings
from
setuptools.compat
import
unicode
from
setuptools.py31compat
import
TemporaryDirectory
from
xml.sax.saxutils
import
unescape
try
:
...
...
@@ -29,26 +29,6 @@ from subprocess import Popen as _Popen, PIPE as _PIPE
# http://stackoverflow.com/questions/5658622/
# python-subprocess-popen-environment-path
class
TempDir
(
object
):
""""
Very simple temporary directory context manager.
Will try to delete afterward, but will also ignore OS and similar
errors on deletion.
"""
def
__init__
(
self
):
self
.
path
=
None
def
__enter__
(
self
):
self
.
path
=
tempfile
.
mkdtemp
()
return
self
def
__exit__
(
self
,
exctype
,
excvalue
,
exctrace
):
try
:
shutil
.
rmtree
(
self
.
path
,
True
)
except
OSError
:
#removal errors are not the only possible
pass
self
.
path
=
None
def
_run_command
(
args
,
stdout
=
_PIPE
,
stderr
=
_PIPE
,
encoding
=
None
,
stream
=
0
):
#regarding the shell argument, see: http://bugs.python.org/issue8557
try
:
...
...
@@ -256,9 +236,9 @@ class SvnInfo(object):
# This is needed because .svn always creates .subversion and
# some operating systems do not handle dot directory correctly.
# Real queries in real svn repos with be concerned with it creation
with
Temp
Dir
()
as
tempdir
:
with
Temp
oraryDirectory
()
as
tempdir
:
code
,
data
=
_run_command
([
'svn'
,
'--config-dir'
,
tempdir
.
path
,
'--config-dir'
,
tempdir
,
'--version'
,
'--quiet'
])
...
...
@@ -282,9 +262,9 @@ class SvnInfo(object):
# This is needed because .svn always creates .subversion and
# some operating systems do not handle dot directory correctly.
# Real queries in real svn repos with be concerned with it creation
with Temp
Dir
() as tempdir:
with Temp
oraryDirectory
() as tempdir:
code, data = _run_command(['
svn
',
'
--
config
-
dir
', tempdir
.path
,
'
--
config
-
dir
', tempdir,
'
info
', normdir])
# Must check for some contents, as some use empty directories
...
...
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