Skip to content

Fix conda current environment detection on github actions #406

@smarie

Description

@smarie

On github actions the following command does not output the right environment's package list:

session.run(*["conda", "list"])

I am not sure if this is because the command is run from a specific shell (I use shell: bash -l {0} in the workflow definition file).

I am able to fix this by using explicit environment variables, this is equivalent to the "conda activate " command according to this source and also this one:

session.run(*["conda", "list"], env={"CONDA_PREFIX": session.bin, "CONDA_DEFAULT_ENV": session.get_session_id()})

The result of both commands (without the fix and with the fix) can be seen on the workflow here. You see that the first displays

nox > conda list
 # packages in environment at /usr/share/miniconda/envs/noxenv:
...

while the second displays:

nox > conda list
 # packages in environment at /home/runner/work/qdscreen/qdscreen/.nox/tests-2-7:
...

Note that for some reason on my local computer session.bin contains the conda env root folder, while on github actions runner this session.bin contains the <conda_env_root>/bin subfolder so I have to remove the "/bin" suffix... any reason why this is so ?

Anyway, this experiment makes me think that maybe it would be a good idea to always add those two environment variables to the env when the backend is conda, in order to mimic the behaviour of activate.

What do you think ?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions