@primate/python 0.5.0 → 0.6.0
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.
- package/lib/private/default.d.ts +4 -0
- package/lib/private/default.js +73 -0
- package/lib/private/errors.d.ts +12 -0
- package/lib/private/errors.js +24 -0
- package/lib/private/module.d.ts +13 -0
- package/lib/private/module.js +11 -0
- package/lib/private/runtime.d.ts +4 -0
- package/lib/private/runtime.js +10 -0
- package/lib/private/to-request.d.ts +1 -1
- package/lib/private/unwrap.d.ts +3 -2
- package/lib/public/default.d.ts +1 -3
- package/lib/public/default.js +1 -2
- package/lib/public/runtime.d.ts +1 -3
- package/lib/public/runtime.js +1 -2
- package/package.json +13 -11
- package/lib/private/Default.d.ts +0 -7
- package/lib/private/Default.js +0 -74
- package/lib/private/Runtime.d.ts +0 -6
- package/lib/private/Runtime.js +0 -6
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import E from "#errors";
|
|
2
|
+
import module from "#module";
|
|
3
|
+
import log from "@primate/core/log";
|
|
4
|
+
import server from "@primate/core/server";
|
|
5
|
+
import assert from "@rcompat/assert";
|
|
6
|
+
import fs from "@rcompat/fs";
|
|
7
|
+
import io from "@rcompat/io";
|
|
8
|
+
const PACKAGE = "primate-run";
|
|
9
|
+
const [MAJOR, MINOR] = server.TAG.split(".").map(Number);
|
|
10
|
+
async function show_package() {
|
|
11
|
+
const str0 = () => "";
|
|
12
|
+
let out = await io.run(`pip show ${PACKAGE} 2>/dev/null`).catch(str0);
|
|
13
|
+
if (out.trim().length > 0)
|
|
14
|
+
return out;
|
|
15
|
+
out = await io.run(`uv pip show ${PACKAGE} 2>/dev/null`).catch(str0);
|
|
16
|
+
if (out.trim().length > 0)
|
|
17
|
+
return out;
|
|
18
|
+
out = await io.run(`python -m pip show ${PACKAGE} 2>/dev/null`).catch(str0);
|
|
19
|
+
if (out.trim().length > 0)
|
|
20
|
+
return out;
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
async function check_version() {
|
|
24
|
+
const output = await show_package();
|
|
25
|
+
if (output === null)
|
|
26
|
+
throw E.package_not_found();
|
|
27
|
+
const version_match = output.match(/Version:\s*(\d+)\.(\d+)\.(\d+)/);
|
|
28
|
+
if (version_match === null)
|
|
29
|
+
throw E.package_not_found();
|
|
30
|
+
const [major, minor] = version_match.slice(1).map(Number);
|
|
31
|
+
if (major !== MAJOR || minor !== MINOR)
|
|
32
|
+
throw E.package_mismatch(major, minor);
|
|
33
|
+
log.info("using {0} package {1}.{2}.x", PACKAGE, major, minor);
|
|
34
|
+
}
|
|
35
|
+
export default function default_module(input = {}) {
|
|
36
|
+
const { extension = module.extension } = module.schema.parse(input);
|
|
37
|
+
return {
|
|
38
|
+
name: module.name,
|
|
39
|
+
setup({ onBuild }) {
|
|
40
|
+
onBuild(async (app) => {
|
|
41
|
+
await check_version();
|
|
42
|
+
const requirements_txt = app.root.join("requirements.txt");
|
|
43
|
+
let packages = [];
|
|
44
|
+
if (await requirements_txt.exists()) {
|
|
45
|
+
const requirements = await fs.text(requirements_txt);
|
|
46
|
+
packages = requirements
|
|
47
|
+
.split("\n")
|
|
48
|
+
.filter(line => line.trim().length > 0 && !line.startsWith("#"))
|
|
49
|
+
.map(p => p.trim());
|
|
50
|
+
}
|
|
51
|
+
const packages_str = JSON.stringify(packages);
|
|
52
|
+
app.bind(extension, async (file, { context }) => {
|
|
53
|
+
assert.true(context === "routes", E.only_route_files());
|
|
54
|
+
const relative = file.debase(app.path.routes).path.replace(/^\//, "");
|
|
55
|
+
const source = await file.text();
|
|
56
|
+
return `
|
|
57
|
+
import wrapper from "@primate/python/wrapper";
|
|
58
|
+
import i18n from "app:config:i18n";
|
|
59
|
+
import session from "app:config:session";
|
|
60
|
+
await wrapper(
|
|
61
|
+
${JSON.stringify(source)},
|
|
62
|
+
${packages_str},
|
|
63
|
+
"${PACKAGE}~=${server.TAG}.0",
|
|
64
|
+
"${relative}",
|
|
65
|
+
{ i18n, session }
|
|
66
|
+
);
|
|
67
|
+
`;
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=default.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare function only_route_files(): import("@rcompat/error").TemplateError;
|
|
2
|
+
declare function package_not_found(): import("@rcompat/error").TemplateError;
|
|
3
|
+
declare function package_mismatch(major: number, minor: number): import("@rcompat/error").TemplateError;
|
|
4
|
+
declare const errors: {
|
|
5
|
+
only_route_files: typeof only_route_files;
|
|
6
|
+
package_not_found: typeof package_not_found;
|
|
7
|
+
package_mismatch: typeof package_mismatch;
|
|
8
|
+
};
|
|
9
|
+
export type Code = keyof typeof errors;
|
|
10
|
+
export declare const Code: { [K in Code]: K; };
|
|
11
|
+
export default errors;
|
|
12
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import server from "@primate/core/server";
|
|
2
|
+
import error from "@rcompat/error";
|
|
3
|
+
const PACKAGE = "primate-run";
|
|
4
|
+
const t = error.template;
|
|
5
|
+
function only_route_files() {
|
|
6
|
+
return t `python: only route files are supported`;
|
|
7
|
+
}
|
|
8
|
+
function package_not_found() {
|
|
9
|
+
const command = `pip install ${PACKAGE}~=${server.TAG}.0`;
|
|
10
|
+
return t `package not found, run ${command}`;
|
|
11
|
+
}
|
|
12
|
+
function package_mismatch(major, minor) {
|
|
13
|
+
const range = `~> ${server.TAG}.x`;
|
|
14
|
+
const version = `${major}.${minor}.x`;
|
|
15
|
+
return t `${PACKAGE} package version ${version} not in range ${range}`;
|
|
16
|
+
}
|
|
17
|
+
const errors = error.coded({
|
|
18
|
+
only_route_files,
|
|
19
|
+
package_not_found,
|
|
20
|
+
package_mismatch,
|
|
21
|
+
});
|
|
22
|
+
export const Code = Object.fromEntries(Object.keys(errors).map(k => [k, k]));
|
|
23
|
+
export default errors;
|
|
24
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare const module: {
|
|
2
|
+
schema: import("pema").ObjectType<import("pema").NormalizeSchemaObject<{
|
|
3
|
+
readonly extension: import("pema").OptionalType<import("pema").StringType>;
|
|
4
|
+
}>, {
|
|
5
|
+
extension: string | undefined;
|
|
6
|
+
}>;
|
|
7
|
+
name: string;
|
|
8
|
+
extension: string;
|
|
9
|
+
};
|
|
10
|
+
type Input = typeof module.schema.input;
|
|
11
|
+
export type { Input };
|
|
12
|
+
export default module;
|
|
13
|
+
//# sourceMappingURL=module.d.ts.map
|
package/lib/private/unwrap.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { Dict } from "@rcompat/type";
|
|
2
1
|
import type { PyProxy } from "pyodide/ffi";
|
|
3
|
-
export default function unwrap(response: PyProxy):
|
|
2
|
+
export default function unwrap(response: PyProxy): {
|
|
3
|
+
[k: string]: unknown;
|
|
4
|
+
};
|
|
4
5
|
//# sourceMappingURL=unwrap.d.ts.map
|
package/lib/public/default.d.ts
CHANGED
package/lib/public/default.js
CHANGED
package/lib/public/runtime.d.ts
CHANGED
package/lib/public/runtime.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@primate/python",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Python backend for Primate",
|
|
5
5
|
"homepage": "https://primate.run/docs/backend/python",
|
|
6
6
|
"bugs": "https://github.com/primate-run/primate/issues",
|
|
@@ -17,22 +17,23 @@
|
|
|
17
17
|
"!/**/*.spec.*"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@rcompat/assert": "^0.
|
|
21
|
-
"@rcompat/
|
|
22
|
-
"@rcompat/
|
|
20
|
+
"@rcompat/assert": "^0.8.1",
|
|
21
|
+
"@rcompat/error": "^0.3.1",
|
|
22
|
+
"@rcompat/fs": "^0.28.1",
|
|
23
|
+
"@rcompat/io": "^0.5.1",
|
|
23
24
|
"pyodide": "^0.29.3",
|
|
24
|
-
"@primate/core": "^0.
|
|
25
|
-
"pema": "^0.
|
|
25
|
+
"@primate/core": "^0.6.0",
|
|
26
|
+
"pema": "^0.6.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"@rcompat/type": "^0.
|
|
29
|
+
"@rcompat/type": "^0.11.1"
|
|
29
30
|
},
|
|
30
31
|
"peerDependencies": {
|
|
31
|
-
"primate": "^0.
|
|
32
|
+
"primate": "^0.37.0"
|
|
32
33
|
},
|
|
33
34
|
"imports": {
|
|
34
35
|
"#*": {
|
|
35
|
-
"
|
|
36
|
+
"@primate/source": "./src/private/*.ts",
|
|
36
37
|
"default": "./lib/private/*.js"
|
|
37
38
|
}
|
|
38
39
|
},
|
|
@@ -42,13 +43,14 @@
|
|
|
42
43
|
"default": "./lib/public/default.js"
|
|
43
44
|
},
|
|
44
45
|
"./*": {
|
|
45
|
-
"
|
|
46
|
+
"@primate/source": "./src/public/*.ts",
|
|
46
47
|
"default": "./lib/public/*.js"
|
|
47
48
|
}
|
|
48
49
|
},
|
|
49
50
|
"scripts": {
|
|
50
51
|
"build": "npm run clean && tsc",
|
|
51
52
|
"clean": "rm -rf ./lib",
|
|
52
|
-
"lint": "eslint ."
|
|
53
|
+
"lint": "eslint .",
|
|
54
|
+
"test": "npx proby"
|
|
53
55
|
}
|
|
54
56
|
}
|
package/lib/private/Default.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import Runtime from "#Runtime";
|
|
2
|
-
import type BuildApp from "@primate/core/BuildApp";
|
|
3
|
-
import type NextBuild from "@primate/core/NextBuild";
|
|
4
|
-
export default class Default extends Runtime {
|
|
5
|
-
build(app: BuildApp, next: NextBuild): Promise<BuildApp>;
|
|
6
|
-
}
|
|
7
|
-
//# sourceMappingURL=Default.d.ts.map
|
package/lib/private/Default.js
DELETED
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import Runtime from "#Runtime";
|
|
2
|
-
import TAG from "@primate/core/backend/TAG";
|
|
3
|
-
import fail from "@primate/core/fail";
|
|
4
|
-
import log from "@primate/core/log";
|
|
5
|
-
import assert from "@rcompat/assert";
|
|
6
|
-
import fs from "@rcompat/fs";
|
|
7
|
-
import io from "@rcompat/io";
|
|
8
|
-
const PACKAGE = "primate-run";
|
|
9
|
-
const [MAJOR, MINOR] = TAG.split(".").map(Number);
|
|
10
|
-
function package_not_found() {
|
|
11
|
-
return fail("package not found - run 'pip install {0}~={1}.0'", PACKAGE, TAG);
|
|
12
|
-
}
|
|
13
|
-
function pkg_mismatch(major, minor) {
|
|
14
|
-
return fail("installed {0} package version {1}.{2}.x not in range ~> {3}.x", PACKAGE, major, minor, TAG);
|
|
15
|
-
}
|
|
16
|
-
async function show_package() {
|
|
17
|
-
const str0 = () => "";
|
|
18
|
-
let out = await io.run(`pip show ${PACKAGE} 2>/dev/null`).catch(str0);
|
|
19
|
-
if (out.trim())
|
|
20
|
-
return out;
|
|
21
|
-
out = await io.run(`uv pip show ${PACKAGE} 2>/dev/null`).catch(str0);
|
|
22
|
-
if (out.trim())
|
|
23
|
-
return out;
|
|
24
|
-
out = await io.run(`python -m pip show ${PACKAGE} 2>/dev/null`).catch(str0);
|
|
25
|
-
if (out.trim())
|
|
26
|
-
return out;
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
async function check_version() {
|
|
30
|
-
const output = await show_package();
|
|
31
|
-
if (!output)
|
|
32
|
-
throw package_not_found();
|
|
33
|
-
const version_match = output.match(/Version:\s*(\d+)\.(\d+)\.(\d+)/);
|
|
34
|
-
if (!version_match)
|
|
35
|
-
throw package_not_found();
|
|
36
|
-
const [major, minor] = version_match.slice(1).map(Number);
|
|
37
|
-
if (major !== MAJOR || minor !== MINOR)
|
|
38
|
-
throw pkg_mismatch(major, minor);
|
|
39
|
-
log.info("using {0} package {1}.{2}.x", PACKAGE, major, minor);
|
|
40
|
-
}
|
|
41
|
-
export default class Default extends Runtime {
|
|
42
|
-
async build(app, next) {
|
|
43
|
-
await check_version();
|
|
44
|
-
const requirements_txt = app.root.join("requirements.txt");
|
|
45
|
-
let packages = [];
|
|
46
|
-
if (await requirements_txt.exists()) {
|
|
47
|
-
const requirements = await fs.text(requirements_txt);
|
|
48
|
-
packages = requirements
|
|
49
|
-
.split("\n")
|
|
50
|
-
.filter(line => line.trim() && !line.startsWith("#"))
|
|
51
|
-
.map(p => p.trim());
|
|
52
|
-
}
|
|
53
|
-
const packages_str = JSON.stringify(packages);
|
|
54
|
-
app.bind(this.fileExtension, async (file, { context }) => {
|
|
55
|
-
assert.true(context === "routes", "python: only route files are supported");
|
|
56
|
-
const relative = file.debase(app.path.routes).path.replace(/^\//, "");
|
|
57
|
-
const source = await file.text();
|
|
58
|
-
return `
|
|
59
|
-
import wrapper from "@primate/python/wrapper";
|
|
60
|
-
import i18n from "app:config:i18n";
|
|
61
|
-
import session from "app:config:session";
|
|
62
|
-
await wrapper(
|
|
63
|
-
${JSON.stringify(source)},
|
|
64
|
-
${packages_str},
|
|
65
|
-
"${PACKAGE}~=${TAG}.0",
|
|
66
|
-
"${relative}",
|
|
67
|
-
{ i18n, session }
|
|
68
|
-
);
|
|
69
|
-
`;
|
|
70
|
-
});
|
|
71
|
-
return next(app);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
//# sourceMappingURL=Default.js.map
|
package/lib/private/Runtime.d.ts
DELETED