Skip to content

Commit

Permalink
Add initial support for .python-version files
Browse files Browse the repository at this point in the history
  • Loading branch information
JrGoodle authored and mxcl committed May 9, 2023
1 parent 38304b4 commit 13ed864
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/hooks/useVirtualEnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,23 @@ export default async function(cwd: Path = Path.cwd()): Promise<VirtualEnv> {
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)) {
Expand Down
1 change: 1 addition & 0 deletions tests/fixtures/.python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
20 changes: 20 additions & 0 deletions tests/functional/devenv.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down

0 comments on commit 13ed864

Please sign in to comment.