@dbx-tools/projen 0.9.51 → 0.9.58
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/README.md +56 -16
- package/index.ts +9 -6
- package/package.json +5 -6
- package/src/dbx-tools-config.ts +8 -0
- package/src/generated.ts +6 -0
- package/src/packages.ts +6 -0
- package/src/project-py.ts +89 -18
- package/src/project.ts +2 -1
- package/src/python-node-bindings-component.ts +71 -0
- package/src/python-node-bindings.ts +38 -14
- package/src/python-node-runtime.ts +56 -0
- package/src/vscode.ts +17 -1
- package/src/workspace-lock.ts +31 -13
- package/tasks/publish-python.ts +14 -6
- package/tasks/python-localize-imports.py +188 -0
- package/tasks/python-node-bindings-watch.ts +96 -0
- package/tasks/python-node-bindings.ts +42 -130
- package/tasks/python-node-runtime-watch.ts +40 -0
- package/tasks/python-sync.ts +85 -3
- package/tasks/release.ts +2 -1
- package/tasks/sync.ts +15 -3
- package/shims/python-node/bootstrap.ts +0 -129
- package/shims/python-node/child-process.ts +0 -96
- package/shims/python-node/crypto.ts +0 -60
- package/shims/python-node/fs-promises.ts +0 -179
- package/shims/python-node/fs.ts +0 -173
- package/shims/python-node/headers.ts +0 -75
- package/shims/python-node/host.ts +0 -341
- package/shims/python-node/os.ts +0 -20
- package/shims/python-node/process.ts +0 -13
- package/shims/python-node/readline.ts +0 -37
- package/shims/python-node/tsconfig.json +0 -24
- package/src/python-node-bundle.ts +0 -67
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
import { Buffer } from "node:buffer";
|
|
2
|
-
|
|
3
|
-
import { pythonHost } from "./host.ts";
|
|
4
|
-
|
|
5
|
-
function nodeError(error: unknown, code: string, path: string): Error {
|
|
6
|
-
return Object.assign(error instanceof Error ? error : new Error(String(error)), { code, path });
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
function translatePythonError(cause: unknown, path: string): never {
|
|
10
|
-
const message = String(cause);
|
|
11
|
-
if (/FileNotFoundError|Errno 2/.test(message)) throw nodeError(cause, "ENOENT", path);
|
|
12
|
-
if (/FileExistsError|Errno 17/.test(message)) throw nodeError(cause, "EEXIST", path);
|
|
13
|
-
if (/PermissionError|Errno 13/.test(message)) throw nodeError(cause, "EACCES", path);
|
|
14
|
-
throw cause;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export async function access(path: string): Promise<void> {
|
|
18
|
-
try {
|
|
19
|
-
await pythonHost().file.stat(String(path));
|
|
20
|
-
} catch (cause) {
|
|
21
|
-
translatePythonError(cause, path);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export async function chmod(path: string, mode: number): Promise<void> {
|
|
26
|
-
await pythonHost().file.chmod(String(path), mode);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export async function appendFile(
|
|
30
|
-
path: string,
|
|
31
|
-
content: string | ArrayBuffer | ArrayBufferView,
|
|
32
|
-
): Promise<void> {
|
|
33
|
-
const bytes =
|
|
34
|
-
typeof content === "string"
|
|
35
|
-
? new TextEncoder().encode(content)
|
|
36
|
-
: content instanceof ArrayBuffer
|
|
37
|
-
? new Uint8Array(content)
|
|
38
|
-
: new Uint8Array(content.buffer, content.byteOffset, content.byteLength);
|
|
39
|
-
await pythonHost().file.appendBytes(String(path), Array.from(bytes));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export async function copyFile(source: string, destination: string): Promise<void> {
|
|
43
|
-
await pythonHost().file.copy(String(source), String(destination));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export async function mkdir(
|
|
47
|
-
path: string,
|
|
48
|
-
options: { recursive?: boolean } = {},
|
|
49
|
-
): Promise<string | undefined> {
|
|
50
|
-
let created: boolean;
|
|
51
|
-
try {
|
|
52
|
-
created = await pythonHost().file.mkdir(String(path), options.recursive === true);
|
|
53
|
-
} catch (cause) {
|
|
54
|
-
if (/FileExistsError|Errno 17/.test(String(cause))) {
|
|
55
|
-
if (options.recursive) return undefined;
|
|
56
|
-
throw nodeError(cause, "EEXIST", path);
|
|
57
|
-
}
|
|
58
|
-
throw cause;
|
|
59
|
-
}
|
|
60
|
-
if (!created && !options.recursive) throw nodeError(new Error(`EEXIST: ${path}`), "EEXIST", path);
|
|
61
|
-
return created ? String(path) : undefined;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export async function mkdtemp(prefix: string): Promise<string> {
|
|
65
|
-
return pythonHost().file.mkdtemp(String(prefix));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export async function readdir(
|
|
69
|
-
path: string,
|
|
70
|
-
options: { withFileTypes?: boolean } = {},
|
|
71
|
-
): Promise<unknown[]> {
|
|
72
|
-
const entries = await pythonHost().file.readDirectory(String(path));
|
|
73
|
-
if (!options.withFileTypes) return entries.map((entry) => entry.name);
|
|
74
|
-
return entries.map((entry) => ({
|
|
75
|
-
name: entry.name,
|
|
76
|
-
isDirectory: () => entry.directory,
|
|
77
|
-
isFile: () => entry.file,
|
|
78
|
-
isSymbolicLink: () => false,
|
|
79
|
-
}));
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export async function readFile(
|
|
83
|
-
path: string,
|
|
84
|
-
options?: string | { encoding?: string | null },
|
|
85
|
-
): Promise<string | Uint8Array> {
|
|
86
|
-
try {
|
|
87
|
-
const bytes = Uint8Array.from(await pythonHost().file.readBytes(String(path)));
|
|
88
|
-
const encoding = typeof options === "string" ? options : options?.encoding;
|
|
89
|
-
return encoding ? new TextDecoder(encoding).decode(bytes) : Buffer.from(bytes);
|
|
90
|
-
} catch (cause) {
|
|
91
|
-
translatePythonError(cause, path);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export async function realpath(path: string): Promise<string> {
|
|
96
|
-
try {
|
|
97
|
-
return await pythonHost().file.realpath(String(path));
|
|
98
|
-
} catch (cause) {
|
|
99
|
-
translatePythonError(cause, path);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
export async function rename(source: string, destination: string): Promise<void> {
|
|
104
|
-
await pythonHost().file.rename(String(source), String(destination));
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export async function rm(
|
|
108
|
-
path: string,
|
|
109
|
-
options: { recursive?: boolean; force?: boolean } = {},
|
|
110
|
-
): Promise<void> {
|
|
111
|
-
await pythonHost().file.remove(String(path), options.recursive === true, options.force === true);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export async function unlink(path: string): Promise<void> {
|
|
115
|
-
// No synchronous existence precheck: let the async remove run and treat a
|
|
116
|
-
// missing file as success, so this never blocks on a sync Python call.
|
|
117
|
-
try {
|
|
118
|
-
await pythonHost().file.remove(String(path), false, true);
|
|
119
|
-
} catch (cause) {
|
|
120
|
-
if (/FileNotFoundError|Errno 2|ENOENT/.test(String(cause))) return;
|
|
121
|
-
translatePythonError(cause, path);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export async function stat(path: string): Promise<unknown> {
|
|
126
|
-
let value: Awaited<ReturnType<ReturnType<typeof pythonHost>["file"]["stat"]>>;
|
|
127
|
-
try {
|
|
128
|
-
value = await pythonHost().file.stat(String(path));
|
|
129
|
-
} catch (cause) {
|
|
130
|
-
translatePythonError(cause, path);
|
|
131
|
-
}
|
|
132
|
-
return {
|
|
133
|
-
mode: value.mode,
|
|
134
|
-
mtime: new Date(value.mtimeMs),
|
|
135
|
-
mtimeMs: value.mtimeMs,
|
|
136
|
-
size: value.size,
|
|
137
|
-
isDirectory: () => value.directory,
|
|
138
|
-
isFile: () => value.file,
|
|
139
|
-
isSymbolicLink: () => false,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export async function writeFile(
|
|
144
|
-
path: string,
|
|
145
|
-
content: string | ArrayBuffer | ArrayBufferView,
|
|
146
|
-
options: { mode?: number } = {},
|
|
147
|
-
): Promise<void> {
|
|
148
|
-
const bytes =
|
|
149
|
-
typeof content === "string"
|
|
150
|
-
? new TextEncoder().encode(content)
|
|
151
|
-
: content instanceof ArrayBuffer
|
|
152
|
-
? new Uint8Array(content)
|
|
153
|
-
: new Uint8Array(content.buffer, content.byteOffset, content.byteLength);
|
|
154
|
-
await pythonHost().file.writeBytes(String(path), Array.from(bytes), options.mode);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export async function open(): Promise<never> {
|
|
158
|
-
throw Object.assign(new Error("File descriptors are unavailable in PythonMonkey"), {
|
|
159
|
-
code: "ENOSYS",
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
export default {
|
|
164
|
-
access,
|
|
165
|
-
appendFile,
|
|
166
|
-
chmod,
|
|
167
|
-
copyFile,
|
|
168
|
-
mkdir,
|
|
169
|
-
mkdtemp,
|
|
170
|
-
open,
|
|
171
|
-
readFile,
|
|
172
|
-
readdir,
|
|
173
|
-
realpath,
|
|
174
|
-
rename,
|
|
175
|
-
rm,
|
|
176
|
-
stat,
|
|
177
|
-
unlink,
|
|
178
|
-
writeFile,
|
|
179
|
-
};
|
package/shims/python-node/fs.ts
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { Readable, Writable } from "node:stream";
|
|
2
|
-
|
|
3
|
-
import * as promises from "./fs-promises.ts";
|
|
4
|
-
import { pythonHost } from "./host.ts";
|
|
5
|
-
|
|
6
|
-
type Callback<T = undefined> = (error: Error | null, value?: T) => void;
|
|
7
|
-
|
|
8
|
-
function callback<T>(operation: Promise<T>, done: Callback<T>): void {
|
|
9
|
-
void operation.then(
|
|
10
|
-
(value) => done(null, value),
|
|
11
|
-
(error) => done(error as Error),
|
|
12
|
-
);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function existsSync(path: string): boolean {
|
|
16
|
-
return pythonHost().file.exists(String(path));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function readFileSync(path: string, _encoding?: string): string {
|
|
20
|
-
return pythonHost().file.readTextSync(String(path));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function readdirSync(path: string, options: { withFileTypes?: boolean } = {}): unknown[] {
|
|
24
|
-
const entries = pythonHost().file.readDirectorySync(String(path));
|
|
25
|
-
if (!options.withFileTypes) return entries.map((entry) => entry.name);
|
|
26
|
-
return entries.map((entry) => ({
|
|
27
|
-
name: entry.name,
|
|
28
|
-
isDirectory: () => entry.directory,
|
|
29
|
-
isFile: () => entry.file,
|
|
30
|
-
isSymbolicLink: () => false,
|
|
31
|
-
}));
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export function readlinkSync(path: string): string {
|
|
35
|
-
return pythonHost().file.readLinkSync(String(path));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export function realpathSync(path: string): string {
|
|
39
|
-
return pythonHost().file.realpathSync(String(path));
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
realpathSync.native = realpathSync;
|
|
43
|
-
|
|
44
|
-
export function lstatSync(path: string): unknown {
|
|
45
|
-
const value = pythonHost().file.statSync(String(path));
|
|
46
|
-
return {
|
|
47
|
-
mode: value.mode,
|
|
48
|
-
mtime: new Date(value.mtimeMs),
|
|
49
|
-
mtimeMs: value.mtimeMs,
|
|
50
|
-
size: value.size,
|
|
51
|
-
isDirectory: () => value.directory,
|
|
52
|
-
isFile: () => value.file,
|
|
53
|
-
isSymbolicLink: () => false,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function createReadStream(path: string): Readable {
|
|
58
|
-
const stream = new Readable({ read() {} });
|
|
59
|
-
void pythonHost()
|
|
60
|
-
.file.readBytes(String(path))
|
|
61
|
-
.then(
|
|
62
|
-
(content) => {
|
|
63
|
-
stream.push(Uint8Array.from(content));
|
|
64
|
-
stream.push(null);
|
|
65
|
-
},
|
|
66
|
-
(error) => stream.destroy(error as Error),
|
|
67
|
-
);
|
|
68
|
-
return stream;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export function createWriteStream(path: string, options: { mode?: number } = {}): Writable {
|
|
72
|
-
const chunks: number[] = [];
|
|
73
|
-
return new Writable({
|
|
74
|
-
write(chunk, _encoding, done) {
|
|
75
|
-
chunks.push(...new Uint8Array(chunk));
|
|
76
|
-
done();
|
|
77
|
-
},
|
|
78
|
-
final(done) {
|
|
79
|
-
void pythonHost()
|
|
80
|
-
.file.writeBytes(String(path), chunks, options.mode)
|
|
81
|
-
.then(
|
|
82
|
-
() => done(),
|
|
83
|
-
(error) => done(error as Error),
|
|
84
|
-
);
|
|
85
|
-
},
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
export function mkdir(path: string, options: object | Callback, done?: Callback): void {
|
|
90
|
-
const settings = typeof options === "function" ? {} : (options as { recursive?: boolean });
|
|
91
|
-
const callbackValue = typeof options === "function" ? options : done;
|
|
92
|
-
callback(
|
|
93
|
-
promises.mkdir(path, settings).then(() => undefined),
|
|
94
|
-
callbackValue ?? (() => {}),
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export function realpath(path: string, done: Callback<string>): void {
|
|
99
|
-
callback(promises.realpath(path), done);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
export function stat(path: string, done: Callback<unknown>): void {
|
|
103
|
-
callback(promises.stat(path), done);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
export const lstat = stat;
|
|
107
|
-
|
|
108
|
-
export function rmdir(path: string, done: Callback): void {
|
|
109
|
-
callback(
|
|
110
|
-
promises.rm(path).then(() => undefined),
|
|
111
|
-
done,
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function utimes(path: string, atime: Date, mtime: Date, done: Callback): void {
|
|
116
|
-
callback(
|
|
117
|
-
pythonHost()
|
|
118
|
-
.file.touch(String(path), atime.getTime(), mtime.getTime())
|
|
119
|
-
.then(() => undefined),
|
|
120
|
-
done,
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export function open(_path: string, _flags: unknown, done: Callback<number>): void {
|
|
125
|
-
done(
|
|
126
|
-
Object.assign(new Error("File descriptors are unavailable in PythonMonkey"), {
|
|
127
|
-
code: "ENOSYS",
|
|
128
|
-
}),
|
|
129
|
-
);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export function close(_fd: number, done: Callback): void {
|
|
133
|
-
done(null);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
export function openSync(): never {
|
|
137
|
-
throw Object.assign(new Error("File descriptors are unavailable in PythonMonkey"), {
|
|
138
|
-
code: "ENOSYS",
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
export function closeSync(): void {}
|
|
143
|
-
|
|
144
|
-
export const constants = {
|
|
145
|
-
O_RDONLY: 0,
|
|
146
|
-
O_WRONLY: 1,
|
|
147
|
-
O_SYMLINK: 0,
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
export { promises };
|
|
151
|
-
|
|
152
|
-
export default {
|
|
153
|
-
close,
|
|
154
|
-
closeSync,
|
|
155
|
-
constants,
|
|
156
|
-
createReadStream,
|
|
157
|
-
createWriteStream,
|
|
158
|
-
existsSync,
|
|
159
|
-
lstat,
|
|
160
|
-
mkdir,
|
|
161
|
-
open,
|
|
162
|
-
openSync,
|
|
163
|
-
promises,
|
|
164
|
-
readFileSync,
|
|
165
|
-
readdirSync,
|
|
166
|
-
realpath,
|
|
167
|
-
realpathSync,
|
|
168
|
-
readlinkSync,
|
|
169
|
-
rmdir,
|
|
170
|
-
stat,
|
|
171
|
-
lstatSync,
|
|
172
|
-
utimes,
|
|
173
|
-
};
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
export class PythonHeaders implements Iterable<[string, string]> {
|
|
2
|
-
readonly #values = new Map<string, string[]>();
|
|
3
|
-
|
|
4
|
-
constructor(init?: HeadersInit) {
|
|
5
|
-
if (!init) return;
|
|
6
|
-
if (Symbol.iterator in Object(init)) {
|
|
7
|
-
for (const [name, value] of init as Iterable<[string, string]>) this.append(name, value);
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
for (const [name, value] of Object.entries(init)) this.set(name, String(value));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
append(name: string, value: string): void {
|
|
14
|
-
const key = normalizeName(name);
|
|
15
|
-
const values = this.#values.get(key) ?? [];
|
|
16
|
-
values.push(String(value));
|
|
17
|
-
this.#values.set(key, values);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
delete(name: string): void {
|
|
21
|
-
this.#values.delete(normalizeName(name));
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
entries(): IterableIterator<[string, string]> {
|
|
25
|
-
return this.#iterateEntries();
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
forEach(
|
|
29
|
-
callback: (value: string, key: string, parent: PythonHeaders) => void,
|
|
30
|
-
thisArg?: unknown,
|
|
31
|
-
): void {
|
|
32
|
-
for (const [key, value] of this) callback.call(thisArg, value, key, this);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
get(name: string): string | null {
|
|
36
|
-
const values = this.#values.get(normalizeName(name));
|
|
37
|
-
return values ? values.join(", ") : null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
getSetCookie(): string[] {
|
|
41
|
-
return [...(this.#values.get("set-cookie") ?? [])];
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
has(name: string): boolean {
|
|
45
|
-
return this.#values.has(normalizeName(name));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
keys(): IterableIterator<string> {
|
|
49
|
-
return this.#values.keys();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
set(name: string, value: string): void {
|
|
53
|
-
this.#values.set(normalizeName(name), [String(value)]);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
values(): IterableIterator<string> {
|
|
57
|
-
return this.#iterateValues();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
[Symbol.iterator](): IterableIterator<[string, string]> {
|
|
61
|
-
return this.entries();
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
*#iterateEntries(): IterableIterator<[string, string]> {
|
|
65
|
-
for (const [name, values] of this.#values) yield [name, values.join(", ")];
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
*#iterateValues(): IterableIterator<string> {
|
|
69
|
-
for (const [, value] of this) yield value;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function normalizeName(name: string): string {
|
|
74
|
-
return String(name).toLowerCase();
|
|
75
|
-
}
|