summaryrefslogtreecommitdiff
path: root/Lib/sysconfig.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@haypocalc.com>2010-10-12 22:53:51 +0000
committerVictor Stinner <victor.stinner@haypocalc.com>2010-10-12 22:53:51 +0000
commitd2f6ae63cd546d84310324012740425772e83de7 (patch)
treea46ffb06d8806f6e6a08d0fd728fda5f2ad9a55b /Lib/sysconfig.py
parent169b133c82ef1463444c6835e37760addb6c3d68 (diff)
downloadcpython-git-d2f6ae63cd546d84310324012740425772e83de7.tar.gz
Merged revisions 85386-85387,85389 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r85386 | victor.stinner | 2010-10-13 00:23:23 +0200 (mer., 13 oct. 2010) | 3 lines Issue #6612: Fix site and sysconfig to catch os.getcwd() error, eg. if the current directory was deleted. ........ r85387 | victor.stinner | 2010-10-13 00:26:08 +0200 (mer., 13 oct. 2010) | 2 lines #6612: add the author of the patch (W. Trevor King) ........ r85389 | victor.stinner | 2010-10-13 00:42:37 +0200 (mer., 13 oct. 2010) | 2 lines NEWS: Move #6612 to Library section ........
Diffstat (limited to 'Lib/sysconfig.py')
-rw-r--r--Lib/sysconfig.py25
1 files changed, 18 insertions, 7 deletions
diff --git a/Lib/sysconfig.py b/Lib/sysconfig.py
index b8880f5355..5d5d5c0100 100644
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -93,21 +93,28 @@ _PREFIX = os.path.normpath(sys.prefix)
_EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
_CONFIG_VARS = None
_USER_BASE = None
+
+def _safe_realpath(path):
+ try:
+ return realpath(path)
+ except OSError:
+ return path
+
if sys.executable:
- _PROJECT_BASE = os.path.dirname(realpath(sys.executable))
+ _PROJECT_BASE = os.path.dirname(_safe_realpath(sys.executable))
else:
# sys.executable can be empty if argv[0] has been changed and Python is
# unable to retrieve the real program name
- _PROJECT_BASE = realpath(os.getcwd())
+ _PROJECT_BASE = _safe_realpath(os.getcwd())
if os.name == "nt" and "pcbuild" in _PROJECT_BASE[-8:].lower():
- _PROJECT_BASE = realpath(os.path.join(_PROJECT_BASE, pardir))
+ _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir))
# PC/VS7.1
if os.name == "nt" and "\\pc\\v" in _PROJECT_BASE[-10:].lower():
- _PROJECT_BASE = realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
+ _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
# PC/AMD64
if os.name == "nt" and "\\pcbuild\\amd64" in _PROJECT_BASE[-14:].lower():
- _PROJECT_BASE = realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
+ _PROJECT_BASE = _safe_realpath(os.path.join(_PROJECT_BASE, pardir, pardir))
def is_python_build():
for fn in ("Setup.dist", "Setup.local"):
@@ -319,7 +326,7 @@ def _init_non_posix(vars):
vars['SO'] = '.pyd'
vars['EXE'] = '.exe'
vars['VERSION'] = _PY_VERSION_SHORT_NO_DOT
- vars['BINDIR'] = os.path.dirname(realpath(sys.executable))
+ vars['BINDIR'] = os.path.dirname(_safe_realpath(sys.executable))
#
# public APIs
@@ -439,8 +446,12 @@ def get_config_vars(*args):
# from a different directory.
if _PYTHON_BUILD and os.name == "posix":
base = _PROJECT_BASE
+ try:
+ cwd = os.getcwd()
+ except OSError:
+ cwd = None
if (not os.path.isabs(_CONFIG_VARS['srcdir']) and
- base != os.getcwd()):
+ base != cwd):
# srcdir is relative and we are not in the same directory
# as the executable. Assume executable is in the build
# directory and make srcdir absolute.