Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
fslpy
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FSL
fslpy
Commits
cf23dcfb
Commit
cf23dcfb
authored
4 years ago
by
Paul McCarthy
Browse files
Options
Downloads
Patches
Plain Diff
MNT: Avoid collections.abc warning, minor formatting
parent
49c91d74
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
fsl/utils/path.py
+13
-8
13 additions, 8 deletions
fsl/utils/path.py
fsl/utils/platform.py
+4
-0
4 additions, 0 deletions
fsl/utils/platform.py
fsl/utils/run.py
+16
-14
16 additions, 14 deletions
fsl/utils/run.py
with
33 additions
and
22 deletions
fsl/utils/path.py
+
13
−
8
View file @
cf23dcfb
...
@@ -23,6 +23,8 @@ paths.
...
@@ -23,6 +23,8 @@ paths.
removeDuplicates
removeDuplicates
uniquePrefix
uniquePrefix
commonBase
commonBase
wslpath
winpath
"""
"""
...
@@ -30,10 +32,11 @@ import os.path as op
...
@@ -30,10 +32,11 @@ import os.path as op
import
os
import
os
import
glob
import
glob
import
operator
import
operator
import
re
import
re
from
fsl.utils.platform
import
platform
from
fsl.utils.platform
import
platform
class
PathError
(
Exception
):
class
PathError
(
Exception
):
"""
``Exception`` class raised by the functions defined in this module
"""
``Exception`` class raised by the functions defined in this module
when something goes wrong.
when something goes wrong.
...
@@ -527,17 +530,18 @@ def commonBase(paths):
...
@@ -527,17 +530,18 @@ def commonBase(paths):
raise
PathError
(
'
No common base
'
)
raise
PathError
(
'
No common base
'
)
def
wslpath
(
winpath
):
def
wslpath
(
winpath
):
"""
"""
Convert Windows path (or a command line argument containing a Windows path)
Convert Windows path (or a command line argument containing a Windows path)
to the equivalent WSL path (e.g. ``c:
\\
Users`` -> ``/mnt/c/Users``). Also supports
to the equivalent WSL path (e.g. ``c:
\\
Users`` -> ``/mnt/c/Users``). Also supports
paths in the form ``
\\
wsl$
\\
(distro)
\\
users
\\
...``
paths in the form ``
\\
wsl$
\\
(distro)
\\
users
\\
...``
:param winpath: Command line argument which may (or may not) contain a Windows path. It is assumed to be
:param winpath: Command line argument which may (or may not) contain a Windows path. It is assumed to be
either of the form <windows path> or --<arg>=<windows path>. Note that we don
'
t need to
either of the form <windows path> or --<arg>=<windows path>. Note that we don
'
t need to
handle --arg <windows path> or -a <windows path> since in these cases the argument
handle --arg <windows path> or -a <windows path> since in these cases the argument
and the path will be parsed as separate entities.
and the path will be parsed as separate entities.
:return: If ``winpath`` matches a Windows path, the converted argument (including the --<arg>= portion).
:return: If ``winpath`` matches a Windows path, the converted argument (including the --<arg>= portion).
Otherwise returns ``winpath`` unchanged.
Otherwise returns ``winpath`` unchanged.
"""
"""
match
=
re
.
match
(
r
"
^(--[\w-]+=)?\\\\wsl\$[\\\/][^\\^\/]+(.*)$
"
,
winpath
)
match
=
re
.
match
(
r
"
^(--[\w-]+=)?\\\\wsl\$[\\\/][^\\^\/]+(.*)$
"
,
winpath
)
...
@@ -552,10 +556,11 @@ def wslpath(winpath):
...
@@ -552,10 +556,11 @@ def wslpath(winpath):
arg
,
drive
,
path
=
match
.
group
(
1
,
2
,
3
)
arg
,
drive
,
path
=
match
.
group
(
1
,
2
,
3
)
if
arg
is
None
:
if
arg
is
None
:
arg
=
""
arg
=
""
return
arg
+
"
/mnt/
"
+
drive
.
lower
()
+
path
.
replace
(
"
\\
"
,
"
/
"
)
return
arg
+
"
/mnt/
"
+
drive
.
lower
()
+
path
.
replace
(
"
\\
"
,
"
/
"
)
return
winpath
return
winpath
def
winpath
(
wslpath
):
def
winpath
(
wslpath
):
"""
"""
Convert a WSL-local filepath (for example ``/usr/local/fsl/``) into a path that can be used from
Convert a WSL-local filepath (for example ``/usr/local/fsl/``) into a path that can be used from
...
...
This diff is collapsed.
Click to expand it.
fsl/utils/platform.py
+
4
−
0
View file @
cf23dcfb
...
@@ -285,16 +285,19 @@ class Platform(notifier.Notifier):
...
@@ -285,16 +285,19 @@ class Platform(notifier.Notifier):
"""
"""
return
os
.
environ
.
get
(
'
FSLDIR
'
,
None
)
return
os
.
environ
.
get
(
'
FSLDIR
'
,
None
)
@property
@property
def
fsldevdir
(
self
):
def
fsldevdir
(
self
):
"""
The FSL development directory location.
"""
"""
The FSL development directory location.
"""
return
os
.
environ
.
get
(
'
FSLDEVDIR
'
,
None
)
return
os
.
environ
.
get
(
'
FSLDEVDIR
'
,
None
)
@property
@property
def
fslwsl
(
self
):
def
fslwsl
(
self
):
"""
Boolean flag indicating whether FSL is installed in Windows Subsystem for Linux
"""
"""
Boolean flag indicating whether FSL is installed in Windows Subsystem for Linux
"""
return
self
.
fsldir
is
not
None
and
self
.
fsldir
.
startswith
(
"
\\\\
wsl$
"
)
return
self
.
fsldir
is
not
None
and
self
.
fsldir
.
startswith
(
"
\\\\
wsl$
"
)
@fsldir.setter
@fsldir.setter
def
fsldir
(
self
,
value
):
def
fsldir
(
self
,
value
):
"""
Changes the value of the :attr:`fsldir` property, and notifies any
"""
Changes the value of the :attr:`fsldir` property, and notifies any
...
@@ -404,6 +407,7 @@ class Platform(notifier.Notifier):
...
@@ -404,6 +407,7 @@ class Platform(notifier.Notifier):
"""
"""
return
self
.
__glIsSoftware
return
self
.
__glIsSoftware
platform
=
Platform
()
platform
=
Platform
()
"""
An instance of the :class:`Platform` class. Feel free to create your own
"""
An instance of the :class:`Platform` class. Feel free to create your own
instance, but be aware that if you do so you will not be updated of changes
instance, but be aware that if you do so you will not be updated of changes
...
...
This diff is collapsed.
Click to expand it.
fsl/utils/run.py
+
16
−
14
View file @
cf23dcfb
...
@@ -20,17 +20,17 @@
...
@@ -20,17 +20,17 @@
"""
"""
import
sys
import
sys
import
shlex
import
shlex
import
logging
import
logging
import
threading
import
threading
import
contextlib
import
contextlib
import
collections
import
collections
.abc
as
abc
import
subprocess
as
sp
import
subprocess
as
sp
import
os.path
as
op
import
os.path
as
op
import
os
import
os
import
six
import
six
from
fsl.utils.platform
import
platform
as
fslplatform
from
fsl.utils.platform
import
platform
as
fslplatform
import
fsl.utils.fslsub
as
fslsub
import
fsl.utils.fslsub
as
fslsub
...
@@ -203,7 +203,7 @@ def run(*args, **kwargs):
...
@@ -203,7 +203,7 @@ def run(*args, **kwargs):
if
submit
is
True
:
if
submit
is
True
:
submit
=
dict
()
submit
=
dict
()
if
submit
is
not
None
and
not
isinstance
(
submit
,
collections
.
Mapping
):
if
submit
is
not
None
and
not
isinstance
(
submit
,
abc
.
Mapping
):
raise
ValueError
(
'
submit must be a mapping containing
'
raise
ValueError
(
'
submit must be a mapping containing
'
'
options for fsl.utils.fslsub.submit
'
)
'
options for fsl.utils.fslsub.submit
'
)
...
@@ -377,16 +377,17 @@ def runfsl(*args, **kwargs):
...
@@ -377,16 +377,17 @@ def runfsl(*args, **kwargs):
return
run
(
*
args
,
**
kwargs
)
return
run
(
*
args
,
**
kwargs
)
def
wslcmd
(
cmdpath
,
*
args
):
def
wslcmd
(
cmdpath
,
*
args
):
"""
"""
Convert a command + arguments into an equivalent set of arguments that will run the command
Convert a command + arguments into an equivalent set of arguments that will run the command
under Windows Subsystem for Linux
under Windows Subsystem for Linux
:param cmdpath: Fully qualified path to the command. This is essentially a WSL path not a Windows
:param cmdpath: Fully qualified path to the command. This is essentially a WSL path not a Windows
one since FSLDIR is specified as a WSL path, however it may have backslashes
one since FSLDIR is specified as a WSL path, however it may have backslashes
as path separators due to previous use of ``os.path.join``
as path separators due to previous use of ``os.path.join``
:param args: Sequence of command arguments (the first of which is the unqualified command name)
:param args: Sequence of command arguments (the first of which is the unqualified command name)
:return: If ``cmdpath`` exists and is executable in WSL, return a sequence of command arguments
:return: If ``cmdpath`` exists and is executable in WSL, return a sequence of command arguments
which when executed will run the command in WSL. Windows paths in the argument list will
which when executed will run the command in WSL. Windows paths in the argument list will
be converted to WSL paths. If ``cmdpath`` was not executable in WSL, returns None
be converted to WSL paths. If ``cmdpath`` was not executable in WSL, returns None
...
@@ -423,6 +424,7 @@ def wslcmd(cmdpath, *args):
...
@@ -423,6 +424,7 @@ def wslcmd(cmdpath, *args):
# Command was not found in WSL with this path
# Command was not found in WSL with this path
return
None
return
None
def
wait
(
job_ids
):
def
wait
(
job_ids
):
"""
Proxy for :func:`.fslsub.wait`.
"""
"""
Proxy for :func:`.fslsub.wait`.
"""
return
fslsub
.
wait
(
job_ids
)
return
fslsub
.
wait
(
job_ids
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment