Skip to content
Snippets Groups Projects
Commit e5bf4784 authored by Paul McCarthy's avatar Paul McCarthy :mountain_bicyclist:
Browse files

Merge branch 'rf/pythonw' into 'master'

Detect pythonw scripts

Closes #3

See merge request !18
parents 1dfe1085 791c73af
No related branches found
No related tags found
1 merge request!18Detect pythonw scripts
Pipeline #10178 passed
......@@ -8,6 +8,8 @@
- The `$FSLDIR/etc/fslconf/fsl.sh` script now uses `$FSLDIR/etc/fslversion`
to identify official FSL installations - if this file is present,
`$FSLDIR/share/fsl/bin` is automatically added to the `$PATH` variable.
- The `$FSLDIR/share/fsl/sbin/createFSLWrapper` script now detects `pythonw`
executables.
## 2107.3 (Monday 12th July 2021)
......
......@@ -85,27 +85,29 @@ for script in $targets; do
# Figure out whether this is a python
# executable or some other type of
# executable. We search for these strings
# in source file headers to ID them as
# python scripts. We need to check both
# match "#!/usr/bin/env python" and
# "#!<fsldir>/bin/python...", because
# conda might generate one or the other
# in different scenarios.
id1=$(head -c 1024 "$sourceScript" | grep "#!/usr/bin/env python")
id2=$(head -c 1024 "$sourceScript" | grep "#!${FSLDIR%/}/bin/python")
# executable.
id=$(head -c 1024 "$sourceScript" | grep -e '^#!.*pythonw\?$')
# Non-python executable - use a
# pass-through script
if [ -z "$id1" ] && [ -z "$id2" ]; then
# Non-python executable - use
# a pass-through script
if [ -z "$id" ]; then
echo "#!/usr/bin/env bash" > "$targetScript"
echo "$FSLDIR/bin/$script "'"$@"' >> "$targetScript"
else
# Python executable - run it via
# $FSLDIR/bin/python in isolated mode
echo "#!/usr/bin/env bash" > "$targetScript"
echo "$FSLDIR/bin/python -I $sourceScript "'"$@"' >> "$targetScript"
# $FSLDIR/bin/python[w] in isolated
# mode. Under macOS, GUI apps are
# invoked with pythonw, so we need
# to preserve the interpreter.
if [[ "$id" == *"pythonw" ]]; then
interp="pythonw"
else
interp="python"
fi
echo "#!/usr/bin/env bash" > "$targetScript"
echo "${FSLDIR}/bin/${interp} -I $sourceScript "'"$@"' >> "$targetScript"
fi
# Preserve file permissions
......
......@@ -126,6 +126,40 @@ def test_create_python_wrapper():
assert got == expect
def test_create_pythonw_wrapper():
"""Test creation of a wrapper script for a python script which
uses pythonw as the interpreter (for GUI apps on macOS).
"""
hashbangs = [
'#!/bin/bash /usr/bin/pythonw',
'#!/usr/bin/pythonw',
'#!/usr/bin/env pythonw']
with temp_fsldir() as (fsldir, wrapperdir):
script_path = op.join(fsldir, 'bin', 'test_script')
wrapper_path = op.join(wrapperdir, 'test_script')
touch(script_path)
for hb in hashbangs:
with open(script_path, 'wt') as f:
f.write(hb + '\n')
f.write('print("hello")\n')
expect = tw.dedent(f"""
#!/usr/bin/env bash
{fsldir}/bin/pythonw -I {script_path} "$@"
""").strip()
run(f'{CREATE_WRAPPER} test_script')
assert op.exists(wrapper_path)
with open(wrapper_path, 'rt') as f:
got = f.read().strip()
assert got == expect
def test_create_other_wrapper():
"""Test creation of a wrapper script for a non-python executable."""
with temp_fsldir() as (fsldir, wrapperdir):
......@@ -151,6 +185,7 @@ def test_create_other_wrapper():
assert got == expect
def test_permissions_preserved():
"""Test that wrapper script has same permissions as wrapped script."""
with temp_fsldir() as (fsldir, wrapperdir):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment