@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,156 @@
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_specifiers_exports = {};
20
+ __export(python_specifiers_exports, {
21
+ PythonBuild: () => PythonBuild,
22
+ PythonImplementation: () => PythonImplementation,
23
+ PythonVariant: () => PythonVariant,
24
+ PythonVersion: () => PythonVersion
25
+ });
26
+ module.exports = __toCommonJS(python_specifiers_exports);
27
+ const PythonImplementation = {
28
+ knownLongNames() {
29
+ return {
30
+ python: "cpython",
31
+ cpython: "cpython",
32
+ pypy: "pypy",
33
+ pyodide: "pyodide",
34
+ graalpy: "graalpy"
35
+ };
36
+ },
37
+ knownShortNames() {
38
+ return { cp: "cpython", pp: "pypy", gp: "graalpy" };
39
+ },
40
+ knownNames() {
41
+ return { ...this.knownLongNames(), ...this.knownShortNames() };
42
+ },
43
+ parse(s) {
44
+ const impl = this.knownNames()[s];
45
+ if (impl !== void 0) {
46
+ return impl;
47
+ } else {
48
+ return { implementation: s };
49
+ }
50
+ },
51
+ isUnknown(impl) {
52
+ return impl.implementation !== void 0;
53
+ },
54
+ toString(impl) {
55
+ switch (impl) {
56
+ case "cpython":
57
+ return "cpython";
58
+ case "pypy":
59
+ return "pypy";
60
+ case "pyodide":
61
+ return "pyodide";
62
+ case "graalpy":
63
+ return "graalpy";
64
+ default:
65
+ return impl.implementation;
66
+ }
67
+ },
68
+ toStringPretty(impl) {
69
+ switch (impl) {
70
+ case "cpython":
71
+ return "CPython";
72
+ case "pypy":
73
+ return "PyPy";
74
+ case "pyodide":
75
+ return "PyOdide";
76
+ case "graalpy":
77
+ return "GraalPy";
78
+ default:
79
+ return impl.implementation;
80
+ }
81
+ }
82
+ };
83
+ const PythonVariant = {
84
+ parse(s) {
85
+ switch (s) {
86
+ case "default":
87
+ return "default";
88
+ case "d":
89
+ case "debug":
90
+ return "debug";
91
+ case "freethreaded":
92
+ return "freethreaded";
93
+ case "t":
94
+ return "freethreaded";
95
+ case "gil":
96
+ return "gil";
97
+ case "freethreaded+debug":
98
+ return "freethreaded+debug";
99
+ case "td":
100
+ return "freethreaded+debug";
101
+ case "gil+debug":
102
+ return "gil+debug";
103
+ default:
104
+ return { type: "unknown", variant: s };
105
+ }
106
+ },
107
+ toString(v) {
108
+ switch (v) {
109
+ case "default":
110
+ return "default";
111
+ case "debug":
112
+ return "debug";
113
+ case "freethreaded":
114
+ return "freethreaded";
115
+ case "gil":
116
+ return "gil";
117
+ case "freethreaded+debug":
118
+ return "freethreaded+debug";
119
+ case "gil+debug":
120
+ return "gil+debug";
121
+ default:
122
+ return v.variant;
123
+ }
124
+ }
125
+ };
126
+ const PythonVersion = {
127
+ toString(version) {
128
+ let verstr = `${version.major}.${version.minor}`;
129
+ if (version.patch !== void 0) {
130
+ verstr = `${verstr}.${version.patch}`;
131
+ }
132
+ if (version.prerelease !== void 0) {
133
+ verstr = `${verstr}${version.prerelease}`;
134
+ }
135
+ return verstr;
136
+ }
137
+ };
138
+ const PythonBuild = {
139
+ toString(build) {
140
+ const parts = [
141
+ PythonImplementation.toString(build.implementation),
142
+ `${PythonVersion.toString(build.version)}+${PythonVariant.toString(build.variant)}`,
143
+ build.os,
144
+ build.architecture,
145
+ build.libc
146
+ ];
147
+ return parts.join("-");
148
+ }
149
+ };
150
+ // Annotate the CommonJS export names for ESM import in node:
151
+ 0 && (module.exports = {
152
+ PythonBuild,
153
+ PythonImplementation,
154
+ PythonVariant,
155
+ PythonVersion
156
+ });
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Zod schemas for Python dependency requirement types.
3
+ *
4
+ * Types are defined in types.ts (source of truth).
5
+ * Schemas are generated by ts-to-zod and re-exported here with proper typing.
6
+ *
7
+ * @module requirement/schema
8
+ */
9
+ import type { z } from 'zod';
10
+ import type { DependencySource, NormalizedRequirement } from './types';
11
+ /**
12
+ * Schema for dependency source information (git, path, or index).
13
+ * Used in [tool.uv.sources] in pyproject.toml.
14
+ */
15
+ export declare const DependencySourceSchema: z.ZodType<DependencySource, z.ZodTypeDef, DependencySource>;
16
+ /**
17
+ * Schema for a normalized representation of a Python dependency.
18
+ * This is the common format used by all parsers before converting to PEP 508 format.
19
+ *
20
+ * Note: This schema uses the generated version without passthrough since
21
+ * NormalizedRequirement is an internal type with a known structure.
22
+ */
23
+ export declare const NormalizedRequirementSchema: z.ZodType<NormalizedRequirement, z.ZodTypeDef, NormalizedRequirement>;
24
+ /**
25
+ * Schema for parsed hash digest for a requirement.
26
+ * Format: algorithm:hash_value (e.g., "sha256:abc123...")
27
+ */
28
+ export declare const HashDigestSchema: z.ZodType<string, z.ZodTypeDef, string>;
@@ -0,0 +1,35 @@
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_exports = {};
20
+ __export(schema_exports, {
21
+ DependencySourceSchema: () => DependencySourceSchema,
22
+ HashDigestSchema: () => HashDigestSchema,
23
+ NormalizedRequirementSchema: () => NormalizedRequirementSchema
24
+ });
25
+ module.exports = __toCommonJS(schema_exports);
26
+ var import_schema = require("./schema.zod");
27
+ const DependencySourceSchema = import_schema.dependencySourceSchema.passthrough();
28
+ const NormalizedRequirementSchema = import_schema.normalizedRequirementSchema;
29
+ const HashDigestSchema = import_schema.hashDigestSchema;
30
+ // Annotate the CommonJS export names for ESM import in node:
31
+ 0 && (module.exports = {
32
+ DependencySourceSchema,
33
+ HashDigestSchema,
34
+ NormalizedRequirementSchema
35
+ });
@@ -0,0 +1,76 @@
1
+ import { z } from 'zod';
2
+ export declare const dependencySourceSchema: z.ZodObject<{
3
+ index: z.ZodOptional<z.ZodString>;
4
+ git: z.ZodOptional<z.ZodString>;
5
+ rev: z.ZodOptional<z.ZodString>;
6
+ path: z.ZodOptional<z.ZodString>;
7
+ editable: z.ZodOptional<z.ZodBoolean>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ index?: string | undefined;
10
+ git?: string | undefined;
11
+ rev?: string | undefined;
12
+ path?: string | undefined;
13
+ editable?: boolean | undefined;
14
+ }, {
15
+ index?: string | undefined;
16
+ git?: string | undefined;
17
+ rev?: string | undefined;
18
+ path?: string | undefined;
19
+ editable?: boolean | undefined;
20
+ }>;
21
+ export declare const normalizedRequirementSchema: z.ZodObject<{
22
+ name: z.ZodString;
23
+ version: z.ZodOptional<z.ZodString>;
24
+ extras: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
25
+ markers: z.ZodOptional<z.ZodString>;
26
+ url: z.ZodOptional<z.ZodString>;
27
+ hashes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
28
+ source: z.ZodOptional<z.ZodObject<{
29
+ index: z.ZodOptional<z.ZodString>;
30
+ git: z.ZodOptional<z.ZodString>;
31
+ rev: z.ZodOptional<z.ZodString>;
32
+ path: z.ZodOptional<z.ZodString>;
33
+ editable: z.ZodOptional<z.ZodBoolean>;
34
+ }, "strip", z.ZodTypeAny, {
35
+ index?: string | undefined;
36
+ git?: string | undefined;
37
+ rev?: string | undefined;
38
+ path?: string | undefined;
39
+ editable?: boolean | undefined;
40
+ }, {
41
+ index?: string | undefined;
42
+ git?: string | undefined;
43
+ rev?: string | undefined;
44
+ path?: string | undefined;
45
+ editable?: boolean | undefined;
46
+ }>>;
47
+ }, "strip", z.ZodTypeAny, {
48
+ name: string;
49
+ version?: string | undefined;
50
+ extras?: string[] | undefined;
51
+ markers?: string | undefined;
52
+ url?: string | undefined;
53
+ hashes?: string[] | undefined;
54
+ source?: {
55
+ index?: string | undefined;
56
+ git?: string | undefined;
57
+ rev?: string | undefined;
58
+ path?: string | undefined;
59
+ editable?: boolean | undefined;
60
+ } | undefined;
61
+ }, {
62
+ name: string;
63
+ version?: string | undefined;
64
+ extras?: string[] | undefined;
65
+ markers?: string | undefined;
66
+ url?: string | undefined;
67
+ hashes?: string[] | undefined;
68
+ source?: {
69
+ index?: string | undefined;
70
+ git?: string | undefined;
71
+ rev?: string | undefined;
72
+ path?: string | undefined;
73
+ editable?: boolean | undefined;
74
+ } | undefined;
75
+ }>;
76
+ export declare const hashDigestSchema: z.ZodString;
@@ -0,0 +1,49 @@
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
+ dependencySourceSchema: () => dependencySourceSchema,
22
+ hashDigestSchema: () => hashDigestSchema,
23
+ normalizedRequirementSchema: () => normalizedRequirementSchema
24
+ });
25
+ module.exports = __toCommonJS(schema_zod_exports);
26
+ var import_zod = require("zod");
27
+ const dependencySourceSchema = import_zod.z.object({
28
+ index: import_zod.z.string().optional(),
29
+ git: import_zod.z.string().optional(),
30
+ rev: import_zod.z.string().optional(),
31
+ path: import_zod.z.string().optional(),
32
+ editable: import_zod.z.boolean().optional()
33
+ });
34
+ const normalizedRequirementSchema = import_zod.z.object({
35
+ name: import_zod.z.string(),
36
+ version: import_zod.z.string().optional(),
37
+ extras: import_zod.z.array(import_zod.z.string()).optional(),
38
+ markers: import_zod.z.string().optional(),
39
+ url: import_zod.z.string().optional(),
40
+ hashes: import_zod.z.array(import_zod.z.string()).optional(),
41
+ source: dependencySourceSchema.optional()
42
+ });
43
+ const hashDigestSchema = import_zod.z.string();
44
+ // Annotate the CommonJS export names for ESM import in node:
45
+ 0 && (module.exports = {
46
+ dependencySourceSchema,
47
+ hashDigestSchema,
48
+ normalizedRequirementSchema
49
+ });
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Pure TypeScript interface definitions for Python dependency requirement 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 requirement/types
8
+ */
9
+ /**
10
+ * Dependency source information (git, path, or index).
11
+ * Used in [tool.uv.sources] in pyproject.toml.
12
+ * @passthrough
13
+ */
14
+ export interface DependencySource {
15
+ /** Index name for the dependency (e.g., "private-pypi") */
16
+ index?: string;
17
+ /** Git repository URL */
18
+ git?: string;
19
+ /** Git revision (branch, tag, or commit hash) */
20
+ rev?: string;
21
+ /** Local path to the dependency */
22
+ path?: string;
23
+ /** Whether the dependency is installed in editable mode */
24
+ editable?: boolean;
25
+ }
26
+ /**
27
+ * A normalized representation of a Python dependency.
28
+ * This is the common format used by all parsers before converting to PEP 508 format.
29
+ */
30
+ export interface NormalizedRequirement {
31
+ /** Package name (e.g., "requests") */
32
+ name: string;
33
+ /** Version specifier (e.g., ">=1.0,<2.0") */
34
+ version?: string;
35
+ /** Extra features (e.g., ["security", "socks"]) */
36
+ extras?: string[];
37
+ /** Environment markers (e.g., "python_version >= '3.8'") */
38
+ markers?: string;
39
+ /** Direct URL for the package */
40
+ url?: string;
41
+ /** Hash digests for verification (e.g., ["sha256:abc123..."]) */
42
+ hashes?: string[];
43
+ /** Source information for uv (git, path, or index) */
44
+ source?: DependencySource;
45
+ }
46
+ /**
47
+ * Parsed hash digest for a requirement.
48
+ * Format: algorithm:hash_value (e.g., "sha256:abc123...")
49
+ */
50
+ export type HashDigest = string;
@@ -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,55 @@
1
+ import type { PyProjectToml } from './pyproject/types';
2
+ import type { NormalizedRequirement } from './requirement/types';
3
+ /**
4
+ * Parsed pip arguments from requirements file.
5
+ */
6
+ export interface PipOptions {
7
+ /** Files referenced via -r or --requirement */
8
+ requirementFiles: string[];
9
+ /** Files referenced via -c or --constraint */
10
+ constraintFiles: string[];
11
+ /** Primary index URL (--index-url or -i) - only the last one is kept */
12
+ indexUrl?: string;
13
+ /** Extra index URLs (--extra-index-url) */
14
+ extraIndexUrls: string[];
15
+ }
16
+ /**
17
+ * Result of parsing a requirements file with pip options.
18
+ */
19
+ export interface ParsedRequirementsFile {
20
+ requirements: NormalizedRequirement[];
21
+ pipOptions: PipOptions;
22
+ }
23
+ /**
24
+ * Function type for reading referenced requirement files.
25
+ */
26
+ export type ReadFileFn = (path: string) => string | null;
27
+ /**
28
+ * Convert a requirements.txt content to a pyproject.toml object suitable for uv.
29
+ *
30
+ * This creates a minimal pyproject:
31
+ *
32
+ * [project]
33
+ * dependencies = [...]
34
+ *
35
+ * [tool.uv.sources]
36
+ * package = { git = "..." }
37
+ *
38
+ * Note: Hash information is not included in pyproject.toml output.
39
+ *
40
+ * @param fileContent - The content of the requirements.txt file
41
+ * @param readFile - Optional function to read referenced requirement files (-r, --requirement).
42
+ * If provided, referenced files will be recursively processed.
43
+ */
44
+ export declare function convertRequirementsToPyprojectToml(fileContent: string, readFile?: ReadFileFn): PyProjectToml;
45
+ /**
46
+ * Parse requirements file content with full pip options support.
47
+ * Returns both the normalized requirements and the parsed pip options
48
+ * (--requirement, --constraint, --index-url, --extra-index-url, --hash).
49
+ *
50
+ * @param fileContent - The content of the requirements.txt file
51
+ * @param readFile - Optional function to read referenced requirement files (-r, --requirement).
52
+ * If provided, referenced files will be recursively processed and their
53
+ * requirements merged into the result.
54
+ */
55
+ export declare function parseRequirementsFile(fileContent: string, readFile?: ReadFileFn): ParsedRequirementsFile;