Skip to content

Commit

Permalink
Merge pull request #16 from crecine/update_install_from_git
Browse files Browse the repository at this point in the history
Fixed issues with conda environments not building successfully
  • Loading branch information
johnjasa authored Jan 2, 2024
2 parents fe58a7e + 00ef1a9 commit 4402ad2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
50 changes: 40 additions & 10 deletions .github/install_env_from_github.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ output_yaml="modified_environment.yml"
if [ "$#" -ge 2 ]; then
env_name=$2
else
env_name="debug_env"
read -r firstline<$input_yaml
env_name=${firstline#*name: }
fi

# Determine if mamba is available and use it; otherwise, use conda
Expand All @@ -45,10 +46,10 @@ else
fi

# Extract pyoptsparse line
pyoptsparse_line=$(grep ' pyoptsparse' $input_yaml | sed 's/^ //')
# pyoptsparse_line=$(grep ' pyoptsparse' $input_yaml | sed 's/^ //')

# Remove specified packages and write to an intermediate file
grep -v -e 'aviary' -e 'build-pyoptsparse' -e 'pyoptsparse' $input_yaml > $intermediate_yaml
grep -v -e 'aviary' -e 'om-aviary' -e 'build-pyoptsparse' -e 'pyoptsparse' -e 'boring-battery' -e 'networkx' -e ' - pip:' $input_yaml > $intermediate_yaml

# Check for 'dev' versions of OpenMDAO and Dymos
if grep -q -e 'openmdao.*dev' $intermediate_yaml; then
Expand All @@ -60,25 +61,46 @@ fi
if grep -q -e 'dymos.*dev' $intermediate_yaml; then
install_dymos_from_git=true
grep -v -e 'dymos' $intermediate_yaml > $output_yaml
else
mv $intermediate_yaml $output_yaml
mv $output_yaml $intermediate_yaml # Move output to intermediate for further processing
fi

# Insert pyoptsparse line after the 'dependencies' line
awk -v p="$pyoptsparse_line" '/dependencies/ {print; print p; next}1' $output_yaml > tmp && mv tmp $output_yaml
# Move remaining pip installs to a separate requirements.txt file
# Prevents conda evironment from failing to build if there is an issue with the pip installs
pip_prefix=' - '
requirements_txt=$env_name"_requirements.txt"
rm -f $requirements_txt
while IFS= read -r line
do
case $line in *$pip_prefix* )
package=${line#*$pip_prefix}
echo $package >> $requirements_txt
;;
*)
echo "$line" >> $output_yaml
esac
done < "$intermediate_yaml"

# Remove the intermediate file
rm -f $intermediate_yaml
# Insert pyoptsparse line after the 'dependencies' line
# awk -v p="$pyoptsparse_line" '/dependencies/ {print; print p; next}1' $output_yaml > tmp && mv tmp $output_yaml

# Create a new conda environment from the modified YAML file
$pkg_manager env create -f $output_yaml -n $env_name

source activate base
# Attempting to resolve "CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'."
# tmp=${SHELL##*/}
# MYSHELL=${tmp##*\\}
# $pkg_manager init $MYSHELL
# source activate base

# Activate the new conda environment
eval "$(conda shell.bash hook)"
conda activate $env_name

# Check flags and install special packages if needed
pip install -r $requirements_txt

pip install "boring_battery @ git+https://github.com/jcchin/boring.git"

if [ "$install_openmdao_from_git" = true ]; then
pip install git+https://github.com/OpenMDAO/OpenMDAO.git
fi
Expand All @@ -87,6 +109,14 @@ if [ "$install_dymos_from_git" = true ]; then
pip install git+https://github.com/OpenMDAO/dymos.git
fi

# Clean up
# Remove the intermediate file
rm -f $intermediate_yaml
# Remove the final file
rm -f $output_yaml
# Remove the pip requirements
rm -f $requirements_txt

# Print a reminder to install other packages manually
echo "---------------"
echo "Reminder: You need to install Aviary manually using the relevant versions based on what you are trying to debug."
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ jobs:
run: |
conda info
conda list
conda env export --name test --file ${{ matrix.NAME }}_environment.yml
conda env export --name ${{ matrix.NAME }}_env --file ${{ matrix.NAME }}_environment.yml
- name: 'Upload environment artifact'
uses: actions/upload-artifact@v3
Expand Down

0 comments on commit 4402ad2

Please sign in to comment.