feat: Added ability to change entry point name
+ Renamed default entry point name + Added proper exception handling + Added ability to use .pth files
This commit is contained in:
15
CHANGELOG.md
15
CHANGELOG.md
@@ -1,13 +1,6 @@
|
|||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
- Updated project structure and CMake settings (read more at build specific changes)
|
- Renamed entry point module to ``pyg2o_entry``
|
||||||
- Revised unpredicted behavior ``All player getters on both sides will now return null if player isn't created/spawned``: these getters should return an empty string if player isn't created/spawned
|
- Added option to change entry point name (read more: <link>)
|
||||||
|
- Added ability to connect additional package folders (read: use virtual environments), read more: <link>
|
||||||
### Build specific changes
|
- Added proper exception handling on the module loading time
|
||||||
|
|
||||||
- Project has been split into separate logical directories (docs, python, build, source)
|
|
||||||
- Added LICENSE (usual free software license)
|
|
||||||
- CMake config was split to logical files for better readabilty
|
|
||||||
- Added README.md and LICENSE for NoNut directory
|
|
||||||
- Removed unused toolchain files and build presets
|
|
||||||
- Added short ``How to build`` section to README.md
|
|
||||||
@@ -7,9 +7,9 @@
|
|||||||
```xml
|
```xml
|
||||||
<module src="PyG2O.x64.dll" type="server" />
|
<module src="PyG2O.x64.dll" type="server" />
|
||||||
```
|
```
|
||||||
4. Create **scripts/** folder in your server root directory, and put an empty ``__init__.py`` file inside it
|
4. Create **pyg2o_entry/** folder in your server root directory, and put an empty ``__init__.py`` file inside it
|
||||||
|
|
||||||
Now, your **scripts/** folder is a Python package and serves as an entry point. You can't rename it (at least for now), but inside this folder you can use any file structure you want.
|
Now, your **pyg2o_entry/** folder is a Python package and serves as an entry point. You can't rename it (at least for now), but inside this folder you can use any file structure you want.
|
||||||
|
|
||||||
Your entry point should import PyG2O library:
|
Your entry point should import PyG2O library:
|
||||||
```python
|
```python
|
||||||
@@ -18,5 +18,17 @@ import g2o
|
|||||||
```
|
```
|
||||||
If you make package that uses PyG2O functions, then this package also should also contain import.
|
If you make package that uses PyG2O functions, then this package also should also contain import.
|
||||||
|
|
||||||
|
## How to change entry point name
|
||||||
|
1. Create ``pyg2o.json`` in your root server folder
|
||||||
|
2. Place this content in it and change entry point name
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"entry": "your_entry_name"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## How to add additional packages folder (use virtual environment)
|
||||||
|
You can create ``.pth`` file in your root server folder and it will be added to your ``sys.path`` before entry point
|
||||||
|
|
||||||
## Examples
|
## Examples
|
||||||
You can find default (example) scripts in [this repository](https://github.com/AURUMVORXX/PyG2O-DefaultScripts)
|
You can find default (example) scripts in [this repository](https://github.com/AURUMVORXX/PyG2O-DefaultScripts)
|
||||||
@@ -6,7 +6,6 @@ namespace py = pybind11;
|
|||||||
using namespace pybind11::literals;
|
using namespace pybind11::literals;
|
||||||
|
|
||||||
extern py::module_ g2o;
|
extern py::module_ g2o;
|
||||||
extern py::module_ pysys;
|
|
||||||
|
|
||||||
void addEventHandler(const char* eventName, SQFUNCTION closure, unsigned int priority = 9999)
|
void addEventHandler(const char* eventName, SQFUNCTION closure, unsigned int priority = 9999)
|
||||||
{
|
{
|
||||||
@@ -40,7 +39,7 @@ void callEvent(const char* eventName, py::dict kwargs)
|
|||||||
}
|
}
|
||||||
catch (py::error_already_set &e)
|
catch (py::error_already_set &e)
|
||||||
{
|
{
|
||||||
pysys.attr("stderr").attr("write")(e.what());
|
py::print(e.what());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,7 @@
|
|||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
py::scoped_interpreter guard{};
|
py::scoped_interpreter guard{};
|
||||||
|
|
||||||
py::module_ pysys = py::module_::import("sys");
|
|
||||||
py::module_ g2o;
|
py::module_ g2o;
|
||||||
py::module_ scripts;
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
system("pause");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api)
|
extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api)
|
||||||
{
|
{
|
||||||
@@ -25,16 +17,38 @@ extern "C" SQRESULT SQRAT_API sqmodule_load(HSQUIRRELVM vm, HSQAPI api)
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
registerSquirrelConstants();
|
registerSquirrelConstants();
|
||||||
registerSquirrelEvents();
|
|
||||||
|
py::exec(R"(
|
||||||
|
import site
|
||||||
|
import json
|
||||||
|
import importlib
|
||||||
|
|
||||||
|
venv_path = 'test_venv/Lib/site-packages'
|
||||||
|
site.addsitedir('.')
|
||||||
|
|
||||||
|
entry_point = 'pyg2o_entry'
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open('pyg2o.json', 'r') as f:
|
||||||
|
json = json.loads(f.read())
|
||||||
|
entry_point = json['entry']
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
importlib.import_module(entry_point)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
)");
|
||||||
|
|
||||||
g2o = py::module_::import("g2o");
|
g2o = py::module_::import("g2o");
|
||||||
scripts = py::module_::import("scripts");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (py::error_already_set &e)
|
catch (py::error_already_set &e)
|
||||||
{
|
{
|
||||||
pysys.attr("stderr").attr("write")(e.what());
|
py::print(e.what());
|
||||||
|
return SQ_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
registerSquirrelEvents();
|
||||||
return SQ_OK;
|
return SQ_OK;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user