

Better conda environments on GitHub actions
source link: https://ericmjl.github.io/blog/2021/12/30/better-conda-environments-on-github-actions/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Better conda environments on GitHub actions
written by Eric J. Ma on 2021-12-30
| tags: continuous integration github actions til
I recently figured out two tips to make GitHub actions play nicely with conda installations. Here they are.
Ensure bash is in login mode
The first is to use the following block:
# https://github.com/marketplace/actions/setup-miniconda#use-a-default-shell defaults: run: shell: bash -l {0}
What this does is ensure that every shell command is run in login mode. As detailed in this StackOverflow answer:
-l
to insure (sic) a login bash, where the environment is correctly set;{0}
, a template placeholder, replaced at pipeline execution time by the actual script command to execute.
Counterfactually, I would have had to use the deprecated source activate <env_name>
,
which always made me a bit nervous.
Now, I can instead switch over to using conda activate <env_name>
before executing environment-specific commands,
thereby providing longevity for the build.
Use mambaforge
The other tip is to use the mambaforge installer to get a conda installation onto GitHub actions. The block I recently used for my causality repo is as follows:
# See: https://github.com/marketplace/actions/setup-miniconda - name: Setup miniconda uses: conda-incubator/setup-miniconda@v2 with: auto-update-conda: true miniforge-variant: Mambaforge channels: conda-forge python-version: 3.9 activate-environment: causality environment-file: environment.yml use-mamba: true
This configuration guarantees the use of mamba
to solve the environment,
which means we will have blazingly fast builds.
Previously, I used to use a different GitHub action (s-weigand/setup-conda@v1
),
original conda
(rather than mamba
),
and a convoluted build that involved environment caching.
You can take a look at an example that I copied over from my nxviz
project repository
by expanding the details below.
: Build documentation
By contrast, the new build is much smaller and easier to maintain:
: Build documentation
Recommend
-
14
How to get started with distributed training of DNNs using Horovod.
-
13
conda依赖关系可视化工具:conda-tree 有时候由于特定的依赖关系,比如以前安装的包X要求它依赖的A包的版本必须低于2.0,会导致新的包无法正常安装或升级。比较常见的情况是当安装新包的时候,conda会选择它的一个比较旧的版本。...
-
8
Python 包管理及虚拟环境的应用(四: conda) 2020-07-31 — Yanbin 一年半以前写了关于 Python 包管理及虚拟环境系列 其中历数了 virtualenv, python3 -m venv, pipenv, 并提到了
-
14
community driven packaging for conda conda-forge...
-
10
开源日报 开源日报第1027期:《GitHub Actions Virtual Environments》 2021-02-02...
-
10
由于某些不可抗因素,Python官方的包在国内有时无法访问或出现网络不稳定现象。conda源也会出现网络链接失败的问题。为了解决这个问题,这里梳理了一些配置方法。
-
7
GitHub Actions Virtual Environments This repository contains the source used to create the virtual environments for GitHub Acti...
-
10
Managing R environments using conda DataColada have a recent blog about their groundhog package, intended to aid in reproducible science. This is more from a perspective of “I have this hi...
-
11
BlogCI/CD in dbt Cloud with GitHub Actions: Automating multiple environments deployment Lucas Ortiz 1...
-
5
Setting conda environments in crontab I prefer using conda environments to manage python (partly out of familiarity). Conda is a bit different though, in that it is often set up locally for a users environment, and not globally as an...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK