##// 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 29 from IPython.core.component import Component
30 30 from IPython.config.loader import ArgParseConfigLoader, NoConfigDefault
31 31 from IPython.utils.traitlets import Unicode, Bool
32 from IPython.utils import genutils
32 33
33 34 #-----------------------------------------------------------------------------
34 35 # Imports
@@ -216,9 +217,9 b' class ClusterDir(Component):'
216 217 ----------
217 218 cluster_dir : unicode or str
218 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 223 if not os.path.isdir(cluster_dir):
223 224 raise ClusterDirError('Cluster directory not found: %s' % cluster_dir)
224 225 return ClusterDir(cluster_dir)
@@ -324,7 +325,7 b' class ApplicationWithClusterDir(Application):'
324 325 cluster_dir = self.command_line_config.Global.cluster_dir
325 326 except AttributeError:
326 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 329 try:
329 330 self.cluster_dir_obj = ClusterDir.find_cluster_dir(cluster_dir)
330 331 except ClusterDirError:
@@ -559,9 +559,7 b' def filefind(filename, path_dirs=None):'
559 559 path_dirs = (path_dirs,)
560 560 for path in path_dirs:
561 561 if path == '.': path = os.getcwd()
562 testname = os.path.expandvars(
563 os.path.expanduser(
564 os.path.join(path, filename)))
562 testname = expand_path(os.path.join(path, filename))
565 563 if os.path.isfile(testname):
566 564 return os.path.abspath(testname)
567 565 raise IOError("File does not exist in any "
@@ -1740,7 +1738,7 b' def extract_vars_above(*names):'
1740 1738 callerNS = sys._getframe(2).f_locals
1741 1739 return dict((k,callerNS[k]) for k in names)
1742 1740
1743 def shexp(s):
1741 def expand_path(s):
1744 1742 """Expand $VARS and ~names in a string, like a shell
1745 1743
1746 1744 :Examples:
@@ -1750,8 +1748,17 b' def shexp(s):'
1750 1748 In [3]: shexp('variable FOO is $FOO')
1751 1749 Out[3]: 'variable FOO is test'
1752 1750 """
1753 return os.path.expandvars(os.path.expanduser(s))
1754
1751 # This is a pretty subtle hack. When expand user is given a UNC path
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 1763 def list_strings(arg):
1757 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