Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🩹 Fix updating base conda causes error on windows #475

Merged
merged 4 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 22 additions & 18 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ repos:
# FORMATTER #
###################
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-ast
- id: check-builtin-literals
Expand All @@ -21,13 +21,22 @@ repos:
- id: absolufy-imports

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
rev: v4.0.0-alpha.8
hooks:
- id: prettier
exclude: '.all-contributorsrc'
additional_dependencies:
- 'prettier@3.3.3'
exclude_types:
- 'javascript'
- 'ts'
- 'tsx'
- 'json'
- 'css'
- 'scss'
exclude: "\\.jsonc|.all-contributorsrc"

- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
rev: 06907d0
hooks:
- id: docformatter
additional_dependencies: [tomli]
Expand All @@ -38,7 +47,7 @@ repos:
###################
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.4
rev: v0.7.0
hooks:
- id: ruff
name: 'ruff sort imports'
Expand All @@ -52,27 +61,22 @@ repos:
- id: ruff
name: 'ruff lint'

- repo: https://github.com/pre-commit/mirrors-eslint
rev: 'v8.56.0' # Use the sha / tag you want to point at
- repo: https://github.com/biomejs/pre-commit
rev: 'v0.5.0' # Use the sha / tag you want to point at
hooks:
- id: eslint
files: \.ts$
types: [file]
additional_dependencies:
- eslint@8.56.0
- '@typescript-eslint/eslint-plugin@7.9.0'
- '@typescript-eslint/parser@7.9.0'
- 'eslint-config-prettier@9.1.0'
- 'eslint-plugin-prettier@5.1.3'
- id: biome-check
additional_dependencies: ['@biomejs/biome@1.9.3']
- id: biome-format
additional_dependencies: ['@biomejs/biome@1.9.3']

- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
rev: v2.3.0
hooks:
- id: codespell
types: [file]
types_or: [python, markdown]

- repo: https://github.com/rhysd/actionlint
rev: 'v1.7.0'
rev: 'v1.7.3'
hooks:
- id: actionlint
2 changes: 1 addition & 1 deletion CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
level of experience, education, socioeconomic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards
Expand Down
164 changes: 74 additions & 90 deletions __tests__/conda_actions.test.ts
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),
)
})
})
);
});
});
56 changes: 26 additions & 30 deletions __tests__/load_config.test.ts
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([]);
});
});
16 changes: 16 additions & 0 deletions biome.jsonc
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`
}
}
27 changes: 0 additions & 27 deletions eslint.config.js

This file was deleted.

Loading
Loading