Skip to content

Commit

Permalink
Move python runtime APIs to py_interop
Browse files Browse the repository at this point in the history
  • Loading branch information
yqs112358 committed Mar 17, 2023
1 parent 5dfe3dc commit dcfb8a8
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 38 deletions.
24 changes: 0 additions & 24 deletions backend/Python/PyEngine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,30 +216,6 @@ std::string PyEngine::getEngineVersion() { return Py_GetVersion(); }

bool PyEngine::isDestroying() const { return destroying; }

void PyEngine::setPythonHomePath(const std::wstring &path) {
return py_runtime_settings::setPythonHomePath(path);
}

std::wstring PyEngine::getPythonHomePath() {
return py_runtime_settings::getPythonHomePath();
}

void PyEngine::setModuleSearchPaths(const std::vector<std::wstring> &paths) {
return py_runtime_settings::setModuleSearchPaths(paths);
}

void PyEngine::addModuleSearchPath(const std::wstring &path) {
return py_runtime_settings::addModuleSearchPath(path);
}

std::vector<std::wstring> PyEngine::getModuleSearchPaths() {
return py_runtime_settings::getModuleSearchPaths();
}

std::wstring PyEngine::getPlatformPathSeparator() {
return py_runtime_settings::getPlatformPathSeparator();
}

} // namespace script::py_backend

SCRIPTX_END_IGNORE_DEPRECARED
8 changes: 0 additions & 8 deletions backend/Python/PyEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,6 @@ class PyEngine : public ScriptEngine {

std::string getEngineVersion() override;

// Python runtime config APIs
static void setPythonHomePath(const std::wstring &path);
static std::wstring getPythonHomePath();
static void setModuleSearchPaths(const std::vector<std::wstring> &paths);
static void addModuleSearchPath(const std::wstring &path);
static std::vector<std::wstring> getModuleSearchPaths();
static std::wstring getPlatformPathSeparator();

protected:
~PyEngine() override;

Expand Down
25 changes: 25 additions & 0 deletions backend/Python/PyHelper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,37 @@

#include "PyHelper.hpp"
#include "PyEngine.h"
#include "PyRuntimeSettings.h"

namespace script {

Arguments py_interop::makeArguments(py_backend::PyEngine* engine, PyObject* self, PyObject* args) {
return Arguments(py_backend::ArgumentsData{engine, self, args});
}

void py_interop::setPythonHomePath(const std::wstring &path) {
return script::py_backend::py_runtime_settings::setPythonHomePath(path);
}

std::wstring py_interop::getPythonHomePath() {
return script::py_backend::py_runtime_settings::getPythonHomePath();
}

void py_interop::setModuleSearchPaths(const std::vector<std::wstring> &paths) {
return script::py_backend::py_runtime_settings::setModuleSearchPaths(paths);
}

void py_interop::addModuleSearchPath(const std::wstring &path) {
return script::py_backend::py_runtime_settings::addModuleSearchPath(path);
}

std::vector<std::wstring> py_interop::getModuleSearchPaths() {
return script::py_backend::py_runtime_settings::getModuleSearchPaths();
}

std::wstring py_interop::getPlatformPathSeparator() {
return script::py_backend::py_runtime_settings::getPlatformPathSeparator();
}

namespace py_backend {

Expand Down
8 changes: 8 additions & 0 deletions backend/Python/PyHelper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ struct py_interop {
}

static Arguments makeArguments(py_backend::PyEngine* engine, PyObject* self, PyObject* args);

// Python runtime config APIs
static void setPythonHomePath(const std::wstring &path);
static std::wstring getPythonHomePath();
static void setModuleSearchPaths(const std::vector<std::wstring> &paths);
static void addModuleSearchPath(const std::wstring &path);
static std::vector<std::wstring> getModuleSearchPaths();
static std::wstring getPlatformPathSeparator();
};

namespace py_backend {
Expand Down
1 change: 1 addition & 0 deletions docs/en/Interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ such as:
1. `V8` -> `script::v8_interop`
1. `JavaScriptCore` -> `script::jsc_interop`
1. `Lua` -> `script::lua_interop`
1. `Python` -> `script::py_interop`

Mainly provide capabilities:
1. Get the internal native engine instance from the engine pointer
Expand Down
6 changes: 3 additions & 3 deletions docs/en/Python.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ Then you can import these third-party packages and use them in ScriptX's Python

### Customizing CPython runtime settings

A number of static methods are provided in PyEngine to modify some settings, including the path to the standard library zip.
A number of static methods are provided in `script::py_interop` to modify some settings, including the path to the standard library zip.

```c++
class PyEngine
struct py_interop
{
//...

Expand Down Expand Up @@ -104,5 +104,5 @@ class PyEngine
For example, if you want to change the path of the standard library zip to `". /lib/python310.zip"`, you can write the following code.
```C++
PyEngine::setModuleSearchPaths( {"./lib/python310.zip"} );
script::py_interop::setModuleSearchPaths( {"./lib/python310.zip"} );
```
1 change: 1 addition & 0 deletions docs/zh/Interop.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ScriptX提供一些基础的接口,以便和原生引擎API互相操作。
1. `V8` -> `script::v8_interop`
1. `JavaScriptCore` -> `script::jsc_interop`
1. `Lua` -> `script::lua_interop`
1. `Python` -> `script::py_interop`

主要提供能力:
1. 从引擎指针获取内部原生引擎实例
Expand Down
6 changes: 3 additions & 3 deletions docs/zh/Python.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ Python API 提供的执行代码接口分为两种:其中 eval 类型的接口

### 自定义CPython运行时设置

在PyEngine中提供了一系列静态方法,可以对标准库压缩包路径在内的部分设置进行修改:
`script::py_interop`中提供了一系列静态方法,可以对标准库压缩包路径在内的部分设置进行修改:

```c++
class PyEngine
struct py_interop
{
//...

Expand Down Expand Up @@ -102,6 +102,6 @@ class PyEngine
比如,你想把标准库压缩包路径修改为`"./lib/python310.zip"`,可以编写如下代码:
```C++
PyEngine::setModuleSearchPaths( {"./lib/python310.zip"} );
script::py_interop::setModuleSearchPaths( {"./lib/python310.zip"} );
```

0 comments on commit dcfb8a8

Please sign in to comment.