Skip to content

Commit

Permalink
[python] remove useless file (#5445)
Browse files Browse the repository at this point in the history
The dependencies in requirements.txt are already declared in setup.py so
the file is not needed anymore.

---------

Co-authored-by: tadelesh <tadelesh.shi@live.cn>
  • Loading branch information
msyyc and tadelesh authored Jan 2, 2025
1 parent 7a7415e commit 6e9fba5
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 50 deletions.
39 changes: 29 additions & 10 deletions packages/http-client-python/emitter/src/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,34 @@ async function setupPyodideCall(root: string) {
const pyodide = await loadPyodide({
indexURL: path.dirname(fileURLToPath(import.meta.resolve("pyodide"))),
});
// mount generator to pyodide
pyodide.FS.mkdirTree("/generator");
pyodide.FS.mount(
pyodide.FS.filesystems.NODEFS,
{ root: path.join(root, "generator") },
"/generator",
);
await pyodide.loadPackage("micropip");
const micropip = pyodide.pyimport("micropip");
await micropip.install("emfs:/generator/dist/pygen-0.1.0-py3-none-any.whl");
const micropipLockPath = path.join(root, "micropip.lock");
while (true) {
if (fs.existsSync(micropipLockPath)) {
const stats = fs.statSync(micropipLockPath);
const now = new Date().getTime();
const lockAge = (now - stats.mtime.getTime()) / 1000;
if (lockAge > 600) {
fs.unlinkSync(micropipLockPath);
}
}
try {
const fd = fs.openSync(micropipLockPath, "wx");
// mount generator to pyodide
pyodide.FS.mkdirTree("/generator");
pyodide.FS.mount(
pyodide.FS.filesystems.NODEFS,
{ root: path.join(root, "generator") },
"/generator",
);
await pyodide.loadPackage("micropip");
const micropip = pyodide.pyimport("micropip");
await micropip.install("emfs:/generator/dist/pygen-0.1.0-py3-none-any.whl");
fs.closeSync(fd);
fs.unlinkSync(micropipLockPath);
break;
} catch (err) {
await new Promise((resolve) => setTimeout(resolve, 1000));
}
}
return pyodide;
}
10 changes: 2 additions & 8 deletions packages/http-client-python/eng/scripts/ci/regenerate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,14 +299,8 @@ async function regenerate(flags: RegenerateFlagsInput): Promise<void> {
const cmdList: TspCommand[] = subdirectories.flatMap((subdirectory) =>
_getCmdList(subdirectory, flagsResolved),
);
const chunks: TspCommand[][] = [];
for (let i = 0; i < cmdList.length; i += 10) {
chunks.push(cmdList.slice(i, i + 10));
}
for (const chunk of chunks) {
const promiseCommands = chunk.map((tspCommand) => executeCommand(tspCommand));
await Promise.all(promiseCommands);
}
const PromiseCommands = cmdList.map((tspCommand) => executeCommand(tspCommand));
await Promise.all(PromiseCommands);
}
}

Expand Down
5 changes: 0 additions & 5 deletions packages/http-client-python/eng/scripts/setup/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ def main():
venv_context = env_builder.context

python_run(venv_context, "pip", ["install", "-U", "pip"])
python_run(
venv_context,
"pip",
["install", "-r", f"{_ROOT_DIR}/generator/requirements.txt"],
)
python_run(venv_context, "pip", ["install", "-e", f"{_ROOT_DIR}/generator"])


Expand Down
20 changes: 0 additions & 20 deletions packages/http-client-python/eng/scripts/setup/install.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import fs from "fs";
import path, { dirname } from "path";
import { loadPyodide } from "pyodide";
import { fileURLToPath } from "url";
import { runPython3 } from "./run-python3.js";

async function main() {
Expand All @@ -10,23 +6,7 @@ async function main() {
console.log("Found Python on your local environment and created a venv with all requirements."); // eslint-disable-line no-console
} catch (error) {
console.log("No Python found on your local environment. We will use Pyodide instead."); // eslint-disable-line no-console
} finally {
await installPyodideDeps();
console.log("Successfully installed all required Python packages in Pyodide"); // eslint-disable-line no-console
}
}

async function installPyodideDeps() {
const root = path.join(dirname(fileURLToPath(import.meta.url)), "..", "..", "..");
const pyodide = await loadPyodide({
indexURL: path.dirname(fileURLToPath(import.meta.resolve("pyodide"))),
});
await pyodide.loadPackage("micropip");
const micropip = pyodide.pyimport("micropip");
const requirementsPath = path.join(root, "generator", "requirements.txt");
const requirementsText = fs.readFileSync(requirementsPath, "utf-8");
const requirementsArray = requirementsText.split("\n").filter((line) => line.trim() !== "");
await micropip.install(requirementsArray);
}

main();
7 changes: 0 additions & 7 deletions packages/http-client-python/generator/requirements.txt

This file was deleted.

0 comments on commit 6e9fba5

Please sign in to comment.