@vercel/python-analysis 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +202 -0
  2. package/dist/index.d.ts +22 -0
  3. package/dist/index.js +107 -0
  4. package/dist/manifest/package.d.ts +166 -0
  5. package/dist/manifest/package.js +422 -0
  6. package/dist/manifest/pep440.d.ts +6 -0
  7. package/dist/manifest/pep440.js +63 -0
  8. package/dist/manifest/pep508.d.ts +64 -0
  9. package/dist/manifest/pep508.js +70 -0
  10. package/dist/manifest/pipfile/schema.d.ts +40 -0
  11. package/dist/manifest/pipfile/schema.js +44 -0
  12. package/dist/manifest/pipfile/schema.zod.d.ts +606 -0
  13. package/dist/manifest/pipfile/schema.zod.js +97 -0
  14. package/dist/manifest/pipfile/types.d.ts +77 -0
  15. package/dist/manifest/pipfile/types.js +16 -0
  16. package/dist/manifest/pipfile-parser.d.ts +35 -0
  17. package/dist/manifest/pipfile-parser.js +262 -0
  18. package/dist/manifest/pyproject/schema.d.ts +50 -0
  19. package/dist/manifest/pyproject/schema.js +56 -0
  20. package/dist/manifest/pyproject/schema.zod.d.ts +767 -0
  21. package/dist/manifest/pyproject/schema.zod.js +94 -0
  22. package/dist/manifest/pyproject/types.d.ts +93 -0
  23. package/dist/manifest/pyproject/types.js +16 -0
  24. package/dist/manifest/python-selector.d.ts +123 -0
  25. package/dist/manifest/python-selector.js +185 -0
  26. package/dist/manifest/python-specifiers.d.ts +76 -0
  27. package/dist/manifest/python-specifiers.js +156 -0
  28. package/dist/manifest/requirement/schema.d.ts +28 -0
  29. package/dist/manifest/requirement/schema.js +35 -0
  30. package/dist/manifest/requirement/schema.zod.d.ts +76 -0
  31. package/dist/manifest/requirement/schema.zod.js +49 -0
  32. package/dist/manifest/requirement/types.d.ts +50 -0
  33. package/dist/manifest/requirement/types.js +16 -0
  34. package/dist/manifest/requirements-txt-parser.d.ts +55 -0
  35. package/dist/manifest/requirements-txt-parser.js +400 -0
  36. package/dist/manifest/uv-config/schema.d.ts +22 -0
  37. package/dist/manifest/uv-config/schema.js +35 -0
  38. package/dist/manifest/uv-config/schema.zod.d.ts +140 -0
  39. package/dist/manifest/uv-config/schema.zod.js +48 -0
  40. package/dist/manifest/uv-config/types.d.ts +48 -0
  41. package/dist/manifest/uv-config/types.js +16 -0
  42. package/dist/manifest/uv-python-version-parser.d.ts +28 -0
  43. package/dist/manifest/uv-python-version-parser.js +268 -0
  44. package/dist/types.d.ts +17 -0
  45. package/dist/types.js +16 -0
  46. package/dist/util/config.d.ts +20 -0
  47. package/dist/util/config.js +100 -0
  48. package/dist/util/error.d.ts +39 -0
  49. package/dist/util/error.js +54 -0
  50. package/dist/util/fs.d.ts +25 -0
  51. package/dist/util/fs.js +75 -0
  52. package/dist/util/type.d.ts +7 -0
  53. package/dist/util/type.js +30 -0
  54. package/package.json +43 -0
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var schema_zod_exports = {};
20
+ __export(schema_zod_exports, {
21
+ licenseObjectSchema: () => licenseObjectSchema,
22
+ licenseSchema: () => licenseSchema,
23
+ personSchema: () => personSchema,
24
+ pyProjectBuildSystemSchema: () => pyProjectBuildSystemSchema,
25
+ pyProjectDependencyGroupsSchema: () => pyProjectDependencyGroupsSchema,
26
+ pyProjectProjectSchema: () => pyProjectProjectSchema,
27
+ pyProjectTomlSchema: () => pyProjectTomlSchema,
28
+ pyProjectToolSectionSchema: () => pyProjectToolSectionSchema,
29
+ readmeObjectSchema: () => readmeObjectSchema,
30
+ readmeSchema: () => readmeSchema
31
+ });
32
+ module.exports = __toCommonJS(schema_zod_exports);
33
+ var import_zod = require("zod");
34
+ var import_schema = require("./../uv-config/schema.zod");
35
+ const pyProjectBuildSystemSchema = import_zod.z.object({
36
+ requires: import_zod.z.array(import_zod.z.string()),
37
+ "build-backend": import_zod.z.string().optional(),
38
+ "backend-path": import_zod.z.array(import_zod.z.string()).optional()
39
+ });
40
+ const personSchema = import_zod.z.object({
41
+ name: import_zod.z.string().optional(),
42
+ email: import_zod.z.string().optional()
43
+ });
44
+ const readmeObjectSchema = import_zod.z.object({
45
+ file: import_zod.z.union([import_zod.z.string(), import_zod.z.array(import_zod.z.string())]),
46
+ content_type: import_zod.z.string().optional()
47
+ });
48
+ const readmeSchema = import_zod.z.union([import_zod.z.string(), readmeObjectSchema]);
49
+ const licenseObjectSchema = import_zod.z.object({
50
+ text: import_zod.z.string().optional(),
51
+ file: import_zod.z.string().optional()
52
+ });
53
+ const licenseSchema = import_zod.z.union([import_zod.z.string(), licenseObjectSchema]);
54
+ const pyProjectProjectSchema = import_zod.z.object({
55
+ name: import_zod.z.string().optional(),
56
+ version: import_zod.z.string().optional(),
57
+ description: import_zod.z.string().optional(),
58
+ readme: readmeSchema.optional(),
59
+ keywords: import_zod.z.array(import_zod.z.string()).optional(),
60
+ authors: import_zod.z.array(personSchema).optional(),
61
+ maintainers: import_zod.z.array(personSchema).optional(),
62
+ license: licenseSchema.optional(),
63
+ classifiers: import_zod.z.array(import_zod.z.string()).optional(),
64
+ urls: import_zod.z.record(import_zod.z.string()).optional(),
65
+ dependencies: import_zod.z.array(import_zod.z.string()).optional(),
66
+ "optional-dependencies": import_zod.z.record(import_zod.z.array(import_zod.z.string())).optional(),
67
+ dynamic: import_zod.z.array(import_zod.z.string()).optional(),
68
+ "requires-python": import_zod.z.string().optional(),
69
+ scripts: import_zod.z.record(import_zod.z.string()).optional(),
70
+ entry_points: import_zod.z.record(import_zod.z.record(import_zod.z.string())).optional()
71
+ });
72
+ const pyProjectDependencyGroupsSchema = import_zod.z.record(import_zod.z.array(import_zod.z.string()));
73
+ const pyProjectToolSectionSchema = import_zod.z.object({
74
+ uv: import_schema.uvConfigSchema.optional()
75
+ });
76
+ const pyProjectTomlSchema = import_zod.z.object({
77
+ project: pyProjectProjectSchema.optional(),
78
+ "build-system": pyProjectBuildSystemSchema.optional(),
79
+ "dependency-groups": pyProjectDependencyGroupsSchema.optional(),
80
+ tool: pyProjectToolSectionSchema.optional()
81
+ });
82
+ // Annotate the CommonJS export names for ESM import in node:
83
+ 0 && (module.exports = {
84
+ licenseObjectSchema,
85
+ licenseSchema,
86
+ personSchema,
87
+ pyProjectBuildSystemSchema,
88
+ pyProjectDependencyGroupsSchema,
89
+ pyProjectProjectSchema,
90
+ pyProjectTomlSchema,
91
+ pyProjectToolSectionSchema,
92
+ readmeObjectSchema,
93
+ readmeSchema
94
+ });
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Pure TypeScript interface definitions for pyproject.toml types.
3
+ *
4
+ * These interfaces serve as the source of truth for types.
5
+ * Zod schemas are generated from these using ts-to-zod.
6
+ *
7
+ * @module pyproject/types
8
+ */
9
+ import type { UvConfig } from '../uv-config/types';
10
+ /**
11
+ * [build-system] per PEP 518.
12
+ * @passthrough
13
+ */
14
+ export interface PyProjectBuildSystem {
15
+ requires: string[];
16
+ 'build-backend'?: string;
17
+ 'backend-path'?: string[];
18
+ }
19
+ /**
20
+ * Author/maintainer entry.
21
+ * @passthrough
22
+ */
23
+ export interface Person {
24
+ name?: string;
25
+ email?: string;
26
+ }
27
+ /**
28
+ * Readme field as an object.
29
+ * @passthrough
30
+ */
31
+ export interface ReadmeObject {
32
+ file: string | string[];
33
+ content_type?: string;
34
+ }
35
+ /**
36
+ * Readme field (can be string or object).
37
+ */
38
+ export type Readme = string | ReadmeObject;
39
+ /**
40
+ * License field as an object.
41
+ * @passthrough
42
+ */
43
+ export interface LicenseObject {
44
+ text?: string;
45
+ file?: string;
46
+ }
47
+ /**
48
+ * License field (can be string or object).
49
+ */
50
+ export type License = string | LicenseObject;
51
+ /**
52
+ * Core PEP 621 fields for [project].
53
+ * @passthrough
54
+ */
55
+ export interface PyProjectProject {
56
+ name?: string;
57
+ version?: string;
58
+ description?: string;
59
+ readme?: Readme;
60
+ keywords?: string[];
61
+ authors?: Person[];
62
+ maintainers?: Person[];
63
+ license?: License;
64
+ classifiers?: string[];
65
+ urls?: Record<string, string>;
66
+ dependencies?: string[];
67
+ 'optional-dependencies'?: Record<string, string[]>;
68
+ dynamic?: string[];
69
+ 'requires-python'?: string;
70
+ scripts?: Record<string, string>;
71
+ entry_points?: Record<string, Record<string, string>>;
72
+ }
73
+ /**
74
+ * [dependency-groups].
75
+ */
76
+ export type PyProjectDependencyGroups = Record<string, string[]>;
77
+ /**
78
+ * [tool.FOO] section.
79
+ * @passthrough
80
+ */
81
+ export interface PyProjectToolSection {
82
+ uv?: UvConfig;
83
+ }
84
+ /**
85
+ * A pyproject.toml file.
86
+ * @passthrough
87
+ */
88
+ export interface PyProjectToml {
89
+ project?: PyProjectProject;
90
+ 'build-system'?: PyProjectBuildSystem;
91
+ 'dependency-groups'?: PyProjectDependencyGroups;
92
+ tool?: PyProjectToolSection;
93
+ }
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+ var types_exports = {};
16
+ module.exports = __toCommonJS(types_exports);
@@ -0,0 +1,123 @@
1
+ import type { Pep440Constraint } from './pep440';
2
+ import type { PythonBuild, PythonConstraint, PythonRequest, PythonVariant, PythonVersion } from './python-specifiers';
3
+ import { PythonImplementation } from './python-specifiers';
4
+ /**
5
+ * Result of selecting a Python build.
6
+ */
7
+ export interface PythonSelectionResult {
8
+ /** The selected build, or null if no build matches. */
9
+ build: PythonBuild | null;
10
+ /** Error messages if selection failed. */
11
+ errors?: string[];
12
+ /** Warning messages (e.g., non-overlapping constraints). */
13
+ warnings?: string[];
14
+ }
15
+ /**
16
+ * Select the best Python build that matches all constraints.
17
+ *
18
+ * @param constraints - Array of Python constraints from various sources
19
+ * @param available - Array of available Python builds to choose from
20
+ * @returns The first matching build, or null with errors/warnings if none match
21
+ */
22
+ export declare function selectPython(constraints: PythonConstraint[], available: PythonBuild[]): PythonSelectionResult;
23
+ /**
24
+ * Convert a PythonVersion to a string suitable for PEP 440 comparison.
25
+ *
26
+ * @param version - The Python version object to convert
27
+ * @returns A version string like "3.12", "3.12.1", or "3.13.0a1"
28
+ *
29
+ * @example
30
+ * pythonVersionToString({ major: 3, minor: 12 }) // "3.12"
31
+ * pythonVersionToString({ major: 3, minor: 12, patch: 1 }) // "3.12.1"
32
+ * pythonVersionToString({ major: 3, minor: 13, patch: 0, prerelease: "a1" }) // "3.13.0a1"
33
+ */
34
+ export declare function pythonVersionToString(version: PythonVersion): string;
35
+ /**
36
+ * Convert an array of Pep440Constraint to a specifier string.
37
+ *
38
+ * @param constraints - Array of PEP 440 version constraints
39
+ * @returns A comma-separated specifier string like ">=3.12,<3.14"
40
+ *
41
+ * @example
42
+ * pep440ConstraintsToString([{ operator: '>=', version: '3.12', prefix: '' }]) // ">=3.12"
43
+ * pep440ConstraintsToString([
44
+ * { operator: '>=', version: '3.12', prefix: '' },
45
+ * { operator: '<', version: '3.14', prefix: '' }
46
+ * ]) // ">=3.12,<3.14"
47
+ */
48
+ export declare function pep440ConstraintsToString(constraints: Pep440Constraint[]): string;
49
+ /**
50
+ * Check if two PythonImplementation values are equal.
51
+ *
52
+ * Handles both known implementations (cpython, pypy, etc.) and unknown
53
+ * implementations (custom strings). Known implementations are compared
54
+ * by identity, unknown implementations by their string value.
55
+ *
56
+ * @param buildImpl - The implementation of the available build
57
+ * @param requestImpl - The implementation requested by the constraint
58
+ * @returns True if the implementations match
59
+ *
60
+ * @example
61
+ * implementationsMatch('cpython', 'cpython') // true
62
+ * implementationsMatch('cpython', 'pypy') // false
63
+ * implementationsMatch({ implementation: 'custom' }, { implementation: 'custom' }) // true
64
+ */
65
+ export declare function implementationsMatch(buildImpl: PythonImplementation, requestImpl: PythonImplementation): boolean;
66
+ /**
67
+ * Check if two PythonVariant values are equal.
68
+ *
69
+ * Handles both known variants (default, debug, freethreaded, etc.) and
70
+ * unknown variants. Known variants are compared by identity, unknown
71
+ * variants by their string value.
72
+ *
73
+ * @param buildVariant - The variant of the available build
74
+ * @param requestVariant - The variant requested by the constraint
75
+ * @returns True if the variants match
76
+ *
77
+ * @example
78
+ * variantsMatch('default', 'default') // true
79
+ * variantsMatch('freethreaded', 'debug') // false
80
+ * variantsMatch({ type: 'unknown', variant: 'custom' }, { type: 'unknown', variant: 'custom' }) // true
81
+ */
82
+ export declare function variantsMatch(buildVariant: PythonVariant, requestVariant: PythonVariant): boolean;
83
+ /**
84
+ * Check if a build matches a single PythonRequest.
85
+ *
86
+ * A build matches a request if all specified fields in the request match
87
+ * the corresponding fields in the build. Unspecified fields in the request
88
+ * are treated as wildcards (match anything).
89
+ *
90
+ * @param build - The available Python build to check
91
+ * @param request - The Python request specifying desired properties
92
+ * @returns True if the build satisfies all specified requirements in the request
93
+ *
94
+ * @example
95
+ * // Request with only version constraint
96
+ * buildMatchesRequest(build, { version: { constraint: [{ operator: '>=', version: '3.12', prefix: '' }] } })
97
+ *
98
+ * // Request with implementation and platform
99
+ * buildMatchesRequest(build, { implementation: 'cpython', platform: { os: 'linux' } })
100
+ */
101
+ export declare function buildMatchesRequest(build: PythonBuild, request: PythonRequest): boolean;
102
+ /**
103
+ * Check if a build matches a PythonConstraint.
104
+ *
105
+ * A constraint contains one or more requests combined with OR logic.
106
+ * The constraint is satisfied if the build matches at least one of its requests.
107
+ * An empty request array is treated as "match anything".
108
+ *
109
+ * @param build - The available Python build to check
110
+ * @param constraint - The constraint containing one or more requests
111
+ * @returns True if the build matches at least one request in the constraint
112
+ *
113
+ * @example
114
+ * // Constraint with multiple alternative requests (OR logic)
115
+ * buildMatchesConstraint(build, {
116
+ * request: [
117
+ * { implementation: 'cpython', version: { constraint: [...] } },
118
+ * { implementation: 'pypy', version: { constraint: [...] } }
119
+ * ],
120
+ * source: '.python-version'
121
+ * })
122
+ */
123
+ export declare function buildMatchesConstraint(build: PythonBuild, constraint: PythonConstraint): boolean;
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var python_selector_exports = {};
20
+ __export(python_selector_exports, {
21
+ buildMatchesConstraint: () => buildMatchesConstraint,
22
+ buildMatchesRequest: () => buildMatchesRequest,
23
+ implementationsMatch: () => implementationsMatch,
24
+ pep440ConstraintsToString: () => pep440ConstraintsToString,
25
+ pythonVersionToString: () => pythonVersionToString,
26
+ selectPython: () => selectPython,
27
+ variantsMatch: () => variantsMatch
28
+ });
29
+ module.exports = __toCommonJS(python_selector_exports);
30
+ var import_pep440 = require("./pep440");
31
+ var import_python_specifiers = require("./python-specifiers");
32
+ function selectPython(constraints, available) {
33
+ const warnings = [];
34
+ const errors = [];
35
+ if (constraints.length === 0) {
36
+ return {
37
+ build: available.length > 0 ? available[0] : null,
38
+ errors: available.length === 0 ? ["No Python builds available"] : void 0
39
+ };
40
+ }
41
+ const constraintMatches = /* @__PURE__ */ new Map();
42
+ for (let i = 0; i < constraints.length; i++) {
43
+ constraintMatches.set(i, []);
44
+ }
45
+ for (const build of available) {
46
+ let matchesAll = true;
47
+ for (let i = 0; i < constraints.length; i++) {
48
+ const constraint = constraints[i];
49
+ if (buildMatchesConstraint(build, constraint)) {
50
+ constraintMatches.get(i)?.push(build);
51
+ } else {
52
+ matchesAll = false;
53
+ }
54
+ }
55
+ if (matchesAll) {
56
+ return {
57
+ build,
58
+ warnings: warnings.length > 0 ? warnings : void 0
59
+ };
60
+ }
61
+ }
62
+ if (constraints.length > 1) {
63
+ const constraintsWithMatches = [];
64
+ for (let i = 0; i < constraints.length; i++) {
65
+ const matches = constraintMatches.get(i) ?? [];
66
+ if (matches.length > 0) {
67
+ constraintsWithMatches.push(i);
68
+ }
69
+ }
70
+ if (constraintsWithMatches.length > 1) {
71
+ const sources = constraintsWithMatches.map((i) => constraints[i].source);
72
+ warnings.push(
73
+ `Python version constraints may not overlap: ${sources.join(", ")}`
74
+ );
75
+ }
76
+ }
77
+ const constraintDescriptions = constraints.map((c) => c.source).join(", ");
78
+ errors.push(
79
+ `No Python build satisfies all constraints: ${constraintDescriptions}`
80
+ );
81
+ return {
82
+ build: null,
83
+ errors,
84
+ warnings: warnings.length > 0 ? warnings : void 0
85
+ };
86
+ }
87
+ function pythonVersionToString(version) {
88
+ let str = `${version.major}.${version.minor}`;
89
+ if (version.patch !== void 0) {
90
+ str += `.${version.patch}`;
91
+ }
92
+ if (version.prerelease) {
93
+ str += version.prerelease;
94
+ }
95
+ return str;
96
+ }
97
+ function pep440ConstraintsToString(constraints) {
98
+ return constraints.map((c) => `${c.operator}${c.prefix}${c.version}`).join(",");
99
+ }
100
+ function implementationsMatch(buildImpl, requestImpl) {
101
+ if (import_python_specifiers.PythonImplementation.isUnknown(buildImpl)) {
102
+ if (import_python_specifiers.PythonImplementation.isUnknown(requestImpl)) {
103
+ return buildImpl.implementation === requestImpl.implementation;
104
+ }
105
+ return false;
106
+ }
107
+ if (import_python_specifiers.PythonImplementation.isUnknown(requestImpl)) {
108
+ return false;
109
+ }
110
+ return buildImpl === requestImpl;
111
+ }
112
+ function variantsMatch(buildVariant, requestVariant) {
113
+ if (typeof buildVariant === "object" && "type" in buildVariant) {
114
+ if (typeof requestVariant === "object" && "type" in requestVariant) {
115
+ return buildVariant.variant === requestVariant.variant;
116
+ }
117
+ return false;
118
+ }
119
+ if (typeof requestVariant === "object" && "type" in requestVariant) {
120
+ return false;
121
+ }
122
+ return buildVariant === requestVariant;
123
+ }
124
+ function buildMatchesRequest(build, request) {
125
+ if (request.implementation !== void 0) {
126
+ if (!implementationsMatch(build.implementation, request.implementation)) {
127
+ return false;
128
+ }
129
+ }
130
+ if (request.version !== void 0) {
131
+ const versionConstraints = request.version.constraint;
132
+ if (versionConstraints.length > 0) {
133
+ const buildVersionStr = pythonVersionToString(build.version);
134
+ const specifier = pep440ConstraintsToString(versionConstraints);
135
+ if (!(0, import_pep440.pep440Satisfies)(buildVersionStr, specifier)) {
136
+ return false;
137
+ }
138
+ }
139
+ if (request.version.variant !== void 0) {
140
+ if (!variantsMatch(build.variant, request.version.variant)) {
141
+ return false;
142
+ }
143
+ }
144
+ }
145
+ if (request.platform !== void 0) {
146
+ const platform = request.platform;
147
+ if (platform.os !== void 0) {
148
+ if (build.os.toLowerCase() !== platform.os.toLowerCase()) {
149
+ return false;
150
+ }
151
+ }
152
+ if (platform.arch !== void 0) {
153
+ if (build.architecture.toLowerCase() !== platform.arch.toLowerCase()) {
154
+ return false;
155
+ }
156
+ }
157
+ if (platform.libc !== void 0) {
158
+ if (build.libc.toLowerCase() !== platform.libc.toLowerCase()) {
159
+ return false;
160
+ }
161
+ }
162
+ }
163
+ return true;
164
+ }
165
+ function buildMatchesConstraint(build, constraint) {
166
+ if (constraint.request.length === 0) {
167
+ return true;
168
+ }
169
+ for (const request of constraint.request) {
170
+ if (buildMatchesRequest(build, request)) {
171
+ return true;
172
+ }
173
+ }
174
+ return false;
175
+ }
176
+ // Annotate the CommonJS export names for ESM import in node:
177
+ 0 && (module.exports = {
178
+ buildMatchesConstraint,
179
+ buildMatchesRequest,
180
+ implementationsMatch,
181
+ pep440ConstraintsToString,
182
+ pythonVersionToString,
183
+ selectPython,
184
+ variantsMatch
185
+ });
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Python specifier types for version, implementation, variant, and build information.
3
+ *
4
+ * These types are used internally for Python version selection and are not
5
+ * parsed from config files (no Zod schemas needed).
6
+ *
7
+ * @module python-specifiers
8
+ */
9
+ import type { Pep440Constraint } from '@renovatebot/pep440';
10
+ export type UnknownPythonImplementation = {
11
+ implementation: string;
12
+ };
13
+ export type PythonImplementation = 'cpython' | 'pypy' | 'pyodide' | 'graalpy' | UnknownPythonImplementation;
14
+ export declare const PythonImplementation: {
15
+ knownLongNames(): Record<string, PythonImplementation>;
16
+ knownShortNames(): Record<string, PythonImplementation>;
17
+ knownNames(): Record<string, PythonImplementation>;
18
+ parse(s: string): PythonImplementation;
19
+ isUnknown(impl: PythonImplementation): impl is UnknownPythonImplementation;
20
+ toString(impl: PythonImplementation): string;
21
+ toStringPretty(impl: PythonImplementation): string;
22
+ };
23
+ export type PythonVariant = 'default' | 'debug' | 'freethreaded' | 'gil' | 'freethreaded+debug' | 'gil+debug' | {
24
+ type: 'unknown';
25
+ variant: string;
26
+ };
27
+ export declare const PythonVariant: {
28
+ parse(s: string): PythonVariant;
29
+ toString(v: PythonVariant): string;
30
+ };
31
+ export interface PythonRequest {
32
+ implementation?: PythonImplementation;
33
+ version?: PythonVersionRequest;
34
+ platform?: PythonPlatformRequest;
35
+ }
36
+ export interface PythonPlatformRequest {
37
+ os?: string;
38
+ arch?: string;
39
+ libc?: string;
40
+ }
41
+ export interface PythonVersionRequest {
42
+ constraint: Pep440Constraint[];
43
+ variant?: PythonVariant;
44
+ }
45
+ /**
46
+ * A Python version constraint with its source.
47
+ *
48
+ * Represents a requirement for a specific Python version range,
49
+ * along with information about where the constraint originated.
50
+ */
51
+ export interface PythonConstraint {
52
+ /** The Python version request(s) that define this constraint. */
53
+ request: PythonRequest[];
54
+ /** Human-readable description of where this constraint came from. */
55
+ source: string;
56
+ }
57
+ export type PythonVersion = {
58
+ major: number;
59
+ minor: number;
60
+ patch?: number;
61
+ prerelease?: string;
62
+ };
63
+ export declare const PythonVersion: {
64
+ toString(version: PythonVersion): string;
65
+ };
66
+ export type PythonBuild = {
67
+ version: PythonVersion;
68
+ implementation: PythonImplementation;
69
+ variant: PythonVariant;
70
+ os: string;
71
+ architecture: string;
72
+ libc: string;
73
+ };
74
+ export declare const PythonBuild: {
75
+ toString(build: PythonBuild): string;
76
+ };