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
conda
installer
Commits
479a677f
Commit
479a677f
authored
Aug 12, 2021
by
Paul McCarthy
🚵
Browse files
Merge branch 'rf/install-base-first' into 'master'
Rf/install base first Closes #1 See merge request fsl/conda/installer!16
parents
0c540eb0
1098bf66
Changes
2
Show whitespace changes
Inline
Side-by-side
fslinstaller.py
View file @
479a677f
...
@@ -52,7 +52,7 @@ log = logging.getLogger(__name__)
...
@@ -52,7 +52,7 @@ log = logging.getLogger(__name__)
__absfile__
=
op
.
abspath
(
__file__
).
rstrip
(
'c'
)
__absfile__
=
op
.
abspath
(
__file__
).
rstrip
(
'c'
)
__version__
=
'1.
2
.0'
__version__
=
'1.
3
.0'
"""Installer script version number. This is automatically updated
"""Installer script version number. This is automatically updated
whenever a new version of the installer script is released.
whenever a new version of the installer script is released.
"""
"""
...
@@ -160,10 +160,12 @@ class Context(object):
...
@@ -160,10 +160,12 @@ class Context(object):
self
.
old_destdir
=
None
self
.
old_destdir
=
None
# The download_fsl_environment function stores
# The download_fsl_environment function stores
# the path to the FSL conda environment file
# the path to the FSL conda environment file,
# and list of conda channels here
# list of conda channels, and fsl-base version,
# here.
self
.
environment_file
=
None
self
.
environment_file
=
None
self
.
environment_channels
=
None
self
.
environment_channels
=
None
self
.
fsl_base_version
=
None
# The config_logging function stores the path
# The config_logging function stores the path
# to the fslinstaller log file here.
# to the fslinstaller log file here.
...
@@ -719,6 +721,14 @@ class Progress(object):
...
@@ -719,6 +721,14 @@ class Progress(object):
return
fallback
return
fallback
def
isstr
(
s
):
"""Returns True if s is a string, False otherwise, Works on python 2.7
and >=3.3.
"""
try
:
return
isinstance
(
s
,
basestring
)
except
Exception
:
return
isinstance
(
s
,
str
)
@
contextlib
.
contextmanager
@
contextlib
.
contextmanager
def
tempdir
(
override_dir
=
None
):
def
tempdir
(
override_dir
=
None
):
"""Returns a context manager which creates, changes into, and returns a
"""Returns a context manager which creates, changes into, and returns a
...
@@ -921,16 +931,25 @@ class Process(object):
...
@@ -921,16 +931,25 @@ class Process(object):
@
staticmethod
@
staticmethod
def
monitor_progress
(
cmd
,
total
=
None
,
*
args
,
**
kwargs
):
def
monitor_progress
(
cmd
,
total
=
None
,
*
args
,
**
kwargs
):
"""Runs the given command, and shows a progress bar under the
"""Runs the given command
(s)
, and shows a progress bar under the
assumption that cmd will produce "total" number of lines of output.
assumption that cmd will produce "total" number of lines of output.
:arg cmd: The commmand to run as a string, or a sequence of
multiple commands.
:arg total: Total number of lines of standard output to expect.
"""
"""
if
total
is
None
:
label
=
None
if
total
is
None
:
label
=
None
else
:
label
=
'%'
else
:
label
=
'%'
if
isstr
(
cmd
):
cmds
=
[
cmd
]
else
:
cmds
=
cmd
with
Progress
(
label
=
label
,
with
Progress
(
label
=
label
,
fmt
=
'{:.0f}'
,
fmt
=
'{:.0f}'
,
transform
=
Progress
.
percent
)
as
prog
:
transform
=
Progress
.
percent
)
as
prog
:
for
cmd
in
cmds
:
proc
=
Process
(
cmd
,
*
args
,
**
kwargs
)
proc
=
Process
(
cmd
,
*
args
,
**
kwargs
)
nlines
=
0
if
total
else
None
nlines
=
0
if
total
else
None
...
@@ -951,7 +970,8 @@ class Process(object):
...
@@ -951,7 +970,8 @@ class Process(object):
if
proc
.
returncode
==
0
:
if
proc
.
returncode
==
0
:
prog
.
update
(
total
,
total
)
prog
.
update
(
total
,
total
)
else
:
else
:
raise
RuntimeError
(
'This command returned an error: '
+
cmd
)
raise
RuntimeError
(
'This command returned '
'an error: '
+
cmd
)
@
staticmethod
@
staticmethod
...
@@ -1099,7 +1119,14 @@ def download_fsl_environment(ctx):
...
@@ -1099,7 +1119,14 @@ def download_fsl_environment(ctx):
# file, and save them to ctx.environment_channels.
# file, and save them to ctx.environment_channels.
# The install_miniconda function will then add the
# The install_miniconda function will then add the
# channels to $FSLDIR/.condarc.
# channels to $FSLDIR/.condarc.
#
# The fsl-base version is installed before any other
# packages, as other FSL packages require it to be
# present in order to install successfully. So we
# also extract the fsl-base vesrion number from
# the environment file, and store it in the context.
channels
=
[]
channels
=
[]
basever
=
None
copy
=
'.'
+
op
.
basename
(
ctx
.
environment_file
)
copy
=
'.'
+
op
.
basename
(
ctx
.
environment_file
)
shutil
.
move
(
ctx
.
environment_file
,
copy
)
shutil
.
move
(
ctx
.
environment_file
,
copy
)
with
open
(
copy
,
'rt'
)
as
inf
,
\
with
open
(
copy
,
'rt'
)
as
inf
,
\
...
@@ -1122,9 +1149,15 @@ def download_fsl_environment(ctx):
...
@@ -1122,9 +1149,15 @@ def download_fsl_environment(ctx):
channels
.
append
(
line
.
split
()[
-
1
])
channels
.
append
(
line
.
split
()[
-
1
])
continue
continue
# save fsl-base version, as
# we install it separately
if
line
.
strip
().
startswith
(
'- fsl-base'
):
basever
=
line
.
split
()[
2
]
outf
.
write
(
line
)
outf
.
write
(
line
)
ctx
.
environment_channels
=
channels
ctx
.
environment_channels
=
channels
ctx
.
fsl_base_version
=
basever
def
download_miniconda
(
ctx
):
def
download_miniconda
(
ctx
):
...
@@ -1229,7 +1262,22 @@ def install_fsl(ctx):
...
@@ -1229,7 +1262,22 @@ def install_fsl(ctx):
else
:
output
=
int
(
output
)
else
:
output
=
int
(
output
)
conda
=
op
.
join
(
ctx
.
destdir
,
'bin'
,
'conda'
)
conda
=
op
.
join
(
ctx
.
destdir
,
'bin'
,
'conda'
)
cmd
=
conda
+
' env update -n base -f '
+
ctx
.
environment_file
# We install FSL in two steps:
#
# 1. Install fsl-base. This is installed first, as other
# FSL packages require it to be present during installation,
# (in their post-link.sh scripts), and this is not
# guaranteed if everything is installed simultaneously
# 2. Install everything else.
#
# The download_fsl_environment function extracts the appropriate
# fsl-base version to install.
commands
=
[]
if
ctx
.
fsl_base_version
is
not
None
:
commands
.
append
(
conda
+
'install -y -n base fsl-base='
+
ctx
.
fsl_base_version
)
commands
.
append
(
conda
+
' env update -n base -f '
+
ctx
.
environment_file
)
printmsg
(
'Installing FSL into {}...'
.
format
(
ctx
.
destdir
))
printmsg
(
'Installing FSL into {}...'
.
format
(
ctx
.
destdir
))
...
@@ -1255,7 +1303,7 @@ def install_fsl(ctx):
...
@@ -1255,7 +1303,7 @@ def install_fsl(ctx):
if
ctx
.
args
.
username
:
env
[
'FSLCONDA_USERNAME'
]
=
ctx
.
args
.
username
if
ctx
.
args
.
username
:
env
[
'FSLCONDA_USERNAME'
]
=
ctx
.
args
.
username
if
ctx
.
args
.
password
:
env
[
'FSLCONDA_PASSWORD'
]
=
ctx
.
args
.
password
if
ctx
.
args
.
password
:
env
[
'FSLCONDA_PASSWORD'
]
=
ctx
.
args
.
password
Process
.
monitor_progress
(
c
md
,
output
,
ctx
.
need_admin
,
ctx
,
env
=
env
)
Process
.
monitor_progress
(
c
ommands
,
output
,
ctx
.
need_admin
,
ctx
,
env
=
env
)
def
finalise_installation
(
ctx
):
def
finalise_installation
(
ctx
):
...
...
test/test_routines.py
View file @
479a677f
...
@@ -140,6 +140,39 @@ def test_Process_check_output():
...
@@ -140,6 +140,39 @@ def test_Process_check_output():
inst
.
Process
.
check_output
(
op
.
join
(
cwd
,
'script'
))
inst
.
Process
.
check_output
(
op
.
join
(
cwd
,
'script'
))
def
test_Process_monitor_progress
():
with
inst
.
tempdir
()
as
cwd
:
script
=
tw
.
dedent
(
"""
#!/usr/bin/env bash
for ((i=0;i<10;i++)); do
echo $i
done
touch $1
"""
).
strip
()
with
open
(
'script'
,
'wt'
)
as
f
:
f
.
write
(
script
)
os
.
chmod
(
'script'
,
0o755
)
script
=
op
.
join
(
cwd
,
'script'
)
# py2: make sure function accepts string and unicode
scripts
=
[
script
,
u
'{}'
.
format
(
script
)]
for
script
in
scripts
:
inst
.
Process
.
monitor_progress
(
script
+
' a'
)
inst
.
Process
.
monitor_progress
([
script
+
' b'
])
inst
.
Process
.
monitor_progress
([
script
+
' c'
,
script
+
' d'
])
inst
.
Process
.
monitor_progress
(
script
+
' e'
,
10
)
inst
.
Process
.
monitor_progress
([
script
+
' f'
],
10
)
inst
.
Process
.
monitor_progress
([
script
+
' g'
,
script
+
' h'
],
10
)
for
touched
in
'abcdefgh'
:
assert
op
.
exists
(
touched
)
os
.
remove
(
touched
)
def
test_read_fslversion
():
def
test_read_fslversion
():
with
inst
.
tempdir
()
as
cwd
:
with
inst
.
tempdir
()
as
cwd
:
os
.
mkdir
(
'etc'
)
os
.
mkdir
(
'etc'
)
...
...
Write
Preview
Markdown
is supported
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