Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(manager/uv): apply normalization on sources #31297

Merged
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
7 changes: 5 additions & 2 deletions lib/modules/manager/pep621/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,14 +339,15 @@ describe('modules/manager/pep621/extract', () => {
"dep4",
"dep5",
"dep6",
"dep7",
"dep-with_NORMALIZATION",
]

[tool.uv.sources]
dep2 = { git = "https://github.com/foo/bar" }
dep3 = { path = "/local-dep.whl" }
dep4 = { url = "https://example.com" }
dep5 = { workspace = true }
dep_WITH-normalization = { workspace = true }
`,
'pyproject.toml',
);
Expand Down Expand Up @@ -382,7 +383,9 @@ describe('modules/manager/pep621/extract', () => {
depName: 'dep6',
},
{
depName: 'dep7',
depName: 'dep-with_NORMALIZATION',
depType: depTypes.uvSources,
skipReason: 'inherited-dependency',
},
]);
});
Expand Down
11 changes: 10 additions & 1 deletion lib/modules/manager/pep621/processors/uv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,16 @@ describe('modules/manager/pep621/processors/uv', () => {
},
},
};
const dependencies = [{ depName: 'dep1' }, { depName: 'dep2' }];
const dependencies = [
{
depName: 'dep1',
packageName: 'dep1',
},
{
depName: 'dep2',
packageName: 'dep2',
},
];

const result = processor.process(pyproject, dependencies);

Expand Down
6 changes: 4 additions & 2 deletions lib/modules/manager/pep621/processors/uv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@ export class UvProcessor implements PyProjectProcessor {
if (uv.sources) {
for (const dep of deps) {
// istanbul ignore if
if (!dep.depName) {
if (!dep.packageName) {
continue;
}

const depSource = uv.sources[dep.depName];
// Using `packageName` as it applies PEP 508 normalization, which is
// also applied by uv when matching a source to a dependency.
const depSource = uv.sources[dep.packageName];
if (depSource) {
dep.depType = depTypes.uvSources;
if ('url' in depSource) {
Expand Down
7 changes: 6 additions & 1 deletion lib/modules/manager/pep621/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from 'zod';
import { LooseArray, LooseRecord, Toml } from '../../../util/schema-utils';
import { normalizePythonDepName } from '../../datasource/pypi/common';

export type PyProject = z.infer<typeof PyProjectSchema>;

Expand Down Expand Up @@ -65,7 +66,11 @@ const UvSource = z.union([

const UvSchema = z.object({
'dev-dependencies': DependencyListSchema,
sources: LooseRecord(z.string(), UvSource).optional(),
sources: LooseRecord(
// uv applies the same normalization as for Python dependencies on sources
z.string().transform((source) => normalizePythonDepName(source)),
UvSource,
).optional(),
});

export const PyProjectSchema = z.object({
Expand Down