-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🩹 Fix updating base conda causes error on windows (#475)
This PR fixes that updating the base conda on windows causes an error by reordering how paths are added so C:\Miniconda\Scripts\conda.exe is used directly in the update instead of C:\Miniconda\Library\bin\conda.bat. Additionally, it upgrades the tooling and dependencies. closes #473
- Loading branch information
Showing
12 changed files
with
1,841 additions
and
6,194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,98 @@ | ||
import { EOL } from 'os' | ||
import { readFileSync } from 'fs' | ||
import { resolve } from 'path' | ||
import { | ||
parseActivationScriptOutput, | ||
addCondaToPath, | ||
} from '../src/conda_actions' | ||
import { readFileSync } from "node:fs"; | ||
import { EOL } from "node:os"; | ||
import { resolve } from "node:path"; | ||
import { addCondaToPath, parseActivationScriptOutput } from "../src/conda_actions"; | ||
|
||
describe('Parse env activation output', () => { | ||
it('Parse linux activation', async () => { | ||
describe("Parse env activation output", () => { | ||
it("Parse linux activation", async () => { | ||
const activationStr = readFileSync( | ||
resolve(__dirname, 'data/linux_conda_bash_activation.sh'), | ||
).toString('utf8') | ||
resolve(__dirname, "data/linux_conda_bash_activation.sh"), | ||
).toString("utf8"); | ||
const { condaPaths, envVars } = await parseActivationScriptOutput( | ||
activationStr, | ||
'export ', | ||
':', | ||
) | ||
expect(condaPaths.length).toBe(3) | ||
expect(envVars['CONDA_PREFIX']).toBe( | ||
'/usr/share/miniconda/envs/__setup_conda', | ||
) | ||
expect(envVars).not.toHaveProperty('CONDA_SHLVL') | ||
expect(envVars['CONDA_DEFAULT_ENV']).toBe('__setup_conda') | ||
expect(envVars['CONDA_PROMPT_MODIFIER']).toBe('(__setup_conda) ') | ||
expect(envVars['CONDA_EXE']).toBe('/usr/share/miniconda/bin/conda') | ||
expect(envVars['_CE_M']).toBe('') | ||
expect(envVars['_CE_CONDA']).toBe('') | ||
expect(envVars['CONDA_PYTHON_EXE']).toBe('/usr/share/miniconda/bin/python') | ||
}) | ||
it('Parse macOs activation', async () => { | ||
"export ", | ||
":", | ||
); | ||
expect(condaPaths.length).toBe(3); | ||
expect(envVars.CONDA_PREFIX).toBe("/usr/share/miniconda/envs/__setup_conda"); | ||
expect(envVars).not.toHaveProperty("CONDA_SHLVL"); | ||
expect(envVars.CONDA_DEFAULT_ENV).toBe("__setup_conda"); | ||
expect(envVars.CONDA_PROMPT_MODIFIER).toBe("(__setup_conda) "); | ||
expect(envVars.CONDA_EXE).toBe("/usr/share/miniconda/bin/conda"); | ||
expect(envVars._CE_M).toBe(""); | ||
expect(envVars._CE_CONDA).toBe(""); | ||
expect(envVars.CONDA_PYTHON_EXE).toBe("/usr/share/miniconda/bin/python"); | ||
}); | ||
it("Parse macOs activation", async () => { | ||
const activationStr = readFileSync( | ||
resolve(__dirname, 'data/mac_conda_bash_activation.sh'), | ||
).toString('utf8') | ||
resolve(__dirname, "data/mac_conda_bash_activation.sh"), | ||
).toString("utf8"); | ||
const { condaPaths, envVars } = await parseActivationScriptOutput( | ||
activationStr, | ||
'export ', | ||
':', | ||
) | ||
expect(condaPaths.length).toBe(3) | ||
expect(envVars['CONDA_PREFIX']).toBe( | ||
'/usr/local/miniconda/envs/__setup_conda', | ||
) | ||
expect(envVars).not.toHaveProperty('CONDA_SHLVL') | ||
expect(envVars['CONDA_DEFAULT_ENV']).toBe('__setup_conda') | ||
expect(envVars['CONDA_PROMPT_MODIFIER']).toBe('(__setup_conda) ') | ||
expect(envVars['CONDA_EXE']).toBe('/usr/local/miniconda/bin/conda') | ||
expect(envVars['_CE_M']).toBe('') | ||
expect(envVars['_CE_CONDA']).toBe('') | ||
expect(envVars['CONDA_PYTHON_EXE']).toBe('/usr/local/miniconda/bin/python') | ||
}) | ||
it('Parse windows activation', async () => { | ||
"export ", | ||
":", | ||
); | ||
expect(condaPaths.length).toBe(3); | ||
expect(envVars.CONDA_PREFIX).toBe("/usr/local/miniconda/envs/__setup_conda"); | ||
expect(envVars).not.toHaveProperty("CONDA_SHLVL"); | ||
expect(envVars.CONDA_DEFAULT_ENV).toBe("__setup_conda"); | ||
expect(envVars.CONDA_PROMPT_MODIFIER).toBe("(__setup_conda) "); | ||
expect(envVars.CONDA_EXE).toBe("/usr/local/miniconda/bin/conda"); | ||
expect(envVars._CE_M).toBe(""); | ||
expect(envVars._CE_CONDA).toBe(""); | ||
expect(envVars.CONDA_PYTHON_EXE).toBe("/usr/local/miniconda/bin/python"); | ||
}); | ||
it("Parse windows activation", async () => { | ||
const activationStr = readFileSync( | ||
resolve(__dirname, 'data/windows_conda_powershell_activation.ps1'), | ||
).toString('utf8') | ||
const { condaPaths, envVars } = await parseActivationScriptOutput( | ||
activationStr, | ||
'$Env:', | ||
';', | ||
) | ||
expect(condaPaths.length).toBe(9) | ||
expect(envVars['CONDA_PREFIX']).toBe('C:\\Miniconda\\envs\\__setup_conda') | ||
expect(envVars).not.toHaveProperty('CONDA_SHLVL') | ||
expect(envVars['CONDA_DEFAULT_ENV']).toBe('__setup_conda') | ||
expect(envVars['CONDA_PROMPT_MODIFIER']).toBe('(__setup_conda) ') | ||
expect(envVars['CONDA_EXE']).toBe('C:\\Miniconda\\Scripts\\conda.exe') | ||
expect(envVars['_CE_M']).toBe('') | ||
expect(envVars['_CE_CONDA']).toBe('') | ||
expect(envVars['CONDA_PYTHON_EXE']).toBe('C:\\Miniconda\\python.exe') | ||
}) | ||
}) | ||
resolve(__dirname, "data/windows_conda_powershell_activation.ps1"), | ||
).toString("utf8"); | ||
const { condaPaths, envVars } = await parseActivationScriptOutput(activationStr, "$Env:", ";"); | ||
expect(condaPaths.length).toBe(9); | ||
expect(envVars.CONDA_PREFIX).toBe("C:\\Miniconda\\envs\\__setup_conda"); | ||
expect(envVars).not.toHaveProperty("CONDA_SHLVL"); | ||
expect(envVars.CONDA_DEFAULT_ENV).toBe("__setup_conda"); | ||
expect(envVars.CONDA_PROMPT_MODIFIER).toBe("(__setup_conda) "); | ||
expect(envVars.CONDA_EXE).toBe("C:\\Miniconda\\Scripts\\conda.exe"); | ||
expect(envVars._CE_M).toBe(""); | ||
expect(envVars._CE_CONDA).toBe(""); | ||
expect(envVars.CONDA_PYTHON_EXE).toBe("C:\\Miniconda\\python.exe"); | ||
}); | ||
}); | ||
|
||
const testConfig = { | ||
activate_conda: false, | ||
update_conda: false, | ||
python_version: '', | ||
python_version: "", | ||
conda_channels: [], | ||
os: 'linux', | ||
} | ||
os: "linux", | ||
}; | ||
|
||
describe("Throw error if CONDA env var isn't set", () => { | ||
const OLD_ENV = process.env | ||
const OLD_ENV = process.env; | ||
|
||
beforeEach(() => { | ||
process.env = {} | ||
}) | ||
process.env = {}; | ||
}); | ||
|
||
afterAll(() => { | ||
process.env = OLD_ENV | ||
}) | ||
process.env = OLD_ENV; | ||
}); | ||
|
||
it.each(['linux', 'win32', 'darwin'])( | ||
`General error %p`, | ||
async (os: string) => { | ||
await expect(addCondaToPath({ ...testConfig, os })).rejects.toThrow( | ||
'Could not determine conda base path, it seams conda is not installed.', | ||
) | ||
}, | ||
) | ||
it.each(["linux", "win32", "darwin"])("General error %p", async (os: string) => { | ||
await expect(addCondaToPath({ ...testConfig, os })).rejects.toThrow( | ||
"Could not determine conda base path, it seams conda is not installed.", | ||
); | ||
}); | ||
|
||
it('MacOs > 12 error', async () => { | ||
process.env.ImageOS = 'macos13' | ||
await expect( | ||
addCondaToPath({ ...testConfig, os: 'darwin' }), | ||
).rejects.toThrow( | ||
it("MacOs > 12 error", async () => { | ||
process.env.ImageOS = "macos13"; | ||
await expect(addCondaToPath({ ...testConfig, os: "darwin" })).rejects.toThrow( | ||
[ | ||
'Could not determine conda base path, it seams conda is not installed.', | ||
"Could not determine conda base path, it seams conda is not installed.", | ||
'MacOS images newer than "macos-12" (i.e. "macOS-latest") are known to be ' + | ||
'incompatible with this action due to a missing miniconda installation.', | ||
'See: https://github.com/s-weigand/setup-conda/issues/432', | ||
"incompatible with this action due to a missing miniconda installation.", | ||
"See: https://github.com/s-weigand/setup-conda/issues/432", | ||
].join(EOL), | ||
) | ||
}) | ||
}) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,37 @@ | ||
import { loadConfig } from '../src/load_config' | ||
import { loadConfig } from "../src/load_config"; | ||
|
||
const testEnvVars = { | ||
'INPUT_ACTIVATE-CONDA': 'true', | ||
'INPUT_UPDATE-CONDA': 'true', | ||
'INPUT_PYTHON-VERSION': 'default', | ||
'INPUT_CONDA-CHANNELS': ' conda-forge, anaconda , bioconda', | ||
} | ||
"INPUT_ACTIVATE-CONDA": "true", | ||
"INPUT_UPDATE-CONDA": "true", | ||
"INPUT_PYTHON-VERSION": "default", | ||
"INPUT_CONDA-CHANNELS": " conda-forge, anaconda , bioconda", | ||
}; | ||
|
||
describe('Reading of the config', () => { | ||
describe("Reading of the config", () => { | ||
beforeEach(() => { | ||
for (const key in testEnvVars) { | ||
process.env[key] = testEnvVars[key as keyof typeof testEnvVars] | ||
process.env[key] = testEnvVars[key as keyof typeof testEnvVars]; | ||
} | ||
|
||
process.stdout.write = jest.fn() | ||
}) | ||
process.stdout.write = jest.fn(); | ||
}); | ||
|
||
afterEach(() => { | ||
for (const key in testEnvVars) Reflect.deleteProperty(testEnvVars, key) | ||
}) | ||
for (const key in testEnvVars) Reflect.deleteProperty(testEnvVars, key); | ||
}); | ||
|
||
it('test config values', () => { | ||
const config = loadConfig() | ||
expect(config.activate_conda).toEqual(true) | ||
expect(config.update_conda).toEqual(true) | ||
expect(config.python_version).toEqual('default') | ||
expect(config.conda_channels).toEqual([ | ||
'conda-forge', | ||
'anaconda', | ||
'bioconda', | ||
]) | ||
expect(config.os).toEqual(process.platform) | ||
}) | ||
it("test config values", () => { | ||
const config = loadConfig(); | ||
expect(config.activate_conda).toEqual(true); | ||
expect(config.update_conda).toEqual(true); | ||
expect(config.python_version).toEqual("default"); | ||
expect(config.conda_channels).toEqual(["conda-forge", "anaconda", "bioconda"]); | ||
expect(config.os).toEqual(process.platform); | ||
}); | ||
|
||
it('no channels', () => { | ||
process.env['INPUT_CONDA-CHANNELS'] = '' | ||
const config = loadConfig() | ||
expect(config.conda_channels).toEqual([]) | ||
}) | ||
}) | ||
it("no channels", () => { | ||
process.env["INPUT_CONDA-CHANNELS"] = ""; | ||
const config = loadConfig(); | ||
expect(config.conda_channels).toEqual([]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"$schema": "https://biomejs.dev/schemas/1.9.3/schema.json", | ||
"organizeImports": { | ||
"enabled": true | ||
}, | ||
"linter": { | ||
"enabled": true, | ||
"rules": { | ||
"recommended": true | ||
} | ||
}, | ||
"formatter": { | ||
"indentStyle": "space", // default is `tab` | ||
"lineWidth": 100 // default is `80` | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.