diff --git a/src/hooks/useVirtualEnv.ts b/src/hooks/useVirtualEnv.ts index 7216f266e..d7c441b9c 100644 --- a/src/hooks/useVirtualEnv.ts +++ b/src/hooks/useVirtualEnv.ts @@ -142,6 +142,23 @@ export default async function(cwd: Path = Path.cwd()): Promise { throw new Error('couldn’t parse: .node-version') } } + if (_if(".python-version")) { + const s = (await f!.read()).trim() + const lines = s.split("\n") + for (let l of lines) { + l = l.trim() + if (!l) continue // skip empty lines + if (l.startsWith('#')) continue // skip commented lines + // TODO: How to handle 'system'? + // TODO: How to handle non-bare versions like pypy3.9-7.3.11, stackless-3.7.5, etc. in pyenv install --list? + l = `python.org@${l}` + try { + pkgs.push(pkg.parse(l)) + } catch { + throw new Error('couldn’t parse: .python-version') + } + } + } if (_if("package.json")) { const json = JSON.parse(await f!.read()) if (isPlainObject(json?.tea)) { diff --git a/tests/fixtures/.python-version b/tests/fixtures/.python-version new file mode 100644 index 000000000..c8cfe3959 --- /dev/null +++ b/tests/fixtures/.python-version @@ -0,0 +1 @@ +3.10 diff --git a/tests/functional/devenv.test.ts b/tests/functional/devenv.test.ts index 786d6ac3e..94c70044c 100644 --- a/tests/functional/devenv.test.ts +++ b/tests/functional/devenv.test.ts @@ -124,6 +124,26 @@ Deno.test("should provide packages in dev env", { sanitizeResources: false, sani } }) +Deno.test("should provide python in dev env", { sanitizeResources: false, sanitizeOps: false }, async test => { + const SHELL = "/bin/zsh" + + const tests = [ + { file: ".python-version", pkg: "python.org~3.10" } + ] + + for (const { file, pkg } of tests) { + await test.step(file, async () => { + const { run, teaDir } = await createTestHarness() + + fixturesDir.join(file).cp({ into: teaDir }) + const { stdout } = await run(["+tea.xyz/magic", "-Esk", "--chaste", "env"], { env: { SHELL } }) + + const output = getTeaPackages(SHELL, stdout) + assert(output.includes(pkg), "should include python dep") + }) + } +}) + Deno.test("tolerant .node-version parsing", { sanitizeResources: false, sanitizeOps: false }, async test => { const SHELL = "/bin/zsh"