OLD | NEW |
(Empty) | |
| 1 import sys |
| 2 import unittest |
| 3 |
| 4 __all__ = ['get_config_vars', 'get_path'] |
| 5 |
| 6 try: |
| 7 # Python 2.7 or >=3.2 |
| 8 from sysconfig import get_config_vars, get_path |
| 9 except ImportError: |
| 10 from distutils.sysconfig import get_config_vars, get_python_lib |
| 11 |
| 12 def get_path(name): |
| 13 if name not in ('platlib', 'purelib'): |
| 14 raise ValueError("Name must be purelib or platlib") |
| 15 return get_python_lib(name == 'platlib') |
| 16 |
| 17 |
| 18 try: |
| 19 # Python >=3.2 |
| 20 from tempfile import TemporaryDirectory |
| 21 except ImportError: |
| 22 import shutil |
| 23 import tempfile |
| 24 |
| 25 class TemporaryDirectory(object): |
| 26 """ |
| 27 Very simple temporary directory context manager. |
| 28 Will try to delete afterward, but will also ignore OS and similar |
| 29 errors on deletion. |
| 30 """ |
| 31 |
| 32 def __init__(self): |
| 33 self.name = None # Handle mkdtemp raising an exception |
| 34 self.name = tempfile.mkdtemp() |
| 35 |
| 36 def __enter__(self): |
| 37 return self.name |
| 38 |
| 39 def __exit__(self, exctype, excvalue, exctrace): |
| 40 try: |
| 41 shutil.rmtree(self.name, True) |
| 42 except OSError: # removal errors are not the only possible |
| 43 pass |
| 44 self.name = None |
| 45 |
| 46 |
| 47 unittest_main = unittest.main |
| 48 |
| 49 _PY31 = (3, 1) <= sys.version_info[:2] < (3, 2) |
| 50 if _PY31: |
| 51 # on Python 3.1, translate testRunner==None to TextTestRunner |
| 52 # for compatibility with Python 2.6, 2.7, and 3.2+ |
| 53 def unittest_main(*args, **kwargs): |
| 54 if 'testRunner' in kwargs and kwargs['testRunner'] is None: |
| 55 kwargs['testRunner'] = unittest.TextTestRunner |
| 56 return unittest.main(*args, **kwargs) |
OLD | NEW |