0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/modules/manager/pep723/schema.ts
Mathieu Kniewallner dcaf51c9f7
feat(manager): add inline script metadata (PEP 723) support (#31266)
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2024-09-30 12:33:07 +00:00

30 lines
876 B
TypeScript

import is from '@sindresorhus/is';
import { z } from 'zod';
import { Toml } from '../../../util/schema-utils';
import { depTypes, pep508ToPackageDependency } from '../pep621/utils';
import type { PackageFileContent } from '../types';
const Pep723Dep = z
.string()
.transform((dep) => pep508ToPackageDependency(depTypes.dependencies, dep));
export const Pep723Schema = Toml.pipe(
z
.object({
'requires-python': z.string().optional(),
dependencies: z
.array(Pep723Dep)
.transform((deps) => deps.filter((dep) => !!dep))
.optional(),
})
.transform(({ 'requires-python': requiresPython, dependencies }) => {
const res: PackageFileContent = { deps: dependencies ?? [] };
if (is.nonEmptyString(requiresPython)) {
res.extractedConstraints = { python: requiresPython };
}
return res;
}),
);