Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mcg1969 committed Nov 6, 2024
1 parent b2729d1 commit 9c57f01
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,17 @@ jobs:
- name: Test the package
run: |
source $CONDA_ROOT/etc/profile.d/conda.sh
solver=${{ matrix.solver }}
export CONDA_EXE=$(echo $CONDA_EXE | sed -E "s@/conda(.exe)?@/${solver}\1@")
[ "$RUNNER_OS" = "Windows" ] && export PYTHONIOENCODING=UTF-8
export PYTHONUNBUFFERED=1
export NBVER=6
[ 3.12 = ${{ matrix.pyver }} ] && export NBVER=7
conda create -n testbase -c ./conda-bld nb_conda_kernels python=${{ matrix.pyver }} notebook=$NBVER pytest pytest-cov mock requests
conda activate testbase
solver=${{ matrix.solver }}
export CONDA_EXE=$(echo $CONDA_EXE | sed -E "s@^(.*/)conda(.*)@\\1${solver}\\2@")
[ $solver = micromamba ] && MAMBA_EXE=$CONDA_EXE
[ $solver = micromamba ] && MAMBA_ROOT_PREFIX=$CONDA_PREFIX
$CONDA_EXE env list
python -m nb_conda_kernels list
python -m pytest -v --cov=nb_conda_kernels tests 2>&1 | tee build.log
# Because Windows refuses to preserve the error code
Expand Down
18 changes: 12 additions & 6 deletions nb_conda_kernels/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,17 @@ def get_conda_info_data():
# differences in one place
envs = list(map(_canonicalize, conda_info.get('envs') or ()))
base_prefix = _canonicalize(conda_info.get('conda_prefix') or conda_info.get('base environment'))
version = conda_info.get('conda_version') or conda_info.get('micromamba version')
if base_prefix not in envs:
# Older versions of conda do not include base_prefix in the env list
envs.insert(0, base_prefix)

return (base_prefix, envs), msg
return {
"conda_exe": conda_exe,
"conda_version": version,
"conda_prefix": base_prefix,
"envs": envs,
}, msg

class CondaInfoThread(threading.Thread):
def run(self):
Expand All @@ -228,7 +234,7 @@ def run(self):
# subprocess just finished
elif t and not t.is_alive():
t.join()
conda_info, msg = t.out
conda_info, msg = t.out, t.err
if msg:
level = "info" if conda_info else "error"
else:
Expand All @@ -255,9 +261,9 @@ def _all_envs(self):
environments in the conda-bld directory. Returns a dict with
canonical environment names as keys, and full paths as values.
"""
base_prefix, envs = self._conda_info
if not envs:
return {}
conda_info = self._conda_info
envs = conda_info['envs']
base_prefix = conda_info['conda_prefix']
envs_prefix = join(base_prefix, 'envs')
build_prefix = join(base_prefix, 'conda-bld', '')
all_envs = {}
Expand Down Expand Up @@ -302,7 +308,7 @@ def _all_specs(self):
all_specs = {}
# We need to be able to find conda-run in the base conda environment
# even if this package is not running there
conda_prefix, _ = self._conda_info
conda_prefix = self._conda_info['conda_prefix']
all_envs = self._all_envs()
for env_name, env_path in all_envs.items():
kspec_base = join(env_path, 'share', 'jupyter', 'kernels')
Expand Down
1 change: 1 addition & 0 deletions testbed/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ fi
full_deactivate
source $CONDA_ROOT/etc/profile.d/conda.sh
conda activate base
conda list

if [ ! -f $CONDA_ROOT/.created ]; then
conda config --prepend channels conda-forge --system
Expand Down
5 changes: 1 addition & 4 deletions testbed/croot.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
name: conda
channels:
- defaults
- conda-forge
dependencies:
- conda
- conda >24.9
- mamba
- micromamba
- conda-build
- conda-verify
- notebook
- jupyter_client
- ipykernel
Expand Down
5 changes: 3 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ def test_configuration():
print('ERROR: Could not find conda find conda.')
exit(-1)
print(u'Current prefix: {}'.format(sys.prefix))
print(u'Root prefix: {}'.format(conda_info['root_prefix']))
print(u'Conda version: {}'.format(conda_info['conda_version']))
print(u'Conda prefix: {}'.format(conda_info['conda_prefix']))
conda_exe = os.path.basename(conda_info['conda_exe']).replace('.exe', '')
print(u'Conda version: {} {}'.format(conda_exe, conda_info['conda_version']))
print(u'Environments:')
for env in conda_info['envs']:
print(u' - {}'.format(env))
Expand Down

0 comments on commit 9c57f01

Please sign in to comment.