Skip to content

Commit 0fc6a29

Browse files
committed
feature: add version parsing from Pipfile
1 parent 5db1cf9 commit 0fc6a29

File tree

5 files changed

+1046
-108
lines changed

5 files changed

+1046
-108
lines changed

.github/workflows/test-python.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,108 @@ jobs:
284284
with:
285285
python-version-file: .tool-versions
286286

287+
setup-versions-from-pipfile-with-python_version:
288+
name: Setup ${{ matrix.python }} ${{ matrix.os }} Pipfile with python_version
289+
runs-on: ${{ matrix.os }}
290+
strategy:
291+
fail-fast: false
292+
matrix:
293+
os:
294+
[
295+
macos-latest,
296+
windows-latest,
297+
ubuntu-20.04,
298+
ubuntu-22.04,
299+
ubuntu-22.04-arm,
300+
macos-13,
301+
ubuntu-latest,
302+
ubuntu-24.04-arm
303+
]
304+
python: [3.9.13, 3.10.11, 3.11.9, 3.13.2]
305+
steps:
306+
- name: Checkout
307+
uses: actions/checkout@v4
308+
309+
- name: build-version-file ${{ matrix.python }}
310+
run: |
311+
echo '[requires]
312+
python_version = "${{ matrix.python }}"
313+
' > Pipenv
314+
315+
- name: setup-python ${{ matrix.python }}
316+
id: setup-python
317+
uses: ./
318+
with:
319+
python-version-file: Pipenv
320+
321+
- name: Check python-path
322+
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
323+
shell: bash
324+
325+
- name: Validate version
326+
run: |
327+
$pythonVersion = (python --version)
328+
if ("Python ${{ matrix.python }}".replace("==", "") -ne "$pythonVersion"){
329+
Write-Host "The current version is $pythonVersion; expected version is ${{ matrix.python }}"
330+
exit 1
331+
}
332+
$pythonVersion
333+
shell: pwsh
334+
335+
- name: Run simple code
336+
run: python -c 'import math; print(math.factorial(5))'
337+
338+
setup-versions-from-pipfile-with-python_full_version:
339+
name: Setup ${{ matrix.python }} ${{ matrix.os }} Pipfile with python_full_version
340+
runs-on: ${{ matrix.os }}
341+
strategy:
342+
fail-fast: false
343+
matrix:
344+
os:
345+
[
346+
macos-latest,
347+
windows-latest,
348+
ubuntu-20.04,
349+
ubuntu-22.04,
350+
ubuntu-22.04-arm,
351+
macos-13,
352+
ubuntu-latest,
353+
ubuntu-24.04-arm
354+
]
355+
python: [3.9.13, 3.10.11, 3.11.9, 3.13.2]
356+
steps:
357+
- name: Checkout
358+
uses: actions/checkout@v4
359+
360+
- name: build-version-file ${{ matrix.python }}
361+
run: |
362+
echo '[requires]
363+
python_full_version = "${{ matrix.python }}"
364+
' > Pipenv
365+
366+
- name: setup-python ${{ matrix.python }}
367+
id: setup-python
368+
uses: ./
369+
with:
370+
python-version-file: Pipenv
371+
372+
- name: Check python-path
373+
run: ./__tests__/check-python-path.sh '${{ steps.setup-python.outputs.python-path }}'
374+
shell: bash
375+
376+
- name: Validate version
377+
run: |
378+
$pythonVersion = (python --version)
379+
if ("Python ${{ matrix.python }}".replace("==", "") -ne "$pythonVersion"){
380+
Write-Host "The current version is $pythonVersion; expected version is ${{ matrix.python }}"
381+
exit 1
382+
}
383+
$pythonVersion
384+
shell: pwsh
385+
386+
- name: Run simple code
387+
run: python -c 'import math; print(math.factorial(5))'
388+
287389
setup-pre-release-version-from-manifest:
288390
name: Setup 3.14.0-alpha.6 ${{ matrix.os }}
289391
runs-on: ${{ matrix.os }}

__tests__/utils.test.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
getVersionInputFromFile,
1313
getVersionsInputFromPlainFile,
1414
getVersionInputFromTomlFile,
15+
getVersionInputFromPipfileFile,
1516
getNextPageUrl,
1617
isGhes,
1718
IS_WINDOWS,
@@ -244,6 +245,44 @@ describe('Version from file test', () => {
244245
expect(_fn(toolVersionFilePath)).toEqual(['3.14t-dev']);
245246
}
246247
);
248+
249+
it.each([getVersionInputFromPipfileFile, getVersionInputFromFile])(
250+
'Version from python_version in Pipfile',
251+
async _fn => {
252+
await io.mkdirP(tempDir);
253+
const pythonVersionFileName = 'Pipfile';
254+
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
255+
const pythonVersion = '3.7';
256+
const pythonVersionFileContent = `[requires]\npython_version = "${pythonVersion}"`;
257+
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
258+
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
259+
}
260+
);
261+
262+
it.each([getVersionInputFromPipfileFile, getVersionInputFromFile])(
263+
'Version from python_full_version in Pipfile',
264+
async _fn => {
265+
await io.mkdirP(tempDir);
266+
const pythonVersionFileName = 'Pipfile';
267+
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
268+
const pythonVersion = '3.7.0';
269+
const pythonVersionFileContent = `[requires]\npython_full_version = "${pythonVersion}"`;
270+
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
271+
expect(_fn(pythonVersionFilePath)).toEqual([pythonVersion]);
272+
}
273+
);
274+
275+
it.each([getVersionInputFromPipfileFile, getVersionInputFromFile])(
276+
'Pipfile undefined version',
277+
async _fn => {
278+
await io.mkdirP(tempDir);
279+
const pythonVersionFileName = 'Pipfile';
280+
const pythonVersionFilePath = path.join(tempDir, pythonVersionFileName);
281+
const pythonVersionFileContent = ``;
282+
fs.writeFileSync(pythonVersionFilePath, pythonVersionFileContent);
283+
expect(_fn(pythonVersionFilePath)).toEqual([]);
284+
}
285+
);
247286
});
248287

249288
describe('getNextPageUrl', () => {

0 commit comments

Comments
 (0)