Skip to content

Commit 259b677

Browse files
mbudnekducthinh993
authored andcommitted
feat(pip-compile): Support compiling dependencies from pyproject.toml (renovatebot#37457)
1 parent c184791 commit 259b677

File tree

3 files changed

+51
-14
lines changed

3 files changed

+51
-14
lines changed

lib/modules/manager/pip-compile/extract.spec.ts

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { codeBlock } from 'common-tags';
12
import upath from 'upath';
23
import { GlobalConfig } from '../../../config/global';
34
import type { RepoGlobalConfig } from '../../../config/types';
@@ -36,8 +37,8 @@ describe('modules/manager/pip-compile/extract', () => {
3637
});
3738

3839
describe('extractPackageFile()', () => {
39-
it('returns object for requirements.in', () => {
40-
const packageFile = extractPackageFile(
40+
it('returns object for requirements.in', async () => {
41+
const packageFile = await extractPackageFile(
4142
Fixtures.get('requirementsWithHashes.txt'),
4243
'requirements.in',
4344
{},
@@ -46,8 +47,8 @@ describe('modules/manager/pip-compile/extract', () => {
4647
expect(packageFile?.deps[0]).toHaveProperty('depName', 'attrs');
4748
});
4849

49-
it('returns object for setup.py', () => {
50-
const packageFile = extractPackageFile(
50+
it('returns object for setup.py', async () => {
51+
const packageFile = await extractPackageFile(
5152
Fixtures.get('setup.py', '../pip_setup'),
5253
'lib/setup.py',
5354
{},
@@ -56,15 +57,47 @@ describe('modules/manager/pip-compile/extract', () => {
5657
expect(packageFile?.deps[0]).toHaveProperty('depName', 'celery');
5758
});
5859

60+
it('returns object for pyproject.toml', async () => {
61+
const pyproject = codeBlock`
62+
[build-system]
63+
requires = ["setuptools", "wheel"]
64+
build-backend = "setuptools.build_meta"
65+
66+
[project]
67+
name = "test-project"
68+
requires-python = ">=3.11"
69+
version = "1.2.3"
70+
description = "Test project for pip-compile with setuptools"
71+
readme = "README.md"
72+
dependencies = [
73+
"aiohttp",
74+
"pydantic>=2.0.0",
75+
]
76+
77+
[project.optional-dependencies]
78+
dev = [
79+
"black",
80+
"flake8",
81+
]
82+
`;
83+
const packageFile = await extractPackageFile(
84+
pyproject,
85+
'pyproject.toml',
86+
{},
87+
);
88+
expect(packageFile).toHaveProperty('deps');
89+
expect(packageFile?.deps[0]).toHaveProperty('depType', 'requires-python');
90+
expect(packageFile?.deps[1]).toHaveProperty('depName', 'aiohttp');
91+
});
92+
5993
it.each([
6094
'random.py',
6195
'app.cfg',
6296
'already_locked.txt',
6397
// TODO(not7cd)
64-
'pyproject.toml',
6598
'setup.cfg',
66-
])('returns null on not supported package files', (file: string) => {
67-
expect(extractPackageFile('some content', file, {})).toBeNull();
99+
])('returns null on not supported package files', async (file: string) => {
100+
expect(await extractPackageFile('some content', file, {})).toBeNull();
68101
});
69102
});
70103

lib/modules/manager/pip-compile/extract.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { logger } from '../../../logger';
33
import { coerceArray } from '../../../util/array';
44
import { readLocalFile } from '../../../util/fs';
55
import { ensureLocalPath } from '../../../util/fs/util';
6+
import { extractPackageFile as extractPep621File } from '../pep621/extract';
67
import { extractPackageFile as extractRequirementsFile } from '../pip_requirements/extract';
78
import { extractPackageFile as extractSetupPyFile } from '../pip_setup';
89
import type {
@@ -19,18 +20,20 @@ import {
1920
sortPackageFiles,
2021
} from './utils';
2122

22-
export function extractPackageFile(
23+
export async function extractPackageFile(
2324
content: string,
2425
packageFile: string,
2526
_config: ExtractConfig,
26-
): PackageFileContent | null {
27+
): Promise<PackageFileContent | null> {
2728
logger.trace('pip-compile.extractPackageFile()');
2829
const manager = matchManager(packageFile);
2930
switch (manager) {
3031
case 'pip_setup':
3132
return extractSetupPyFile(content, packageFile, _config);
3233
case 'pip_requirements':
3334
return extractRequirementsFile(content);
35+
case 'pep621':
36+
return await extractPep621File(content, packageFile, _config);
3437
case 'unknown':
3538
logger.warn(
3639
{ packageFile },
@@ -134,7 +137,7 @@ export async function extractAllPackageFiles(
134137
continue;
135138
}
136139

137-
const packageFileContent = extractPackageFile(
140+
const packageFileContent = await extractPackageFile(
138141
content,
139142
packageFile,
140143
config,

lib/modules/manager/pip-compile/readme.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ In turn `pip-compile` manager will find all source files and parse them as packa
3232

3333
The following files are currently supported:
3434

35-
| Source filename | Manager |
36-
| --------------: | ------------------ |
37-
| `setup.py` | `pip_setup` |
38-
| `*.in` | `pip_requirements` |
35+
| Source filename | Manager |
36+
| ---------------: | ------------------ |
37+
| `pyproject.toml` | `pep621` |
38+
| `setup.py` | `pip_setup` |
39+
| `*.in` | `pip_requirements` |
3940

4041
Example header:
4142

0 commit comments

Comments
 (0)