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/pep621): add support for uv index configuration #32771

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
206 changes: 203 additions & 3 deletions lib/modules/manager/pep621/processors/uv.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,177 @@ describe('modules/manager/pep621/processors/uv', () => {
]);
});

it('pinned to non-default index', () => {
const pyproject = {
tool: {
uv: {
sources: {
dep1: { index: 'foo' },
dep2: { index: 'bar' },
dep3: { non_existent_future_source: {} } as any,
},
index: [
{
name: 'foo',
url: 'https://foo.com/simple',
default: false,
explicit: true,
},
{
name: 'bar',
url: 'https://bar.com/simple',
default: false,
explicit: true,
},
{
name: 'baz',
url: 'https://baz.com/simple',
default: false,
explicit: false,
},
],
},
},
};

const dependencies = [
{
depName: 'dep1',
packageName: 'dep1',
},
{
depName: 'dep2',
packageName: 'dep2',
},
{
depName: 'dep3',
packageName: 'dep3',
},
{
depName: 'dep4',
packageName: 'dep4',
},
];

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

expect(result).toEqual([
{
depName: 'dep1',
depType: depTypes.uvSources,
registryUrls: ['https://foo.com/simple'],
packageName: 'dep1',
},
{
depName: 'dep2',
depType: depTypes.uvSources,
registryUrls: ['https://bar.com/simple'],
packageName: 'dep2',
},
{
depName: 'dep3',
depType: depTypes.uvSources,
packageName: 'dep3',
skipReason: 'unknown-registry',
},
{
depName: 'dep4',
registryUrls: ['https://baz.com/simple', 'https://pypi.org/pypi/'],
packageName: 'dep4',
},
]);
});

it('override implicit default index', () => {
const pyproject = {
tool: {
uv: {
index: [
{
name: 'foo',
url: 'https://foo.com/simple',
default: true,
explicit: false,
},
],
},
},
};

const dependencies = [
{
depName: 'dep1',
packageName: 'dep1',
},
{
depName: 'dep2',
packageName: 'dep2',
},
];

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

expect(result).toEqual([
{
depName: 'dep1',
registryUrls: ['https://foo.com/simple'],
packageName: 'dep1',
},
{
depName: 'dep2',
registryUrls: ['https://foo.com/simple'],
packageName: 'dep2',
},
]);
});

it('override explicit default index', () => {
const pyproject = {
tool: {
uv: {
sources: {
dep1: { index: 'foo' },
},
index: [
{
name: 'foo',
url: 'https://foo.com/simple',
default: true,
explicit: true,
},
],
},
},
};

const dependencies = [
{
depName: 'dep1',
packageName: 'dep1',
},
{
depName: 'dep2',
packageName: 'dep2',
},
];

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

expect(result).toEqual([
{
depName: 'dep1',
depType: depTypes.uvSources,
registryUrls: ['https://foo.com/simple'],
packageName: 'dep1',
},
{
depName: 'dep2',
registryUrls: [],
packageName: 'dep2',
},
]);
});

describe('updateArtifacts()', () => {
it('returns null if there is no lock file', async () => {
fs.getSiblingFileName.mockReturnValueOnce('uv.lock');
Expand Down Expand Up @@ -303,6 +474,11 @@ describe('modules/manager/pep621/processors/uv', () => {
username: 'user',
password: 'pass',
});
hostRules.add({
matchHost: 'https://pinned.com/simple',
username: 'user',
password: 'pass',
});
googleAuth.mockImplementationOnce(
jest.fn().mockImplementationOnce(() => ({
getAccessToken: jest.fn().mockResolvedValue('some-token'),
Expand Down Expand Up @@ -353,6 +529,12 @@ describe('modules/manager/pep621/processors/uv', () => {
'https://someregion-python.pkg.dev/some-project/some-repo/',
],
},
{
packageName: 'dep6',
depType: depTypes.dependencies,
datasource: PypiDatasource.id,
registryUrls: ['https://pinned.com/simple'],
},
];
const result = await processor.updateArtifacts(
{
Expand All @@ -361,7 +543,23 @@ describe('modules/manager/pep621/processors/uv', () => {
config: {},
updatedDeps,
},
{},
{
tool: {
uv: {
sources: {
dep6: { index: 'pinned-index' },
},
index: [
{
name: 'pinned-index',
url: 'https://pinned.com/simple',
default: false,
explicit: true,
},
],
},
},
},
);
expect(result).toEqual([
{
Expand All @@ -374,10 +572,10 @@ describe('modules/manager/pep621/processors/uv', () => {
]);
expect(execSnapshots).toMatchObject([
{
cmd: 'uv lock --upgrade-package dep1 --upgrade-package dep2 --upgrade-package dep3 --upgrade-package dep4 --upgrade-package dep5',
cmd: 'uv lock --upgrade-package dep1 --upgrade-package dep2 --upgrade-package dep3 --upgrade-package dep4 --upgrade-package dep5 --upgrade-package dep6',
options: {
env: {
GIT_CONFIG_COUNT: '3',
GIT_CONFIG_COUNT: '6',
GIT_CONFIG_KEY_0: 'url.https://user:pass@example.com/.insteadOf',
GIT_CONFIG_KEY_1: 'url.https://user:pass@example.com/.insteadOf',
GIT_CONFIG_KEY_2: 'url.https://user:pass@example.com/.insteadOf',
Expand All @@ -386,6 +584,8 @@ describe('modules/manager/pep621/processors/uv', () => {
GIT_CONFIG_VALUE_2: 'https://example.com/',
UV_EXTRA_INDEX_URL:
'https://foobar.com/ https://user:pass@example.com/ https://oauth2accesstoken:some-token@someregion-python.pkg.dev/some-project/some-repo/',
UV_INDEX_PINNED_INDEX_USERNAME: 'user',
UV_INDEX_PINNED_INDEX_PASSWORD: 'pass',
},
},
},
Expand Down
Loading