Expand $VARS and ~names in a string, like a shell :Examples: In [2]: os.environ['FOO']='test' In [3]: expand_path('variable FOO is $FOO') Out[3]: 'variable FOO is test'
(s)
| 280 | return locate_profile(profile=profile) |
| 281 | |
| 282 | def expand_path(s): |
| 283 | """Expand $VARS and ~names in a string, like a shell |
| 284 | |
| 285 | :Examples: |
| 286 | |
| 287 | In [2]: os.environ['FOO']='test' |
| 288 | |
| 289 | In [3]: expand_path('variable FOO is $FOO') |
| 290 | Out[3]: 'variable FOO is test' |
| 291 | """ |
| 292 | # This is a pretty subtle hack. When expand user is given a UNC path |
| 293 | # on Windows (\\server\share$\%username%), os.path.expandvars, removes |
| 294 | # the $ to get (\\server\share\%username%). I think it considered $ |
| 295 | # alone an empty var. But, we need the $ to remains there (it indicates |
| 296 | # a hidden share). |
| 297 | if os.name=='nt': |
| 298 | s = s.replace('$\\', 'IPYTHON_TEMP') |
| 299 | s = os.path.expandvars(os.path.expanduser(s)) |
| 300 | if os.name=='nt': |
| 301 | s = s.replace('IPYTHON_TEMP', '$\\') |
| 302 | return s |
| 303 | |
| 304 | |
| 305 | def unescape_glob(string): |
no outgoing calls
no test coverage detected