From d087ca6a60a082adcd26bd7d3ca585b1070dfdb2 Mon Sep 17 00:00:00 2001 From: Thorsten Beier Date: Thu, 13 Jun 2024 12:05:47 +0200 Subject: [PATCH] fs api (#70) --- .github/workflows/main.yml | 5 ----- environment-dev.yml | 1 + include/pyjs/pre_js/init.js | 2 +- src/export_js_module.cpp | 12 ++++++++++++ 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ba5940d..0514003 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -31,11 +31,6 @@ jobs: environment-file: environment-dev.yml environment-name: pyjs-wasm - # temporary: install pyjs_code_runner from source - - name: Install pyjs_code_runner - shell: bash -el {0} - run: | - python -m pip install git+https://github.com/emscripten-forge/pyjs-code-runner.git@main --no-deps --no-build-isolation - name: Install Playwright run: | diff --git a/environment-dev.yml b/environment-dev.yml index 849959c..7b55ef0 100644 --- a/environment-dev.yml +++ b/environment-dev.yml @@ -29,3 +29,4 @@ dependencies: - hatchling - pip: - JLDracula + - pyjs_code_runner >= 3.0 diff --git a/include/pyjs/pre_js/init.js b/include/pyjs/pre_js/init.js index 03cbcc7..a784dce 100644 --- a/include/pyjs/pre_js/init.js +++ b/include/pyjs/pre_js/init.js @@ -30,7 +30,7 @@ Module['init_phase_1'] = async function(prefix, python_version) { } - Module.FS.mkdirTree(side_path); + Module.create_directories(side_path); Module["_interpreter"] = new Module["_Interpreter"]() diff --git a/src/export_js_module.cpp b/src/export_js_module.cpp index f4e67f6..bd290dc 100644 --- a/src/export_js_module.cpp +++ b/src/export_js_module.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -79,6 +80,14 @@ namespace pyjs setenv(key.c_str(), value.c_str(), 1); } + void create_directories(const std::string & p) + { + std::filesystem::create_directories(std::filesystem::path(p)); + } + bool is_directory(const std::string & p) + { + return std::filesystem::is_directory(std::filesystem::path(p)); + } void export_js_module() { @@ -91,6 +100,9 @@ namespace pyjs em::function("_exec", &exec); em::function("_eval_file", &eval_file); + em::function("create_directories", &create_directories); + em::function("is_directory", &is_directory); + em::function("_untar", &untar); em::function("setenv", &set_env);