Skip to content

Commit 3afdf12

Browse files
authored
Activate default environment instead of base environment (#414)
1 parent f77e237 commit 3afdf12

File tree

10 files changed

+372
-92
lines changed

10 files changed

+372
-92
lines changed

.github/workflows/example-16.yml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
name: "Example 16: Default environment activation"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
schedule:
9+
# Note that cronjobs run on master/main by default
10+
- cron: "0 0 * * *"
11+
12+
jobs:
13+
example-16-build:
14+
# prevent cronjobs from running on forks
15+
if:
16+
(github.event_name == 'schedule' && github.repository ==
17+
'conda-incubator/setup-miniconda') || (github.event_name != 'schedule')
18+
name:
19+
Build Ex16 (os=${{matrix.os}}, default env=${{ matrix.add-activation-env
20+
== 'true' && 'default' || 'base' }})
21+
runs-on: ${{ matrix.os }}-latest
22+
strategy:
23+
fail-fast: false
24+
matrix:
25+
add-activation-env: ["false", "true"]
26+
os: ["ubuntu", "windows"]
27+
steps:
28+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
29+
with:
30+
persist-credentials: false
31+
32+
- name: Set up Miniconda for installer builds
33+
uses: ./
34+
with:
35+
activate-environment: ""
36+
auto-activate: false
37+
38+
- name: Create installer
39+
uses: conda-incubator/installer@2d2df0b03c6795f70e128c56403c7d084cca4fb8 # v0.1.0
40+
id: create-installer
41+
with:
42+
conda-root: ${{ env.CONDA }}
43+
environment-yaml-string: |
44+
channels:
45+
- conda-forge
46+
dependencies:
47+
- constructor
48+
variables:
49+
ADD_ACTIVATION_ENV: '${{ matrix.add-activation-env }}'
50+
EXT: ${{ matrix.os == 'windows' && 'exe' || 'sh' }}
51+
input-directory: etc/example-installers/default-environment/
52+
53+
- name: Upload installer to Github artifact
54+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
55+
with:
56+
path: ${{ steps.create-installer.outputs.artifacts-directory }}/*
57+
name:
58+
ex16-${{ matrix.os }}-${{ matrix.add-activation-env == 'false' &&
59+
'no-' }}-activation-env
60+
61+
example-16-test:
62+
needs: [example-16-build]
63+
name:
64+
Test Ex16 (os=${{matrix.os}}, default env=${{ matrix.add-activation-env ==
65+
'true' && 'default' || 'base' }}, auto-activate-base=${{
66+
matrix.auto-activate-base }})
67+
runs-on: ${{ matrix.os }}-latest
68+
strategy:
69+
fail-fast: false
70+
matrix:
71+
auto-activate-base: ["false", "true"]
72+
add-activation-env: ["false", "true"]
73+
os: ["ubuntu", "windows"]
74+
steps:
75+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
76+
with:
77+
persist-credentials: false
78+
79+
- name: Obtain artifact
80+
uses: actions/download-artifact@634f93cb2916e3fdff6788551b99b062d0335ce0 # v5.0.0
81+
with:
82+
name:
83+
ex16-${{ matrix.os }}-${{ matrix.add-activation-env == 'false' &&
84+
'no-' }}-activation-env
85+
path: ${{ runner.temp }}/_installer
86+
87+
- name: Determine installer file name
88+
id: installer-file
89+
env:
90+
ARTIFACTS_DIRECTORY: ${{ runner.temp }}/_installer
91+
EXT: ${{ matrix.os == 'windows' && 'exe' || 'sh' }}
92+
run: |
93+
INSTALLER_FILE=$(find "${ARTIFACTS_DIRECTORY}" -name "*.${EXT}" | head -n 1)
94+
echo "installer-file=${INSTALLER_FILE}" >> ${GITHUB_OUTPUT}
95+
shell: bash
96+
97+
- name: Run installation
98+
uses: ./
99+
with:
100+
activate-environment: ""
101+
auto-activate-base:
102+
${{ matrix.auto-activate-base == 'true' && 'true' ||
103+
'legacy-placeholder' }}
104+
auto-activate:
105+
${{ matrix.auto-activate-base == 'true' && '' || 'true' }}
106+
installation-dir: ${{ runner.temp }}/installer_test
107+
installer-url:
108+
file://${{ steps.installer-file.outputs.installer-file }}
109+
110+
- name: Output conda info (bash)
111+
env:
112+
DEFAULT_ENV: ${{ matrix.add-activation-env && 'default' || 'base' }}
113+
TEST_DIR: ${{ runner.temp }}/installer_output
114+
run: |
115+
mkdir -p ${TEST_DIR}
116+
conda info --json > "${TEST_DIR}/bash.json"
117+
shell: bash -el {0}
118+
119+
- name: Output conda info (cmd.exe)
120+
if: matrix.os == 'windows'
121+
env:
122+
TEST_DIR: ${{ runner.temp }}\installer_output
123+
run: |
124+
conda info --json > "%TEST_DIR%\cmd.exe.json"
125+
shell: cmd /C CALL {0}
126+
127+
- name: Output conda info (PowerShell)
128+
if: matrix.os == 'windows'
129+
env:
130+
TEST_DIR: ${{ runner.temp }}\installer_output
131+
run: conda info --json > "${env:TEST_DIR}\pwsh.json"
132+
shell: pwsh
133+
134+
- name: Test default environments
135+
env:
136+
DEFAULT_ENV:
137+
${{ matrix.add-activation-env == 'true' && matrix.auto-activate-base
138+
== 'false' && 'default' || 'base' }}
139+
TEST_DIR: ${{ runner.temp }}/installer_output
140+
run: |
141+
import json
142+
import os
143+
from pathlib import Path
144+
145+
json_dir = Path(os.environ["TEST_DIR"])
146+
default_env_expected = os.environ["DEFAULT_ENV"]
147+
incorrect_environments = {}
148+
for file in json_dir.iterdir():
149+
conda_info = json.loads(file.read_text())
150+
default_env = conda_info.get("active_prefix_name")
151+
if default_env != default_env_expected:
152+
incorrect_environments[str(file.name).removesuffix(".json")] = default_env
153+
if incorrect_environments:
154+
raise AssertionError(
155+
f"Found incorrect default environments: {incorrect_environments}"
156+
)
157+
shell: python

.github/workflows/example-3.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
environment-file: etc/example-environment.yml
3939
python-version: 3.8
4040
condarc-file: etc/example-condarc.yml
41-
auto-activate-base: false
41+
auto-activate: false
4242
auto-update-conda: true
4343
- run: |
4444
conda info
@@ -60,7 +60,7 @@ jobs:
6060
environment-file: etc/example-environment-no-name.yml
6161
python-version: 3.8
6262
condarc-file: etc/example-condarc.yml
63-
auto-activate-base: false
63+
auto-activate: false
6464
auto-update-conda: true
6565
- run: |
6666
conda info

README.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ possibility of automatically activating the `test` environment on all shells.
6161
| [Apple Silicon](#example-13-apple-silicon) | [![Apple Silicon][ex13-badge]][ex13] |
6262
| [Remove defaults](#example-14-remove-defaults-channel) | [![Remove defaults][ex14-badge]][ex14] |
6363
| [Linux ARM](#example-15-linux-arm) | [![Linux ARM][ex15-badge]][ex15] |
64+
| Default environments | [![Default environments][ex16-badge]][ex16] |
6465

6566
[ex1]:
6667
https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-1.yml
@@ -122,6 +123,10 @@ possibility of automatically activating the `test` environment on all shells.
122123
https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-15.yml
123124
[ex15-badge]:
124125
https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-15.yml/badge.svg?branch=main
126+
[ex16]:
127+
https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-16.yml
128+
[ex16-badge]:
129+
https://github.com/conda-incubator/setup-miniconda/actions/workflows/example-16.yml/badge.svg?branch=main
125130

126131
## Other Workflows
127132

@@ -180,16 +185,16 @@ Miniconda installation.
180185

181186
### Activate `base` environment
182187

183-
If your specific workflow still needs to activate and use `base` you will need
184-
to do **both** of:
188+
If your specific workflow still needs to activate and use the default
189+
environment, you will need to do **both**:
185190

186191
- set `activate-environment` to an empty string
187-
- set `auto-activate-base` to `true`
192+
- set `auto-activate` to `true`
188193

189194
```yaml
190195
- uses: conda-incubator/setup-miniconda@v3
191196
with:
192-
auto-activate-base: true
197+
auto-activate: true
193198
activate-environment: ""
194199
```
195200

@@ -330,7 +335,7 @@ jobs:
330335
environment-file: etc/example-environment.yml
331336
python-version: 3.5
332337
condarc-file: etc/example-condarc.yml
333-
auto-activate-base: false
338+
auto-activate: false
334339
- run: |
335340
conda info
336341
conda list

action.yml

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -134,16 +134,27 @@ inputs:
134134
for more information.'
135135
required: false
136136
default: ""
137-
auto-activate-base:
137+
auto-activate:
138138
description:
139-
'Conda configuration. If you’d prefer that conda’s base environment not be
140-
activated on startup, set the to "false". Default is "true". This setting
141-
always overrides if set to "true" or "false". If you want to use the
142-
"condarc-file" setting pass and empty string. See
139+
'Conda configuration. If you’d prefer that conda’s default environment not
140+
be activated on startup, set the to "false". Default is "true". This
141+
setting always overrides if set to "true" or "false". If you want to use
142+
the "condarc-file" setting pass an empty string. See
143143
https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/
144144
for more information.'
145145
required: false
146146
default: "true"
147+
auto-activate-base:
148+
description:
149+
(deprecated in favor of `auto-activate`) 'Conda configuration. If you’d
150+
prefer that conda’s base environment not be activated on startup, set the
151+
to "false". Default is "true". This setting always overrides if set to
152+
"true" or "false". If you want to use the "condarc-file" setting pass an
153+
empty string. See
154+
https://docs.conda.io/projects/conda/en/latest/user-guide/configuration/
155+
for more information.'
156+
required: false
157+
default: "legacy-placeholder"
147158
auto-update-conda:
148159
description:
149160
'Conda configuration. When "true", conda updates itself any time a user

dist/delete/index.js

Lines changed: 14 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)