Skip to content

Commit 11917a6

Browse files
ruromeroclaude
andcommitted
fix(python): differentiate python_version (X.Y) from python_full_version (X.Y.Z)
PEP 508 defines python_version as major.minor and python_full_version as major.minor.micro. The Python command now queries both components in a single call, and getEnvironmentMarkers() assigns them separately. Resolves TC-4315 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 31416b3 commit 11917a6

2 files changed

Lines changed: 45 additions & 11 deletions

File tree

src/providers/marker_evaluator.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,19 @@
66
import { execSync } from 'node:child_process'
77
import os from 'node:os'
88

9-
let cachedPythonVersion = undefined
9+
let cachedPythonVersions = undefined
1010

11-
function getPythonVersion() {
12-
if (cachedPythonVersion !== undefined) { return cachedPythonVersion }
11+
function getPythonVersions() {
12+
if (cachedPythonVersions !== undefined) { return cachedPythonVersions }
1313
try {
14-
let out = execSync('python3 -c "import sys; print(f\'{sys.version_info.major}.{sys.version_info.minor}\')"',
14+
let out = execSync('python3 -c "import sys; v=sys.version_info; print(f\'{v.major}.{v.minor} {v.major}.{v.minor}.{v.micro}\')"',
1515
{ timeout: 5000, stdio: ['pipe', 'pipe', 'pipe'] }).toString().trim()
16-
cachedPythonVersion = out
16+
let [short, full] = out.split(' ')
17+
cachedPythonVersions = { short, full }
1718
} catch {
18-
cachedPythonVersion = null
19+
cachedPythonVersions = null
1920
}
20-
return cachedPythonVersion
21+
return cachedPythonVersions
2122
}
2223

2324
/**
@@ -29,16 +30,16 @@ export function getEnvironmentMarkers() {
2930
let platform = process.platform
3031
let systemMap = { win32: 'Windows', linux: 'Linux', darwin: 'Darwin' }
3132
let machine = typeof os.machine === 'function' ? os.machine() : process.arch
32-
let pyVer = getPythonVersion()
33+
let pyVer = getPythonVersions()
3334
return {
3435
sys_platform: platform,
3536
platform_system: systemMap[platform] || platform,
3637
os_name: platform === 'win32' ? 'nt' : 'posix',
3738
platform_machine: machine,
3839
platform_release: os.release(),
3940
platform_version: os.version?.() || '',
40-
python_version: pyVer || '',
41-
python_full_version: pyVer || '',
41+
python_version: pyVer?.short || '',
42+
python_full_version: pyVer?.full || '',
4243
implementation_name: 'cpython',
4344
}
4445
}

test/providers/marker_evaluator.test.js

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { expect } from 'chai'
22

3-
import { evaluateMarker } from '../../src/providers/marker_evaluator.js'
3+
import { evaluateMarker, getEnvironmentMarkers } from '../../src/providers/marker_evaluator.js'
44

55
let originalPlatform
66

@@ -82,4 +82,37 @@ suite('PEP 508 marker evaluator', () => {
8282
)
8383
})
8484
})
85+
86+
suite('python_version vs python_full_version', () => {
87+
test('python_version matches X.Y format', () => {
88+
let env = getEnvironmentMarkers()
89+
if (env.python_version) {
90+
expect(env.python_version).to.match(/^\d+\.\d+$/)
91+
}
92+
})
93+
94+
test('python_full_version matches X.Y.Z format', () => {
95+
let env = getEnvironmentMarkers()
96+
if (env.python_full_version) {
97+
expect(env.python_full_version).to.match(/^\d+\.\d+\.\d+$/)
98+
}
99+
})
100+
101+
test('python_full_version starts with python_version', () => {
102+
let env = getEnvironmentMarkers()
103+
if (env.python_version && env.python_full_version) {
104+
expect(env.python_full_version).to.satisfy(
105+
v => v.startsWith(env.python_version + '.')
106+
)
107+
}
108+
})
109+
110+
test('python_full_version marker evaluates with micro version', () => {
111+
let env = getEnvironmentMarkers()
112+
if (env.python_full_version) {
113+
expect(evaluateMarker(`python_full_version >= '${env.python_full_version}'`)).to.be.true
114+
expect(evaluateMarker(`python_full_version == '${env.python_full_version}'`)).to.be.true
115+
}
116+
})
117+
})
85118
})

0 commit comments

Comments
 (0)