Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FSL
add_module
Commits
62f9addc
Commit
62f9addc
authored
Oct 26, 2020
by
Paul McCarthy
🚵
Browse files
RF: Roll our own expandvars, because op.expandvars doesn't replace unset
variables with the empty string
parent
ed96be43
Changes
1
Hide whitespace changes
Inline
Side-by-side
fsl/add_module/routines.py
View file @
62f9addc
...
...
@@ -10,6 +10,8 @@ program.
import
os.path
as
op
import
os
import
re
import
math
import
zlib
import
shutil
...
...
@@ -26,11 +28,30 @@ except ImportError: progressbar = None
import
fsl.add_module.admin
as
admin
def
expand
(
path
:
Union
[
str
,
pathlib
.
Path
]):
"""Applies ``os.path.abspath``, ``os.path.expandvars`` and
def
expandvars
(
path
:
Union
[
str
,
pathlib
.
Path
])
->
str
:
"""Alternative to ``os.path.expandvars`` which replaces unset variables
with an empty string.
"""
path
=
str
(
path
)
patterns
=
[
r
'(\$\{(\w+)\})'
,
r
'(\$(\w+))'
,
]
for
pat
in
patterns
:
matches
=
re
.
findall
(
pat
,
path
)
for
fullmatch
,
name
in
matches
:
path
=
path
.
replace
(
fullmatch
,
os
.
environ
.
get
(
name
,
''
))
return
path
def
expand
(
path
:
Union
[
str
,
pathlib
.
Path
])
->
str
:
"""Applies ``os.path.abspath``, :func:`expandvars` and
``os.path.expanduser`` to ``path``.
"""
return
op
.
abspath
(
op
.
expandvars
(
op
.
expanduser
(
path
)))
return
op
.
abspath
(
expandvars
(
op
.
expanduser
(
path
)))
class
DownloadFailed
(
Exception
):
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment