Skip to content
Snippets Groups Projects
Unverified Commit 89facd1d authored by Hasan Awad's avatar Hasan Awad Committed by GitHub
Browse files

feat: add extractedConstraint field for poetry (#15922)

parent faedc811
Branches
No related tags found
No related merge requests found
......@@ -2,7 +2,6 @@
exports[`modules/manager/poetry/extract extractPackageFile() extracts mixed versioning types 1`] = `
Object {
"constraints": Object {},
"deps": Array [
Object {
"currentValue": "0.2",
......@@ -345,13 +344,13 @@ Object {
"versioning": "pep440",
},
],
"extractedConstraints": Object {},
"registryUrls": undefined,
}
`;
exports[`modules/manager/poetry/extract extractPackageFile() extracts multiple dependencies (with dep = {version = "1.2.3"} case) 1`] = `
Object {
"constraints": Object {},
"deps": Array [
Object {
"currentValue": "*",
......@@ -424,6 +423,7 @@ Object {
"versioning": "poetry",
},
],
"extractedConstraints": Object {},
"registryUrls": undefined,
}
`;
......@@ -533,7 +533,6 @@ Array [
exports[`modules/manager/poetry/extract extractPackageFile() handles multiple constraint dependencies 1`] = `
Object {
"constraints": Object {},
"deps": Array [
Object {
"currentValue": "",
......@@ -546,15 +545,13 @@ Object {
"skipReason": "multiple-constraint-dep",
},
],
"extractedConstraints": Object {},
"registryUrls": undefined,
}
`;
exports[`modules/manager/poetry/extract extractPackageFile() resolves lockedVersions from the lockfile 1`] = `
Object {
"constraints": Object {
"python": "^3.9",
},
"deps": Array [
Object {
"currentValue": "*",
......@@ -568,6 +565,9 @@ Object {
"versioning": "poetry",
},
],
"extractedConstraints": Object {
"python": "^3.9",
},
"registryUrls": undefined,
}
`;
......@@ -44,7 +44,7 @@ describe('modules/manager/poetry/extract', () => {
const res = await extractPackageFile(pyproject1toml, filename);
expect(res.deps).toMatchSnapshot();
expect(res.deps).toHaveLength(9);
expect(res.constraints).toEqual({
expect(res.extractedConstraints).toEqual({
python: '~2.7 || ^3.4',
});
});
......@@ -135,7 +135,7 @@ describe('modules/manager/poetry/extract', () => {
fs.readLocalFile.mockResolvedValue(pyproject11tomlLock);
const res = await extractPackageFile(pyproject11toml, filename);
expect(res).toMatchSnapshot({
constraints: { python: '^3.9' },
extractedConstraints: { python: '^3.9' },
deps: [{ lockedVersion: '1.17.5' }],
});
});
......
......@@ -128,16 +128,17 @@ export async function extractPackageFile(
return null;
}
const constraints: Record<string, any> = {};
const extractedConstraints: Record<string, any> = {};
if (is.nonEmptyString(pyprojectfile.tool?.poetry?.dependencies?.python)) {
constraints.python = pyprojectfile.tool?.poetry?.dependencies?.python;
extractedConstraints.python =
pyprojectfile.tool?.poetry?.dependencies?.python;
}
const res: PackageFile = {
deps,
registryUrls: extractRegistries(pyprojectfile),
constraints,
extractedConstraints,
};
// Try poetry.lock first
let lockFile = getSiblingFileName(fileName, 'poetry.lock');
......
......@@ -76,6 +76,7 @@ export interface PackageFile<T = Record<string, any>>
autoReplaceStringTemplate?: string;
hasYarnWorkspaces?: boolean;
constraints?: Record<string, string>;
extractedConstraints?: Record<string, string>;
datasource?: string;
registryUrls?: string[];
additionalRegistryUrls?: string[];
......
import { mergeConfigConstraints } from './common';
import type { LookupUpdateConfig } from './types';
describe('workers/repository/process/lookup/common', () => {
it('overrides extracted config with user config', () => {
const config: LookupUpdateConfig = {
datasource: '',
depName: '',
versioning: '',
rangeStrategy: 'pin',
};
config.constraints = {
constraint1: 'configValue1',
constraint2: 'configValue2',
constraint3: 'configValue3',
};
config.extractedConstraints = {
constraint3: 'extractedValue3',
constraint4: 'exractedValue4',
};
expect(mergeConfigConstraints(config)).toMatchObject({
datasource: '',
depName: '',
versioning: '',
rangeStrategy: 'pin',
constraints: {
constraint1: 'configValue1',
constraint2: 'configValue2',
constraint3: 'configValue3',
constraint4: 'exractedValue4',
},
});
});
it('sets config with extracted config', () => {
const config: LookupUpdateConfig = {
datasource: '',
depName: '',
versioning: '',
rangeStrategy: 'pin',
};
config.extractedConstraints = {
constraint3: 'extractedValue3',
constraint4: 'exractedValue4',
};
expect(mergeConfigConstraints(config)).toMatchObject({
datasource: '',
depName: '',
versioning: '',
rangeStrategy: 'pin',
constraints: {
constraint3: 'extractedValue3',
constraint4: 'exractedValue4',
},
});
});
});
import type { LookupUpdateConfig } from './types';
export function mergeConfigConstraints(
config: LookupUpdateConfig
): LookupUpdateConfig {
if (config?.extractedConstraints) {
config.constraints = {
...config.extractedConstraints,
...config.constraints,
};
delete config.extractedConstraints;
}
return config;
}
......@@ -19,6 +19,7 @@ import { clone } from '../../../../util/clone';
import { applyPackageRules } from '../../../../util/package-rules';
import { regEx } from '../../../../util/regex';
import { getBucket } from './bucket';
import { mergeConfigConstraints } from './common';
import { getCurrentVersion } from './current';
import { filterVersions } from './filter';
import { filterInternalChecks } from './filter-checks';
......@@ -74,6 +75,8 @@ export async function lookupUpdates(
return res;
}
config = mergeConfigConstraints(config);
const dependency = clone(await getPkgReleases(config));
if (!dependency) {
// If dependency lookup fails then warn and return
......
......@@ -44,6 +44,7 @@ export interface LookupUpdateConfig
datasource: string;
depName: string;
minimumConfidence?: string;
extractedConstraints?: Record<string, string>;
}
export interface UpdateResult {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment