Skip to content

Commit

Permalink
🩹 Removed env vars from conda activation
Browse files Browse the repository at this point in the history
Adding the env vars did lead to 'source activate <env_name>' not working anymore see issue 125
  • Loading branch information
s-weigand committed Jul 5, 2021
1 parent e130942 commit 5a73bf3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 79 deletions.
10 changes: 1 addition & 9 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,7 @@ jobs:
uses: ./
with:
activate-conda: false
- name: Which activate
shell: bash -l {0}
run: which activate
- name: Login shell activate script
shell: bash -l {0}
run: |
conda shell.bash activate base
conda shell.posix activate base
- name: Install pandoc and graphviz
- name: Create Test env
shell: bash -l {0}
run: |
conda create --name TEST python=3.8
Expand Down
57 changes: 16 additions & 41 deletions __tests__/conda_actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import * as fs from 'fs'
import * as path from 'path'
import {
parseActivationScriptOutput,
ParsedActivationScriptOutput,
} from '../src/conda_actions'
import { parseActivationScriptOutput } from '../src/conda_actions'

describe('Parse evn activation output', () => {
it('Parse linux activation', async () => {
Expand All @@ -12,59 +9,37 @@ describe('Parse evn activation output', () => {
path.resolve(__dirname, 'data/linux_conda_bash_activation.sh')
)
.toString('utf8')
const result: ParsedActivationScriptOutput =
await parseActivationScriptOutput(activationStr, 'export ', ':')
const { condaPaths, envVars } = result
expect(condaPaths.length).toBe(3)
expect(envVars['CONDA_PREFIX']).toEqual('/usr/share/miniconda')
expect(envVars['CONDA_SHLVL']).toEqual('1')
expect(envVars['CONDA_DEFAULT_ENV']).toEqual('base')
expect(envVars['CONDA_PROMPT_MODIFIER']).toEqual('(base)')
expect(envVars['CONDA_EXE']).toEqual('/usr/share/miniconda/bin/conda')
expect(envVars['_CE_M']).toEqual('')
expect(envVars['_CE_CONDA']).toEqual('')
expect(envVars['CONDA_PYTHON_EXE']).toEqual(
'/usr/share/miniconda/bin/python'
const condaPaths: string[] = await parseActivationScriptOutput(
activationStr,
'export ',
':'
)
expect(condaPaths.length).toBe(3)
})
it('Parse macOs activation', async () => {
const activationStr = fs
.readFileSync(
path.resolve(__dirname, 'data/mac_conda_bash_activation.sh')
)
.toString('utf8')
const result: ParsedActivationScriptOutput =
await parseActivationScriptOutput(activationStr, 'export ', ':')
const { condaPaths, envVars } = result
expect(condaPaths.length).toBe(3)
expect(envVars['CONDA_PREFIX']).toEqual('/usr/local/miniconda')
expect(envVars['CONDA_SHLVL']).toEqual('1')
expect(envVars['CONDA_DEFAULT_ENV']).toEqual('base')
expect(envVars['CONDA_PROMPT_MODIFIER']).toEqual('(base)')
expect(envVars['CONDA_EXE']).toEqual('/usr/local/miniconda/bin/conda')
expect(envVars['_CE_M']).toEqual('')
expect(envVars['_CE_CONDA']).toEqual('')
expect(envVars['CONDA_PYTHON_EXE']).toEqual(
'/usr/local/miniconda/bin/python'
const condaPaths: string[] = await parseActivationScriptOutput(
activationStr,
'export ',
':'
)
expect(condaPaths.length).toBe(3)
})
it('Parse windows activation', async () => {
const activationStr = fs
.readFileSync(
path.resolve(__dirname, 'data/windows_conda_powershell_activation.ps1')
)
.toString('utf8')
const result: ParsedActivationScriptOutput =
await parseActivationScriptOutput(activationStr, '$Env:', ';')
const { condaPaths, envVars } = result
const condaPaths: string[] = await parseActivationScriptOutput(
activationStr,
'$Env:',
';'
)
expect(condaPaths.length).toBe(7)
expect(envVars['CONDA_PREFIX']).toEqual('C:\\Miniconda')
expect(envVars['CONDA_SHLVL']).toEqual('1')
expect(envVars['CONDA_DEFAULT_ENV']).toEqual('base')
expect(envVars['CONDA_PROMPT_MODIFIER']).toEqual('(base)')
expect(envVars['CONDA_EXE']).toEqual('C:\\Miniconda\\Scripts\\conda.exe')
expect(envVars['_CE_M']).toEqual('')
expect(envVars['_CE_CONDA']).toEqual('')
expect(envVars['CONDA_PYTHON_EXE']).toEqual('C:\\Miniconda\\python.exe')
})
})
9 changes: 0 additions & 9 deletions integrationtests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,3 @@ def test_conda_channels():
assert returncode == 0
assert channel_list == expected
assert stderr == b""


def test_conda_env_vars_set():
"""Conda env_vars are set"""
assert "miniconda" in os.environ["CONDA_PREFIX"].lower()
assert "miniconda" in os.environ["CONDA_EXE"].lower()
assert "miniconda" in os.environ["CONDA_PYTHON_EXE"].lower()
assert int(os.environ["CONDA_SHLVL"]) >= 1
assert os.environ["CONDA_DEFAULT_ENV"] != ""
23 changes: 3 additions & 20 deletions src/conda_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@ import * as core from '@actions/core'

import { ConfigObject } from './load_config'

/**
* Container holding the results of parseActivationScriptOutput
*/
export interface ParsedActivationScriptOutput {
condaPaths: string[]
envVars: Record<string, string>
}

/**
* Sets up conda to be later used.
*
Expand Down Expand Up @@ -74,7 +66,7 @@ const addCondaToPath = async (config: ConfigObject): Promise<void> => {
}

/**
* Activates the conda base env.
* Activates the conda base env by changing the path and env variables.
*
* @param config Configuration of the action
*/
Expand Down Expand Up @@ -110,9 +102,6 @@ const activate_conda = async (config: ConfigObject): Promise<void> => {
for (const condaPath of condaPaths) {
sane_add_path(condaPath)
}
for (const varName in envVars) {
core.exportVariable(varName, envVars[varName])
}
core.endGroup()
}

Expand All @@ -128,9 +117,8 @@ export const parseActivationScriptOutput = async (
activationStr: string,
envExport: string,
osPathSep: string
): Promise<ParsedActivationScriptOutput> => {
): Promise<string[]> => {
let condaPaths: string[] = []
const envVars: Record<string, string> = {}
const lines = activationStr.split(envExport)
for (const line of lines) {
if (line.startsWith('PATH')) {
Expand All @@ -141,14 +129,9 @@ export const parseActivationScriptOutput = async (
(orig, index, self) =>
index === self.findIndex((subSetItem) => subSetItem === orig)
)
} else {
const [varName, varValue] = line.replace(/'|"|\n|\s/g, '').split('=')
if (varValue !== undefined) {
envVars[varName.trim()] = varValue.trim()
}
}
}
return { condaPaths, envVars }
return condaPaths
}

const get_python_location = async (): Promise<string> => {
Expand Down

0 comments on commit 5a73bf3

Please sign in to comment.