Skip to content

Commit

Permalink
do not try to add miniconda to path when its not in use
Browse files Browse the repository at this point in the history
  • Loading branch information
jhoblitt committed Sep 27, 2017
1 parent b4449bd commit 9405979
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 45 deletions.
53 changes: 31 additions & 22 deletions scripts/newinstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -849,44 +849,46 @@ n8l::problem_vars_check() {

n8l::generate_loader_bash() {
local file_name=${1?file_name is required}
local miniconda_path=${2?miniconda_path is required}
local eups_pkgroot=${2?eups_pkgroot is required}
local miniconda_path=$3

local cmd_setup_miniconda="export PATH=\"${miniconda_path}/bin:\${PATH}\""
if [[ -n $miniconda_path ]]; then
local cmd_setup_miniconda="export PATH=\"${miniconda_path}/bin:\${PATH}\""
fi

# shellcheck disable=SC2094
cat > "$file_name" <<-EOF
# This script is intended to be used with bash to load the minimal LSST
# environment
# Usage: source $(basename "$file_name")
# Setup optional packages
${cmd_setup_miniconda}
LSST_HOME="\$( cd "\$( dirname "\${BASH_SOURCE[0]}" )" && pwd )"
# Bootstrap EUPS
EUPS_DIR="\${LSST_HOME}/eups/$(n8l::eups_slug)"
source "\${EUPS_DIR}/bin/setups.sh"
export EUPS_PKGROOT=\${EUPS_PKGROOT:-$EUPS_PKGROOT}
export EUPS_PKGROOT=\${EUPS_PKGROOT:-$eups_pkgroot}
EOF
}

n8l::generate_loader_csh() {
local file_name=${1?file_name is required}
local miniconda_path=${2?miniconda_path is required}
local eups_pkgroot=${2?eups_pkgroot is required}
local miniconda_path=$3

local cmd_setup_miniconda="setenv PATH ${miniconda_path}/bin:\$PATH"
if [[ -n $miniconda_path ]]; then
local cmd_setup_miniconda="setenv PATH ${miniconda_path}/bin:\$PATH"
fi

# shellcheck disable=SC2094
cat > "$file_name" <<-EOF
# This script is intended to be used with (t)csh to load the minimal LSST
# environment
# Usage: source $(basename "$file_name")
# Setup optional packages
${cmd_setup_miniconda}
set LSST_HOME = \`dirname \$0\`
set LSST_HOME = \`cd \${LSST_HOME} && pwd\`
Expand All @@ -895,68 +897,75 @@ n8l::generate_loader_csh() {
source "\${EUPS_DIR}/bin/setups.csh"
if ( ! \${?EUPS_PKGROOT} ) then
setenv EUPS_PKGROOT "$EUPS_PKGROOT"
setenv EUPS_PKGROOT "$eups_pkgroot"
endif
EOF
}

n8l::generate_loader_ksh() {
local file_name=${1?file_name is required}
local miniconda_path=${2?miniconda_path is required}
local eups_pkgroot=${2?eups_pkgroot is required}
local miniconda_path=$3

local cmd_setup_miniconda="export PATH=\"${miniconda_path}/bin:\${PATH}\""
if [[ -n $miniconda_path ]]; then
local cmd_setup_miniconda="export PATH=\"${miniconda_path}/bin:\${PATH}\""
fi

# shellcheck disable=SC2094
cat > "$file_name" <<-EOF
# This script is intended to be used with ksh to load the minimal LSST
# environment
# Usage: source $(basename "$file_name")
# Setup optional packages
${cmd_setup_miniconda}
LSST_HOME="\$( cd "\$( dirname "\${.sh.file}" )" && pwd )"
# Bootstrap EUPS
EUPS_DIR="\${LSST_HOME}/eups/$(n8l::eups_slug)"
source "\${EUPS_DIR}/bin/setups.sh"
export EUPS_PKGROOT=\${EUPS_PKGROOT:-$EUPS_PKGROOT}
export EUPS_PKGROOT=\${EUPS_PKGROOT:-$eups_pkgroot}
EOF
}

n8l::generate_loader_zsh() {
local file_name=${1?file_name is required}
local miniconda_path=${2?miniconda_path is required}
local eups_pkgroot=${2?eups_pkgroot is required}
local miniconda_path=$3

local cmd_setup_miniconda="export PATH=\"${miniconda_path}/bin:\${PATH}\""
if [[ -n $miniconda_path ]]; then
local cmd_setup_miniconda="export PATH=\"${miniconda_path}/bin:\${PATH}\""
fi

# shellcheck disable=SC2094
cat > "$file_name" <<-EOF
# This script is intended to be used with zsh to load the minimal LSST
# environment
# Usage: source $(basename "$file_name")
# Setup optional packages
${cmd_setup_miniconda}
LSST_HOME=\`dirname "\$0:A"\`
# Bootstrap EUPS
EUPS_DIR="\${LSST_HOME}/eups/$(n8l::eups_slug)"
source "\${EUPS_DIR}/bin/setups.zsh"
export EUPS_PKGROOT=\${EUPS_PKGROOT:-$EUPS_PKGROOT}
export EUPS_PKGROOT=\${EUPS_PKGROOT:-$eups_pkgroot}
EOF
}

n8l::create_load_scripts() {
local prefix=${1?prefix is required}
local miniconda_path=${2?miniconda_path is required}
local eups_pkgroot=${2?eups_pkgroot is required}
local miniconda_path=$3

for sfx in bash ksh csh zsh; do
echo -n "Creating startup scripts (${sfx}) ... "
n8l::generate_loader_$sfx "${prefix}/loadLSST.${sfx}" "$miniconda_path"
# shellcheck disable=SC2086
n8l::generate_loader_$sfx \
"${prefix}/loadLSST.${sfx}" \
"$eups_pkgroot" \
$miniconda_path
echo "done."
done
}
Expand Down
41 changes: 37 additions & 4 deletions spec/unit/n8l/create_load_scripts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,56 @@
end
end

context '$2/miniconda_path' do
context '$2/eups_pkgroot' do
it 'is required' do
out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
"#{func} foo",
)

expect(out).to eq('')
expect(err).to match(/miniconda_path is required/)
expect(err).to match('eups_pkgroot is required')
expect(status.exitstatus).to_not be 0
end
end

context '$3/miniconda_path' do
it 'is optional' do
out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
"#{func} foo bar",
)

expect(out).to match('Creating startup scripts')
expect(err).to eq('')
expect(status.exitstatus).to be 0
end
end
end

it 'does not invent a miniconda_path' do
out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
"#{func} /dne /dne/apple",
)

shells.each { |sh| expect(out).to match(/#{sh}/) }
expect(err).to eq('')
expect(status.exitstatus).to be 0

@cmds.each do |sh, stub|
expect(stub).to be_called_with_arguments.times(1)
expect(stub).to be_called_with_arguments(
"/dne/loadLSST.#{sh}",
'/dne/apple',
)
end
end

it 'works' do
it 'does passes through miniconda_path' do
out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
"#{func} /dne /dne/python/banana",
"#{func} /dne /dne/apple /dne/python/banana",
)

shells.each { |sh| expect(out).to match(/#{sh}/) }
Expand All @@ -59,6 +91,7 @@
expect(stub).to be_called_with_arguments.times(1)
expect(stub).to be_called_with_arguments(
"/dne/loadLSST.#{sh}",
'/dne/apple',
'/dne/python/banana',
)
end
Expand Down
86 changes: 67 additions & 19 deletions spec/unit/n8l/generate_loader_spec.rb
Original file line number Diff line number Diff line change
@@ -1,31 +1,79 @@
require 'rspec/bash'
require 'tempfile'

describe 'n8l::generate_loader' do
describe 'n8l::generate_loader_*' do
include Rspec::Bash

let(:stubbed_env) { create_stubbed_env }

# Unfortunately, this example(s) needs to write to the filesystem. While
# `cat` can be mocked out, bash i/o redirection can not.
%w[bash csh ksh zsh].each do |sh|
context sh do
Tempfile.create(sh) do |f|
it 'writes file' do
out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
"n8l::generate_loader_#{sh} #{f.path} #{f.path}/python/banana",
)

expect(status.exitstatus).to be 0
expect(out).to eq('')
expect(err).to eq('')

expect(File.read(f)).to match(
/This script is intended to be used with.*#{sh}/
)
func = "n8l::generate_loader_#{sh}"

describe func do
context 'parameters' do
context '$1/file_name' do
it 'is required' do
out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
func,
)

expect(out).to eq('')
expect(err).to match('file_name is required')
expect(status.exitstatus).to_not be 0
end
end

context '$2/eups_pkgroot' do
it 'is required' do
out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
"#{func} foo"
)

expect(out).to eq('')
expect(err).to match('eups_pkgroot is required')
expect(status.exitstatus).to_not be 0
end
end
end
end
end

context '$3/miniconda_path' do
%w[with without].each do |have|
Tempfile.create(sh) do |f|
context have do
have == 'with' && miniconda_path = "#{f.path}/python/banana"

it "writes loadLSST script #{have} PATH" do
out, err, status = stubbed_env.execute_function(
'scripts/newinstall.sh',
"#{func} #{f.path} /dne/banana #{miniconda_path}"
)

expect(out).to eq('')
expect(err).to eq('')
expect(status.exitstatus).to be 0

loader = File.read(f)

expect(loader).to match(
"This script is intended to be used with.*#{sh}"
)
expect(loader).to match('/dne/banana')

case have
when 'with'
expect(loader).to match('PATH')
when 'without'
expect(loader).to_not match('PATH')
end
end
end
end # $3/miniconda_path
end # Tempfile
end # have
end # parameters
end # func
end # shell
end

0 comments on commit 9405979

Please sign in to comment.