Skip to content

Commit 28e0d54

Browse files
committed
Don't add $CONDA_PREFIX/bin to the PATH on Linux and MacOS
Instead, add the path to Conda environment bin directory to the environment, *as a specific environment variable*. Thus, we match "Conda-based" environments as much as possible. A "Conda-based" environment is a Conda environment whose packages are launched outside of the environment, as e.g. when using the Khiops Python library from a JuPyter notebook which: - is installed outside the Conda environment where Khiops is installed - uses a Python kernel (via the `ipykernel` Conda package) which is installed inside the Conda envirovnment. This configuration results in two particularities: - `sys.path` is correctly set according to the Conda environment (as the Python kernel is installed therein); - `PATH` does not contain `$CONDA_PREFIX/bin`.
1 parent bb5cf6e commit 28e0d54

File tree

3 files changed

+79
-13
lines changed

3 files changed

+79
-13
lines changed

.github/actions/test-khiops-install/action.yml

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ runs:
55
using: composite
66
steps:
77
- name: Test that the executables are installed (Linux/macOS)
8+
# We compute the directory of khiops_env if khiops_env is in the PATH,
9+
# otherwise we get this directory from the environment
810
# We call khiops_env a first time to test the calling of _khiopsgetprocnumber
911
# then we play with KHIOPS_PROC_NUMBER:
1012
# - with KHIOPS_PROC_NUMBER=2, khiops should not use MPI, we check that KHIOPS_MPI_COMMAND is empty
@@ -19,13 +21,28 @@ runs:
1921
OMPI_MCA_rmaps_base_oversubscribe: true
2022
KHIOPS_MPI_VERBOSE: true
2123
run: |
24+
# Compute or get the khiops_env directory
25+
if type -P khiops_env &> /dev/null
26+
then
27+
KHIOPS_ENV_DIR=$(dirname $(type -P khiops_env))
28+
elif [[ -n "$CONDA_ENV_BIN_DIR" ]]
29+
then
30+
KHIOPS_ENV_DIR=$CONDA_ENV_BIN_DIR
31+
else
32+
echo "::error::This action expects CONDA_ENV_BIN_DIR to be defined"
33+
false
34+
fi
35+
echo
36+
echo --- khiops_env directory $KHIOPS_ENV_DIR
2237
echo
2338
echo --- Khiops environment with KHIOPS_PROC_NUMBER not set
24-
khiops_env --env
39+
40+
# khiops_env is not in the path anymore, for Conda environments
41+
$KHIOPS_ENV_DIR/khiops_env --env
2542
echo
2643
export KHIOPS_PROC_NUMBER=2
2744
echo --- Khiops environment with KHIOPS_PROC_NUMBER=$KHIOPS_PROC_NUMBER
28-
source khiops_env --env
45+
source $KHIOPS_ENV_DIR/khiops_env --env
2946
if [ ! -z "$KHIOPS_MPI_COMMAND" ];
3047
then
3148
echo "::error::MPI is used even though there are only 2 procs available"
@@ -34,7 +51,7 @@ runs:
3451
echo
3552
export KHIOPS_PROC_NUMBER=8
3653
echo --- Khiops environment with KHIOPS_PROC_NUMBER=$KHIOPS_PROC_NUMBER
37-
source khiops_env --env
54+
source $KHIOPS_ENV_DIR/khiops_env --env
3855
if [ ! -z "$KHIOPS_MPI_ERROR" ];
3956
then
4057
echo "::error::Unexpected MPI error: $KHIOPS_MPI_ERROR"
@@ -47,10 +64,10 @@ runs:
4764
fi
4865
echo
4966
echo --- Khiops status
50-
khiops -s
67+
$KHIOPS_ENV_DIR/khiops -s
5168
echo
5269
echo --- Khiops Coclustering status
53-
khiops_coclustering -s
70+
$KHIOPS_ENV_DIR/khiops_coclustering -s
5471
- name: Test that the executables are installed (windows)
5572
if: runner.os == 'Windows'
5673
shell: cmd /C call {0}
@@ -96,8 +113,19 @@ runs:
96113
OMPI_MCA_rmaps_base_oversubscribe: true
97114
KHIOPS_MPI_VERBOSE: true
98115
run: |
99-
khiops -s
100-
khiops -v &> output
116+
# Compute or get the khiops_env directory
117+
if type -P khiops_env &> /dev/null
118+
then
119+
KHIOPS_ENV_DIR=$(dirname $(type -P khiops_env))
120+
elif [[ -n "$CONDA_ENV_BIN_DIR" ]]
121+
then
122+
KHIOPS_ENV_DIR=$CONDA_ENV_BIN_DIR
123+
else
124+
echo "::error::This action expects CONDA_ENV_BIN_DIR to be defined"
125+
false
126+
fi
127+
$KHIOPS_ENV_DIR/khiops -s
128+
$KHIOPS_ENV_DIR/khiops -v &> output
101129
LINE_NUMBER=$(wc -l < output)
102130
if [ $LINE_NUMBER -gt 1 ] ;
103131
then
@@ -120,8 +148,19 @@ runs:
120148
if: runner.os != 'Windows'
121149
shell: bash
122150
run: |-
123-
khiops_coclustering -s
124-
khiops_coclustering -v &> output
151+
# Compute or get the khiops_env directory
152+
if type -P khiops_env &> /dev/null
153+
then
154+
KHIOPS_ENV_DIR=$(dirname $(type -P khiops_env))
155+
elif [[ -n "$CONDA_ENV_BIN_DIR" ]]
156+
then
157+
KHIOPS_ENV_DIR=$CONDA_ENV_BIN_DIR
158+
else
159+
echo "::error::This action expects CONDA_ENV_BIN_DIR to be defined"
160+
false
161+
fi
162+
$KHIOPS_ENV_DIR/khiops_coclustering -s
163+
$KHIOPS_ENV_DIR/khiops_coclustering -v &> output
125164
LINE_NUMBER=$(wc -l < output)
126165
if [ $LINE_NUMBER -gt 1 ] ;
127166
then
@@ -147,7 +186,18 @@ runs:
147186
KHIOPS_PROC_NUMBER: 4
148187
OMPI_MCA_rmaps_base_oversubscribe: true
149188
run: |-
150-
PROC_NUMBER=$(khiops -s | grep "Logical processes" | awk '{print $NF}')
189+
# Compute or get the khiops_env directory
190+
if type -P khiops_env &> /dev/null
191+
then
192+
KHIOPS_ENV_DIR=$(dirname $(type -P khiops_env))
193+
elif [[ -n "$CONDA_ENV_BIN_DIR" ]]
194+
then
195+
KHIOPS_ENV_DIR=$CONDA_ENV_BIN_DIR
196+
else
197+
echo "::error::This action expects CONDA_ENV_BIN_DIR to be defined"
198+
false
199+
fi
200+
PROC_NUMBER=$($KHIOPS_ENV_DIR/khiops -s | grep "Logical processes" | awk '{print $NF}')
151201
if [ "$PROC_NUMBER" != "$KHIOPS_PROC_NUMBER" ] ;
152202
then
153203
echo "::error::Wrong proc number ($PROC_NUMBER vs $KHIOPS_PROC_NUMBER)"

.github/actions/test-khiops-on-iris/action.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,19 @@ runs:
4444
echo "KHIOPS_SCRIPT=$KHIOPS_SCRIPT" >> "$GITHUB_ENV"
4545
echo "KHIOPS_CC_SCRIPT=$KHIOPS_CC_SCRIPT" >> "$GITHUB_ENV"
4646
else
47-
echo "KHIOPS_SCRIPT=khiops" >> "$GITHUB_ENV"
48-
echo "KHIOPS_CC_SCRIPT=khiops_coclustering" >> "$GITHUB_ENV"
47+
# Compute or get the khiops_env directory
48+
if type -P khiops_env &> /dev/null
49+
then
50+
KHIOPS_ENV_DIR=$(dirname $(type -P khiops_env))
51+
elif [[ -n "$CONDA_ENV_BIN_DIR" ]]
52+
then
53+
KHIOPS_ENV_DIR=$CONDA_ENV_BIN_DIR
54+
else
55+
echo "::error::This action expects CONDA_ENV_BIN_DIR to be defined"
56+
false
57+
fi
58+
echo "KHIOPS_SCRIPT=$KHIOPS_ENV_DIR/khiops" >> "$GITHUB_ENV"
59+
echo "KHIOPS_CC_SCRIPT=$KHIOPS_ENV_DIR/khiops_coclustering" >> "$GITHUB_ENV"
4960
fi
5061
- name: Run Khiops tests
5162
shell: bash

.github/workflows/conda.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,14 @@ jobs:
119119
- name: Install the Khiops executables in the Conda environment
120120
run: |
121121
conda install --channel conda-forge --channel ./build/conda khiops-core
122-
- name: Add CONDA_PREFIX to shared PATH
122+
- name: Add CONDA_PREFIX to shared PATH (Windows)
123+
if: runner.os == 'Windows'
123124
run: |
124125
echo "$CONDA_PREFIX/bin" >> $GITHUB_PATH
126+
- name: Add Conda environment binary directory to the environment (Linux and
127+
MacOS)
128+
if: runner.os != 'Windows'
129+
run: echo "CONDA_ENV_BIN_DIR=$CONDA_PREFIX/bin" >> $GITHUB_ENV
125130
- name: Checkout sources
126131
uses: actions/checkout@v4
127132
- name: Test that the Khiops executables are installed

0 commit comments

Comments
 (0)