Skip to content

Commit

Permalink
fix(manager/uv): skip unsupported sources
Browse files Browse the repository at this point in the history
  • Loading branch information
mkniewallner committed Sep 8, 2024
1 parent 57b1c92 commit 7183564
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 3 deletions.
61 changes: 58 additions & 3 deletions lib/modules/manager/pep621/processors/uv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ describe('modules/manager/pep621/processors/uv', () => {
describe('process()', () => {
it('returns initial dependencies if there is no tool.uv section', () => {
const pyproject = { tool: {} };
const dependencies = [{ packageName: 'dep1' }];
const dependencies = [{ depName: 'dep1' }];

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

Expand All @@ -37,12 +37,12 @@ describe('modules/manager/pep621/processors/uv', () => {
const pyproject = {
tool: { uv: { 'dev-dependencies': ['dep2==1.2.3', 'dep3==2.3.4'] } },
};
const dependencies = [{ packageName: 'dep1' }];
const dependencies = [{ depName: 'dep1' }];

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

expect(result).toEqual([
{ packageName: 'dep1' },
{ depName: 'dep1' },
{
currentValue: '==1.2.3',
currentVersion: '1.2.3',
Expand All @@ -61,6 +61,61 @@ describe('modules/manager/pep621/processors/uv', () => {
},
]);
});

it('skips dependencies with unsupported sources', () => {
const pyproject = {
tool: {
uv: {
sources: {
dep2: { workspace: false },
dep3: { git: 'https://github.com/foo/bar' },
dep4: { path: '/local-dep.whl' },
dep5: { url: 'https://example.com' },
dep6: { workspace: true },
},
},
},
};
const dependencies = [
{ depName: 'dep1' },
{ depName: 'dep2' },
{ depName: 'dep3' },
{ depName: 'dep4' },
{ depName: 'dep5' },
{ depName: 'dep6' },
];

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

expect(result).toEqual([
{
depName: 'dep1',
},
{
depName: 'dep2',
},
{
depName: 'dep3',
currentValue: '',
skipReason: 'git-dependency',
},
{
depName: 'dep4',
currentValue: '',
skipReason: 'path-dependency',
},
{
depName: 'dep5',
currentValue: '',
skipReason: 'unsupported-url',
},
{
depName: 'dep6',
currentValue: '',
skipReason: 'inherited-dependency',
},
]);
});
});

describe('updateArtifacts()', () => {
Expand Down
31 changes: 31 additions & 0 deletions lib/modules/manager/pep621/processors/uv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import is from '@sindresorhus/is';
import { quote } from 'shlex';
import { TEMPORARY_ERROR } from '../../../../constants/error-messages';
import { logger } from '../../../../logger';
import type { SkipReason } from '../../../../types';
import { exec } from '../../../../util/exec';
import type { ExecOptions, ToolConstraint } from '../../../../util/exec/types';
import { getSiblingFileName, readLocalFile } from '../../../../util/fs';
Expand Down Expand Up @@ -32,6 +33,36 @@ export class UvProcessor implements PyProjectProcessor {
),
);

// https://docs.astral.sh/uv/concepts/dependencies/#dependency-sources
// Skip sources that are either not yet handled by Renovate (e.g. git), or do not make sense to handle (e.g. path).
if (uv.sources) {
for (const dep of deps) {
if (!dep.depName) {
continue;
}

const depSource = uv.sources[dep.depName];
if (depSource) {
let skipReason: SkipReason | undefined;

if (depSource.git) {
skipReason = 'git-dependency';
} else if (depSource.url) {
skipReason = 'unsupported-url';
} else if (depSource.path) {
skipReason = 'path-dependency';
} else if (depSource.workspace === true) {
skipReason = 'inherited-dependency';
}

if (skipReason) {
dep.currentValue = '';
dep.skipReason = skipReason;
}
}
}
}

return deps;
}

Expand Down
8 changes: 8 additions & 0 deletions lib/modules/manager/pep621/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,16 @@ const HatchSchema = z.object({
.optional(),
});

const UvSource = z.object({
git: z.string().optional(),
path: z.string().optional(),
url: z.string().optional(),
workspace: z.boolean().optional(),
});

const UvSchema = z.object({
'dev-dependencies': DependencyListSchema,
sources: z.record(z.string(), UvSource).optional(),
});

export const PyProjectSchema = z.object({
Expand Down

0 comments on commit 7183564

Please sign in to comment.