Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions lib/modules/manager/pep621/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,91 @@ describe('modules/manager/pep621/extract', () => {
});
});

it('should flag deps which pdm.lock holds at more than one version', async () => {
fs.getSiblingFileName.mockReturnValueOnce('pdm.lock');
fs.readLocalFile.mockResolvedValueOnce(
codeBlock`
[metadata]
groups = ["default"]
strategy = ["inherit_metadata"]
lock_version = "4.5.0"
[[metadata.targets]]
requires_python = ">=3.10"
[[metadata.targets]]
requires_python = ">=3.9,<3.10"
[[package]]
name = "numpy"
version = "2.2.6"
requires_python = ">=3.10"
[[package]]
name = "numpy"
version = "2.0.2"
requires_python = ">=3.9"
[[package]]
name = "httpx"
version = "0.28.1"
[[package]]
name = "httpx"
version = "0.28.1"
extras = ["socks"]
[[package]]
name = "urllib3"
version = "2.5.0"
[[package]]
name = "urllib3"
version = "1.26.20"
[[package]]
name = "urllib3"
version = "1.26.20"
extras = ["socks"]
`,
);
// pdm.lock, then no uv.lock
fs.findLocalSiblingOrParent.mockResolvedValueOnce('pdm.lock');
fs.findLocalSiblingOrParent.mockResolvedValueOnce(null);

const res = await extractPackageFile(
codeBlock`
[project]
name = "pep621-pdm"
dependencies = ["numpy>=2.0", "httpx[socks]>=0.28", "urllib3>=1.26"]
[tool.pdm]
distribution = false
`,
'pyproject.toml',
);

// the version of the last entry is the locked one, as before
expect(res?.deps).toEqual([
expect.objectContaining({
packageName: 'numpy',
lockedVersion: '2.0.2',
managerData: { hasMultipleLockedEntries: true },
}),
// an entry with extras is the same package at the same version
expect.not.objectContaining({ managerData: expect.anything() }),
expect.objectContaining({
packageName: 'urllib3',
lockedVersion: '1.26.20',
managerData: { hasMultipleLockedEntries: true },
}),
]);
expect(res?.deps[1]).toMatchObject({
packageName: 'httpx',
lockedVersion: '0.28.1',
});
});

it('should resolve lockedVersions from uv.lock', async () => {
fs.readLocalFile.mockResolvedValue(
codeBlock`
Expand Down
11 changes: 9 additions & 2 deletions lib/modules/manager/pep621/processors/pdm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,17 @@ export class PdmProcessor extends BasePyProjectProcessor {
PdmLockfile.transform(({ lock }) => lock),
).unwrapOr({});

for (const dep of deps) {
for (const dep of deps as PackageDependency<Pep621ManagerData>[]) {
Comment thread
secustor marked this conversation as resolved.
Resolved
const packageName = dep.packageName;
if (packageName && packageName in lockFileMapping) {
dep.lockedVersion = lockFileMapping[packageName];
const locked = lockFileMapping[packageName];
dep.lockedVersion = locked.version;
if (locked.hasMultipleEntries) {
dep.managerData = {
...dep.managerData,
hasMultipleLockedEntries: true,
};
}
}
}
}
Expand Down
32 changes: 27 additions & 5 deletions lib/modules/manager/pep621/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ export const PyProject = z.object({
});
export type PyProject = z.infer<typeof PyProject>;

export interface PdmLockedPackage {
version: string;
/**
* Whether the lock file holds this package at more than one version, as it
* does when lock targets resolve to different versions.
*/
hasMultipleEntries?: boolean;
}

export const PdmLockfile = Toml.pipe(
z.object({
package: LooseArray(
Expand All @@ -246,11 +255,24 @@ export const PdmLockfile = Toml.pipe(
),
}),
)
.transform(({ package: pkg }) =>
Object.fromEntries(
pkg.map(({ name, version }): [string, string] => [name, version]),
),
)
.transform(({ package: pkgs }) => {
const lock: Record<string, PdmLockedPackage> = {};
for (const { name, version } of pkgs) {
const locked = lock[name];
if (!locked) {
lock[name] = { version };
continue;
}
// A package with extras has an entry of its own at the same version, so
// only another version counts. The last entry wins.
const hasMultipleEntries =
locked.hasMultipleEntries === true || locked.version !== version;
lock[name] = hasMultipleEntries
? { version, hasMultipleEntries }
: { version };
}
return lock;
})
.transform((lock) => ({ lock }));

export interface UvLockedPackage {
Expand Down
Loading