Skip to content

Commit 2e9e479

Browse files
jonashaagviceice
andauthored
fix(manager/pixi): support optional channel options (#45273)
* fix(manager/pixi): support optional channel options * Review feedback Co-authored-by: Michael Kriese <michael.kriese@gmx.de> * fix(pixi): import number coercion utility --------- Co-authored-by: Michael Kriese <michael.kriese@gmx.de>
1 parent ff76622 commit 2e9e479

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

lib/modules/manager/pixi/extract.spec.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { codeBlock } from 'common-tags';
22
import { describe, expect, it, vi } from 'vitest';
33
import { fs } from '~test/util.ts';
4+
import { getUserPixiConfig } from './extract.ts';
45
import { extractPackageFile } from './index.ts';
56

67
vi.mock('../../../util/fs/index.ts');
@@ -631,7 +632,7 @@ describe('modules/manager/pixi/extract', () => {
631632
});
632633
});
633634

634-
it(`extract package with channel priority`, async () => {
635+
it(`extract package with channel options`, async () => {
635636
const result = await extractPackageFile(
636637
codeBlock`
637638
[project]
@@ -642,7 +643,12 @@ describe('modules/manager/pixi/extract', () => {
642643
version = "0.1.0"
643644
644645
[feature.scipy]
645-
channels = ["anaconda", {channel = 'cuda', priority = 1}, {channel = 'cuda2', priority = 1}]
646+
channels = [
647+
"anaconda",
648+
{ channel = "community", exclude-newer = "7d" },
649+
{ channel = "cuda", priority = 1 },
650+
{ channel = "cuda2", priority = 1 },
651+
]
646652
dependencies = { scipy = "==1.15.1" }
647653
648654
[feature.numpy]
@@ -661,6 +667,7 @@ describe('modules/manager/pixi/extract', () => {
661667
'https://api.anaconda.org/package/cuda/',
662668
'https://api.anaconda.org/package/cuda2/',
663669
'https://api.anaconda.org/package/anaconda/',
670+
'https://api.anaconda.org/package/community/',
664671
'https://api.anaconda.org/package/conda-forge/',
665672
'https://api.anaconda.org/package/conda-not-forge/',
666673
],
@@ -682,6 +689,24 @@ describe('modules/manager/pixi/extract', () => {
682689
});
683690
});
684691

692+
it('parses optional channel configuration', () => {
693+
expect(
694+
getUserPixiConfig(
695+
codeBlock`
696+
[project]
697+
channels = [
698+
{ channel = "conda-forge", exclude-newer = "7d" },
699+
{ channel = "cuda", priority = 1 },
700+
]
701+
`,
702+
'pixi.toml',
703+
)?.project.channels,
704+
).toEqual([
705+
{ channel: 'conda-forge', 'exclude-newer': '7d' },
706+
{ channel: 'cuda', priority: 1 },
707+
]);
708+
});
709+
685710
it('returns null for non-known config file', async () => {
686711
await expect(extractPackageFile(`{}`, 'unexpected.json')).resolves.toBe(
687712
null,

lib/modules/manager/pixi/extract.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { z } from 'zod/v4';
44
import { logger } from '../../../logger/index.ts';
55
import { coerceArray } from '../../../util/array.ts';
66
import { getSiblingFileName, localPathExists } from '../../../util/fs/index.ts';
7+
import { coerceNumber } from '../../../util/number.ts';
78
import { Result } from '../../../util/result.ts';
89
import {
910
ensureTrailingSlash,
@@ -163,7 +164,7 @@ function orderChannels(channels: Channels = []): string[] {
163164
return { channel, priority: 0, index };
164165
}
165166

166-
return { ...channel, index: 0 };
167+
return { ...channel, priority: coerceNumber(channel.priority), index };
167168
})
168169
.toSorted((a, b) => {
169170
// first based on priority then based on index

lib/modules/manager/pixi/schema.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ export type Channels = z.infer<typeof Channel>[];
1414

1515
const Channel = z.union([
1616
z.string(),
17-
z.object({ channel: z.string(), priority: z.number() }),
17+
z.object({
18+
channel: z.string(),
19+
priority: z.number().optional(),
20+
'exclude-newer': z.string().optional(),
21+
}),
1822
]);
1923

2024
export interface PixiPackageDependency extends PackageDependency {

0 commit comments

Comments
 (0)