Skip to content

Commit

Permalink
source crow was being found instead of pip crow
Browse files Browse the repository at this point in the history
  • Loading branch information
j-bryan committed Apr 16, 2024
1 parent a9a647f commit 6206fd8
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 7 deletions.
4 changes: 2 additions & 2 deletions developer_tools/check_pip_packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ python -m pip install dist/raven_framework*cp39*.whl || exit -1

# Run some tests to check that the installed package is working. The user_guide
# tests are all pretty simple, and there are only a few of them, so we'll use those.
$RAVEN_DIR/run_tests --re="user_guide" --tester-command RavenFramework $(which raven_framework) RavenErrors $(which raven_framework) --python-command $(which python)
$RAVEN_DIR/run_tests --re="user_guide" --tester-command RavenFramework raven_framework --skip-load-env

echo
echo Checking Python 3.10
Expand All @@ -45,4 +45,4 @@ conda activate python310_pip
python -m pip uninstall -y raven_framework || echo not installed
python -m pip install dist/raven_framework*cp310*.whl || exit -1

$RAVEN_DIR/run_tests --re="user_guide" --tester-command RavenFramework $(which raven_framework) RavenErrors $(which raven_framework) --python-command $(which python)
$RAVEN_DIR/run_tests --re="user_guide" --tester-command RavenFramework raven_framework --skip-load-env
8 changes: 8 additions & 0 deletions ravenframework/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,14 @@ def find_crow(framework_dir):
@ In, framework_dir, string, the absolute path of the framework
@ Out, None
"""
# Rearrange the values in sys.path so that any entry containing "site-packages" is at the
# beginning. If there's a pip-installed version of crow_modules, we want to be able to import it
# before looking for the source version. No paths are added or removed, just reordered.
sitePackagesDir = [loc for loc in sys.path if loc.endswith("site-packages")]
for loc in sitePackagesDir:
sys.path.remove(loc)
sys.path.insert(0, loc)

try:
import crow_modules.distribution1D
return
Expand Down
16 changes: 15 additions & 1 deletion run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,19 @@ source $RAVEN_RC_SCRIPT
# set up installation manager
INSTALLATION_MANAGER=$(read_ravenrc "INSTALLATION_MANAGER")

# maybe skip loading the environment in .ravenrc
SKIP_LOAD_ENV=0

# read command-line arguments
ARGS=()
for A in "$@"; do
case $A in
--skip-conda)
INSTALLATION_MANAGER=PIP
;;
--skip-load-env)
SKIP_LOAD_ENV=1
;;
--raven)
TEST_SET=0
;;
Expand All @@ -44,12 +50,18 @@ for A in "$@"; do
esac
done
echo 'Loading libraries ...'
if [[ "$INSTALLATION_MANAGER" == "CONDA" ]];
if [[ $SKIP_LOAD_ENV == 1 ]];
then
echo Using currently active python environment, with command $(which python)
PYTHON_COMMAND=$(which python)
elif [[ "$INSTALLATION_MANAGER" == "CONDA" ]];
then
source $SCRIPT_DIR/scripts/establish_conda_env.sh --load
echo Loaded conda environment, with command $(which python)
elif [[ "$INSTALLATION_MANAGER" == "PIP" ]];
then
source $SCRIPT_DIR/scripts/establish_conda_env.sh --load --installation-manager PIP
echo Loaded pip environment, with command $(which python)
else
echo No installation: $INSTALLATION_MANAGER
if [ -z $PYTHON_COMMAND ];
Expand Down Expand Up @@ -106,6 +118,8 @@ if [[ $DO_RAVEN == 0 ]]; then
echo
echo 'Running RAVEN tests ...'

echo "Python command: $PYTHON_COMMAND"
echo "Script directory: $SCRIPT_DIR"
$PYTHON_COMMAND $SCRIPT_DIR/rook/main.py --config-file=$SCRIPT_DIR/developer_tools/rook.ini "${ARGS[@]}"
# store return codes individually (rc) and combined (ALL_PASS)
rc=$?
Expand Down
16 changes: 12 additions & 4 deletions tests/crow/crowTestUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,20 @@
import os
import importlib

ravenDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
print("ravenDir",ravenDir)
ravenFrameworkDir = os.path.join(ravenDir,"framework")
sys.path.append(ravenDir)
try:
# If a straight import of ravenframework works, ravenframework has likely been installed as a pip
# package. In that case, we need to find the crow_modules module in the python environment instead
# of the local copy of crow.
import ravenframework
ravenFrameworkDir = os.path.dirname(os.path.dirname(ravenframework.__file__))
except:
ravenDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
ravenFrameworkDir = os.path.join(ravenDir,"framework")
sys.path.append(ravenDir)

from ravenframework.utils import utils
#Get crow path loaded
print('ravenFrameworkDir:',ravenFrameworkDir)
utils.find_crow(ravenFrameworkDir)

findCrowModule = utils.findCrowModule
Expand Down
6 changes: 6 additions & 0 deletions tests/crow/test_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#Check for editable install
if os.path.exists(os.path.join(raven_dir, "src", "crow_modules", "randomENG.py")):
sys.path.append(os.path.join(raven_dir, "src"))
# Also check for crow_modules installed as a pip package. Just because there's an editable install
# doesn't mean that's what should be tested. If we find an appropriate pip package, that's what
# should be tested.
for path in [p for p in sys.path if p.endswith("site-packages")]:
sys.path.remove(path)
sys.path.insert(0, path)

import crow_modules.distribution1D
import crow_modules.interpolationND
Expand Down

0 comments on commit 6206fd8

Please sign in to comment.