@dbx-tools/projen 0.6.222 → 0.6.224

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/tasks/uniffi.ts CHANGED
@@ -15,6 +15,7 @@ import { tmpdir } from "node:os";
15
15
  import { basename, dirname, join, resolve } from "node:path";
16
16
  import { fileURLToPath } from "node:url";
17
17
  import { parseArgs } from "node:util";
18
+ import { installPythonBindings } from "./uniffi-python.js";
18
19
  import { makeReadonly, makeWritable, stampGenerated } from "../src/generated.ts";
19
20
  import type { RustWorkspaceMapping } from "../src/project-rs.ts";
20
21
  import {
@@ -110,22 +111,6 @@ const replaceGenerated = (source: string, destination: string): void => {
110
111
  }
111
112
  };
112
113
 
113
- const stampGeneratedPython = (file: string): void => {
114
- makeWritable(file);
115
- const body = readFileSync(file, "utf8");
116
- writeFileSync(
117
- file,
118
- [
119
- "# GENERATED by UniFFI binding generation - DO NOT EDIT.",
120
- `# Regenerated from the ${crate} Rust exports.`,
121
- "# Hand edits are overwritten on the next watch; this file is read-only.",
122
- "",
123
- body,
124
- ].join("\n"),
125
- );
126
- makeReadonly(file);
127
- };
128
-
129
114
  if (!values["skip-build"]) {
130
115
  run("cargo", [
131
116
  "build",
@@ -265,33 +250,14 @@ if (values.python) {
265
250
  if (!values["python-module"]) {
266
251
  throw new Error("Expected --python-module with --python");
267
252
  }
268
- const pythonPackage = resolve(root, values.python, "src", ...values["python-module"].split("."));
269
- const pythonOutput = mkdtempSync(join(tmpdir(), `${libraryName}-python-`));
270
- run(
271
- join(targetDirectory, `${crate}-uniffi-bindgen${process.platform === "win32" ? ".exe" : ""}`),
272
- [
273
- "generate",
274
- "--language",
275
- "python",
276
- "--crate",
277
- libraryName,
278
- "--out-dir",
279
- pythonOutput,
280
- library,
281
- ],
282
- );
283
- const generated = join(pythonOutput, `${libraryName}.py`);
284
- const pythonBindings = join(pythonPackage, "bindings.py");
285
- replaceGenerated(generated, pythonBindings);
286
- stampGeneratedPython(pythonBindings);
287
- const pythonInit = join(pythonPackage, "__init__.py");
288
- makeWritable(pythonInit);
289
- writeFileSync(pythonInit, "");
290
- makeReadonly(pythonInit);
291
- const pythonLibrary = join(pythonPackage, basename(library));
292
- makeWritable(pythonLibrary);
293
- cpSync(library, pythonLibrary);
294
- makeReadonly(pythonLibrary);
295
- rmSync(join(pythonPackage, "_generated"), { recursive: true, force: true });
296
- rmSync(pythonOutput, { recursive: true, force: true });
253
+ installPythonBindings({
254
+ crate,
255
+ library,
256
+ module: values["python-module"],
257
+ packageRoot: resolve(root, values.python),
258
+ platform: process.platform,
259
+ readonly: true,
260
+ run,
261
+ targetDirectory,
262
+ });
297
263
  }