Skip to content

Commit

Permalink
added conda shell init function
Browse files Browse the repository at this point in the history
  • Loading branch information
s-weigand committed Nov 17, 2019
1 parent 247dcf9 commit 27a57d0
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 38 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ jobs:
os: [ubuntu-latest, windows-latest, macOS-latest]
steps:
- uses: actions/checkout@v1
- run: python --version
- run: npm ci
- run: npm run release
- uses: ./
- run: conda --version
- run: conda init bash
- run: conda activate base
- run: python --version
- run: python -c "import sys;print(sys.executable)"
2 changes: 2 additions & 0 deletions src/activate_conda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
source activate base
14 changes: 0 additions & 14 deletions src/init_conda.sh

This file was deleted.

38 changes: 20 additions & 18 deletions src/init_conda.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,34 @@
import * as path from 'path'
import * as exec from '@actions/exec'
import * as core from '@actions/core'

const IS_WINDOWS = process.platform === 'win32'
// Miniconda has "scripts" or "bin" directories where command-line tools that come with packages are installed.
// This is where pip is, along with anything that pip installs.
// There is a seperate directory for `pip install --user`.
//
// For reference, these directories are as follows:
// macOS / Linux:
// <sys.prefix>/bin (by default /usr/local/bin, but not on hosted agents -- see the `else`)
// (--user) ~/.local/bin
// Windows:
// <Miniconda installation dir>\Scripts
// (--user) %APPDATA%\Python\PythonXY\Scripts
// See https://docs.python.org/3/library/sysconfig.html
import { ConfigObject } from './load_config'

function binDir(installDir: string): string {
if (IS_WINDOWS) {
function binDir(installDir: string, config: ConfigObject): string {
if (config.os === 'win32') {
return path.join(installDir, 'Scripts')
} else {
return path.join(installDir, 'bin')
}
}

export const init_conda = () => {
console.log(`process.env.CONDA: ${process.env.CONDA}`)
export const init_conda = async (config: ConfigObject): Promise<void> => {
await addCondaToPath(config)
await activate_conda(config)
}

const addCondaToPath = async (config: ConfigObject): Promise<void> => {
console.log(`Adding conda path to path: ${process.env.CONDA}`)
const conda_base_path = process.env.CONDA as string
const bin_dir = binDir(conda_base_path)
const bin_dir = binDir(conda_base_path, config)
core.addPath(conda_base_path)
core.addPath(bin_dir)
}

const activate_conda = async (config: ConfigObject): Promise<void> => {
if (config.os === 'win32') {
await exec.exec('activate.bat', ['base'])
} else {
await exec.exec('bash', ['src/activate_conda.sh'])
}
}
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ async function run(): Promise<void> {
await download_miniconda(config)
await install_conda(config)
}
init_conda()
await init_conda(config)
} catch (error) {
core.setFailed(error.message)
}
}

/* tslint:disable-next-line:no-floating-promises */
run()
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
"noImplicitAny": false /* Raise error on expressions and declarations with an implied 'any' type. */,
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
Expand Down
2 changes: 1 addition & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
"semicolon": [true, "never"],
"quotemark": [true, "single", "jsx-single", "avoid-escape"]
},
"linterOptions": { "exclude": ["src/init_conda.sh"] }
"linterOptions": { "exclude": ["src/activate_conda.sh"] }
}

0 comments on commit 27a57d0

Please sign in to comment.