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

feat(manager/uv): set registry URLs #31186

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
62 changes: 61 additions & 1 deletion lib/modules/manager/pep621/processors/uv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,18 @@ describe('modules/manager/pep621/processors/uv', () => {
const result = processor.process(pyproject, dependencies);

expect(result).toEqual([
{ packageName: 'dep1' },
{
packageName: 'dep1',
registryUrls: ['https://pypi.org/pypi/'],
},
{
currentValue: '==1.2.3',
currentVersion: '1.2.3',
datasource: 'pypi',
depName: 'dep2',
depType: 'tool.uv.dev-dependencies',
packageName: 'dep2',
registryUrls: ['https://pypi.org/pypi/'],
},
{
currentValue: '==2.3.4',
Expand All @@ -58,6 +62,62 @@ describe('modules/manager/pep621/processors/uv', () => {
depName: 'dep3',
depType: 'tool.uv.dev-dependencies',
packageName: 'dep3',
registryUrls: ['https://pypi.org/pypi/'],
},
]);
});

it('uses default PyPI and extra URLs when setting extra-index-url', () => {
const pyproject = {
tool: {
uv: {
'extra-index-url': [
'https://foo.example.com',
'https://bar.example.com',
],
},
},
};
const dependencies = [{ packageName: 'dep1' }];

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

expect(result).toEqual([
{
packageName: 'dep1',
registryUrls: [
'https://foo.example.com',
'https://bar.example.com',
'https://pypi.org/pypi/',
],
},
]);
});

it('uses index and extra URLs when setting index-url and extra-index-url', () => {
const pyproject = {
tool: {
uv: {
'index-url': 'https://foobar.example.com',
'extra-index-url': [
'https://foo.example.com',
'https://bar.example.com',
],
},
},
};
const dependencies = [{ packageName: 'dep1' }];

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

expect(result).toEqual([
{
packageName: 'dep1',
registryUrls: [
'https://foo.example.com',
'https://bar.example.com',
'https://foobar.example.com',
],
},
]);
});
Expand Down
18 changes: 17 additions & 1 deletion lib/modules/manager/pep621/processors/uv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import { exec } from '../../../../util/exec';
import type { ExecOptions, ToolConstraint } from '../../../../util/exec/types';
import { getSiblingFileName, readLocalFile } from '../../../../util/fs';
import { Result } from '../../../../util/result';
import { PypiDatasource } from '../../../datasource/pypi';
import type {
PackageDependency,
UpdateArtifact,
UpdateArtifactsResult,
Upgrade,
} from '../../types';
import { type PyProject, UvLockfileSchema } from '../schema';
import { type PyProject, type Uv, UvLockfileSchema } from '../schema';
import { depTypes, parseDependencyList } from '../utils';
import type { PyProjectProcessor } from './types';

Expand All @@ -32,6 +33,11 @@ export class UvProcessor implements PyProjectProcessor {
),
);

const registryUrls = extractRegistryUrls(uv);
for (const dep of deps) {
dep.registryUrls = [...registryUrls];
mkniewallner marked this conversation as resolved.
Show resolved Hide resolved
}

return deps;
}

Expand Down Expand Up @@ -142,6 +148,16 @@ export class UvProcessor implements PyProjectProcessor {
}
}

function extractRegistryUrls(uvManifest: Uv): string[] {
rarkins marked this conversation as resolved.
Show resolved Hide resolved
// Extra indexes have priority over default index: https://docs.astral.sh/uv/reference/settings/#extra-index-url
const registryUrls = uvManifest['extra-index-url'] ?? [];

// If default index URL is not overridden, we need to use default PyPI URL additionally to potential extra indexes.
registryUrls.push(uvManifest['index-url'] ?? PypiDatasource.defaultURL);

return registryUrls;
}

function generateCMD(updatedDeps: Upgrade[]): string {
const deps: string[] = [];

Expand Down
72 changes: 38 additions & 34 deletions lib/modules/manager/pep621/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,41 @@ const DependencyRecordSchema = z
.record(z.string(), z.array(z.string()))
.optional();

const PdmSchema = z.object({
'dev-dependencies': DependencyRecordSchema,
source: z
.array(
z.object({
url: z.string(),
name: z.string(),
verify_ssl: z.boolean().optional(),
}),
)
.optional(),
});

const HatchSchema = z.object({
envs: z
.record(
z.string(),
z
.object({
dependencies: DependencyListSchema,
'extra-dependencies': DependencyListSchema,
})
.optional(),
)
.optional(),
});

const UvSchema = z.object({
'dev-dependencies': DependencyListSchema,
'index-url': z.string().optional(),
'extra-index-url': z.array(z.string()).optional(),
});

export type Uv = z.infer<typeof UvSchema>;

export const PyProjectSchema = z.object({
project: z
.object({
Expand All @@ -25,40 +60,9 @@ export const PyProjectSchema = z.object({
.optional(),
tool: z
.object({
pdm: z
.object({
'dev-dependencies': DependencyRecordSchema,
source: z
.array(
z.object({
url: z.string(),
name: z.string(),
verify_ssl: z.boolean().optional(),
}),
)
.optional(),
})
.optional(),
hatch: z
.object({
envs: z
.record(
z.string(),
z
.object({
dependencies: DependencyListSchema,
'extra-dependencies': DependencyListSchema,
})
.optional(),
)
.optional(),
})
.optional(),
uv: z
.object({
'dev-dependencies': DependencyListSchema,
})
.optional(),
pdm: PdmSchema.optional(),
hatch: HatchSchema.optional(),
uv: UvSchema.optional(),
})
.optional(),
});
Expand Down