##// END OF EJS Templates
Fixing subtle bug in expanduser(expandvars(path)) on Windows....
Brian Granger -
Show More
@@ -29,6 +29,7 b' from IPython.core.application import Application'
29 from IPython.core.component import Component
29 from IPython.core.component import Component
30 from IPython.config.loader import ArgParseConfigLoader, NoConfigDefault
30 from IPython.config.loader import ArgParseConfigLoader, NoConfigDefault
31 from IPython.utils.traitlets import Unicode, Bool
31 from IPython.utils.traitlets import Unicode, Bool
32 from IPython.utils import genutils
32
33
33 #-----------------------------------------------------------------------------
34 #-----------------------------------------------------------------------------
34 # Imports
35 # Imports
@@ -216,9 +217,9 b' class ClusterDir(Component):'
216 ----------
217 ----------
217 cluster_dir : unicode or str
218 cluster_dir : unicode or str
218 The path of the cluster directory. This is expanded using
219 The path of the cluster directory. This is expanded using
219 :func:`os.path.expandvars` and :func:`os.path.expanduser`.
220 :func:`IPython.utils.genutils.expand_path`.
220 """
221 """
221 cluster_dir = os.path.expandvars(os.path.expanduser(cluster_dir))
222 cluster_dir = genutils.expand_path(cluster_dir)
222 if not os.path.isdir(cluster_dir):
223 if not os.path.isdir(cluster_dir):
223 raise ClusterDirError('Cluster directory not found: %s' % cluster_dir)
224 raise ClusterDirError('Cluster directory not found: %s' % cluster_dir)
224 return ClusterDir(cluster_dir)
225 return ClusterDir(cluster_dir)
@@ -324,7 +325,7 b' class ApplicationWithClusterDir(Application):'
324 cluster_dir = self.command_line_config.Global.cluster_dir
325 cluster_dir = self.command_line_config.Global.cluster_dir
325 except AttributeError:
326 except AttributeError:
326 cluster_dir = self.default_config.Global.cluster_dir
327 cluster_dir = self.default_config.Global.cluster_dir
327 cluster_dir = os.path.expandvars(os.path.expanduser(cluster_dir))
328 cluster_dir = genutils.expand_path(cluster_dir)
328 try:
329 try:
329 self.cluster_dir_obj = ClusterDir.find_cluster_dir(cluster_dir)
330 self.cluster_dir_obj = ClusterDir.find_cluster_dir(cluster_dir)
330 except ClusterDirError:
331 except ClusterDirError:
@@ -559,9 +559,7 b' def filefind(filename, path_dirs=None):'
559 path_dirs = (path_dirs,)
559 path_dirs = (path_dirs,)
560 for path in path_dirs:
560 for path in path_dirs:
561 if path == '.': path = os.getcwd()
561 if path == '.': path = os.getcwd()
562 testname = os.path.expandvars(
562 testname = expand_path(os.path.join(path, filename))
563 os.path.expanduser(
564 os.path.join(path, filename)))
565 if os.path.isfile(testname):
563 if os.path.isfile(testname):
566 return os.path.abspath(testname)
564 return os.path.abspath(testname)
567 raise IOError("File does not exist in any "
565 raise IOError("File does not exist in any "
@@ -1740,7 +1738,7 b' def extract_vars_above(*names):'
1740 callerNS = sys._getframe(2).f_locals
1738 callerNS = sys._getframe(2).f_locals
1741 return dict((k,callerNS[k]) for k in names)
1739 return dict((k,callerNS[k]) for k in names)
1742
1740
1743 def shexp(s):
1741 def expand_path(s):
1744 """Expand $VARS and ~names in a string, like a shell
1742 """Expand $VARS and ~names in a string, like a shell
1745
1743
1746 :Examples:
1744 :Examples:
@@ -1750,8 +1748,17 b' def shexp(s):'
1750 In [3]: shexp('variable FOO is $FOO')
1748 In [3]: shexp('variable FOO is $FOO')
1751 Out[3]: 'variable FOO is test'
1749 Out[3]: 'variable FOO is test'
1752 """
1750 """
1753 return os.path.expandvars(os.path.expanduser(s))
1751 # This is a pretty subtle hack. When expand user is given a UNC path
1754
1752 # on Windows (\\server\share$\%username%), os.path.expandvars, removes
1753 # the $ to get (\\server\share\%username%). I think it considered $
1754 # alone an empty var. But, we need the $ to remains there (it indicates
1755 # a hidden share).
1756 if os.name=='nt':
1757 s.replace('$\\', 'IPYTHON_TEMP')
1758 s2 = os.path.expandvars(os.path.expanduser(s))
1759 if os.name=='nt':
1760 s2.replace('IPYTHON_TEMP', '$\\')
1761 return s2
1755
1762
1756 def list_strings(arg):
1763 def list_strings(arg):
1757 """Always return a list of strings, given a string or list of strings
1764 """Always return a list of strings, given a string or list of strings
General Comments 0
You need to be logged in to leave comments. Login now