diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9e2096c..eef47c7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -114,8 +114,8 @@ jobs: - name: Upload Artifact uses: actions/upload-artifact@v2 with: - name: cortex.python-runtime-${{ matrix.os }}-${{ matrix.name }} - path: ./cortex.python-runtime.tar.gz + name: cortex.python-${{ matrix.os }}-${{ matrix.name }} + path: ./cortex.python.tar.gz - uses: actions/upload-release-asset@v1.0.1 if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') @@ -123,6 +123,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ needs.create-draft-release.outputs.upload_url }} - asset_path: ./cortex.python-runtime.tar.gz - asset_name: cortex.python-runtime-${{ needs.create-draft-release.outputs.version }}-${{ matrix.os }}-${{ matrix.name }}.tar.gz + asset_path: ./cortex.python.tar.gz + asset_name: cortex.python-${{ needs.create-draft-release.outputs.version }}-${{ matrix.os }}-${{ matrix.name }}.tar.gz asset_content_type: application/gzip diff --git a/.github/workflows/quality-gate.yml b/.github/workflows/quality-gate.yml index e9c7966..278c5ba 100644 --- a/.github/workflows/quality-gate.yml +++ b/.github/workflows/quality-gate.yml @@ -70,5 +70,5 @@ jobs: - name: Upload Artifact uses: actions/upload-artifact@v2 with: - name: cortex.python-runtime-${{ matrix.os }}-${{ matrix.name }} - path: ./cortex.python-runtime.tar.gz + name: cortex.python-${{ matrix.os }}-${{ matrix.name }} + path: ./cortex.python.tar.gz diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ac5e97..2f17c4b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.5) -project(cortex.python-runtime C CXX) +project(cortex.python C CXX) set(TARGET engine) include(CheckIncludeFileCXX) diff --git a/Makefile b/Makefile index e470ae4..f0da019 100644 --- a/Makefile +++ b/Makefile @@ -35,12 +35,12 @@ endif package: ifeq ($(OS),Windows_NT) - @powershell -Command "mkdir -p cortex.python-runtime; cp build\Release\engine.dll cortex.python-runtime\; cp -r build\python cortex.python-runtime\; 7z a -ttar temp.tar cortex.python-runtime\*; 7z a -tgzip cortex.python-runtime.tar.gz temp.tar;" + @powershell -Command "mkdir -p cortex.python; cp build\Release\engine.dll cortex.python\; cp -r build\python cortex.python\; 7z a -ttar temp.tar cortex.python\*; 7z a -tgzip cortex.python.tar.gz temp.tar;" else - @mkdir -p cortex.python-runtime && \ - cp build/libengine.$(shell uname | tr '[:upper:]' '[:lower:]' | sed 's/darwin/dylib/;s/linux/so/') cortex.python-runtime && \ - cp -r build/python cortex.python-runtime - tar -czvf cortex.python-runtime.tar.gz cortex.python-runtime + @mkdir -p cortex.python && \ + cp build/libengine.$(shell uname | tr '[:upper:]' '[:lower:]' | sed 's/darwin/dylib/;s/linux/so/') cortex.python && \ + cp -r build/python cortex.python + tar -czvf cortex.python.tar.gz cortex.python endif run-e2e-test: @@ -48,18 +48,18 @@ ifeq ($(RUN_TESTS),false) @echo "Skipping tests" else ifeq ($(OS),Windows_NT) - @powershell -Command "mkdir -p .\examples\server\build\Release\engines\cortex.python-runtime; cd examples\server\build\Release; cp ..\..\..\..\build\Release\engine.dll engines\cortex.python-runtime; ..\..\..\..\.github\scripts\e2e-test-server-windows.bat server.exe ..\..\..\..\$(PYTHON_FILE_EXECUTION_PATH);" + @powershell -Command "mkdir -p .\examples\server\build\Release\engines\cortex.python; cd examples\server\build\Release; cp ..\..\..\..\build\Release\engine.dll engines\cortex.python; ..\..\..\..\.github\scripts\e2e-test-server-windows.bat server.exe ..\..\..\..\$(PYTHON_FILE_EXECUTION_PATH);" else - @mkdir -p examples/server/build/engines/cortex.python-runtime && \ + @mkdir -p examples/server/build/engines/cortex.python && \ cd examples/server/build && \ - cp ../../../build/libengine.$(shell uname | tr '[:upper:]' '[:lower:]' | sed 's/darwin/dylib/;s/linux/so/') engines/cortex.python-runtime/ && \ + cp ../../../build/libengine.$(shell uname | tr '[:upper:]' '[:lower:]' | sed 's/darwin/dylib/;s/linux/so/') engines/cortex.python/ && \ chmod +x ../../../.github/scripts/e2e-test-server-linux-and-mac.sh && ../../../.github/scripts/e2e-test-server-linux-and-mac.sh ./server ../../../$(PYTHON_FILE_EXECUTION_PATH) endif endif clean: ifeq ($(OS),Windows_NT) - cmd /C "rmdir /S /Q build examples\\server\\build cortex.python-runtime cortex.python-runtime.tar.gz cortex.python-runtime.zip" + cmd /C "rmdir /S /Q build examples\\server\\build cortex.python cortex.python.tar.gz cortex.python.zip" else - rm -rf build examples/server/build cortex.python-runtime cortex.python-runtime.tar.gz cortex.python-runtime.zip + rm -rf build examples/server/build cortex.python cortex.python.tar.gz cortex.python.zip endif diff --git a/README.md b/README.md index 46a6368..0a9faed 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# cortex.python-runtime +# cortex.python **Python embedding on C++** Each python execution request will create a new child process for python runtime by using `` on Windows and `` on UNIX (Linux and MacOS). @@ -8,13 +8,13 @@ Each python execution request will create a new child process for python runtime ### Linux and MacOS 1. Install dependencies: ```bash -# In cortex.python-runtime/ root dir +# In cortex.python/ root dir ./install_deps.sh ``` 2. Build the project ```bash -# In cortex.python-runtime/ root dir +# In cortex.python/ root dir mkdir build && cd build cmake .. make -j32 @@ -23,14 +23,14 @@ make -j32 ### Windows (testing) 1. Install dependencies ```powershell -# In cortex.python-runtime\ root dir +# In cortex.python\ root dir cmake -S ./third-party -B ./build_deps/third-party cmake --build ./build_deps/third-party --config Release ``` 2. Build the project ```powershell -# In cortex.python-runtime\ root dir +# In cortex.python\ root dir mkdir -p build cd build cmake .. @@ -47,11 +47,11 @@ Go to the `.../build/` directory. While running the python-runtime with no argument, it will use the default `.../build/python/` library ``` -~/cortex.python-runtime/build$ ./python-runtime +~/cortex.python/build$ ./python-runtime ``` Or, you can use your desired Python3 version by adding a path to the directory that contain the `libpython***.so` or `libpython***.dylib` file. ``` -~/cortex.python-runtime/build$ ./python-runtime {PATH_TO_DYNAMIC_LIB_DIR} +~/cortex.python/build$ ./python-runtime {PATH_TO_DYNAMIC_LIB_DIR} ``` Then input the path to your Python file that need to be executed. You can input **multiple times**, each input will create a new child process for Python runtime. @@ -75,7 +75,7 @@ Then input the path to your Python file that need to be executed. You can input Updating... 🙏 ### Linux ```bash -# In cortex.python-runtime/ root dir +# In cortex.python/ root dir cd ./build/python/ export PYTHONHOME=$(pwd) ./bin/python3 -m ensurepip @@ -104,37 +104,37 @@ print("Hello from Cortex!") ``` # Default library -~/cortex.python-runtime/build$ ./python-runtime +~/cortex.python/build$ ./python-runtime python-runtime started /home/jan/cortex/main.py Created child process for Python embedding -No specified Python library path, using default Python library in /home/jan/cortex.python-runtime/build/python/ -Found dynamic library file /home/jan/cortex.python-runtime/build/python/libpython3.10.so.1.0 -Successully loaded Python dynamic library from file: /home/jan/cortex.python-runtime/build/python/libpython3.10.so.1.0 +No specified Python library path, using default Python library in /home/jan/cortex.python/build/python/ +Found dynamic library file /home/jan/cortex.python/build/python/libpython3.10.so.1.0 +Successully loaded Python dynamic library from file: /home/jan/cortex.python/build/python/libpython3.10.so.1.0 Trying to run Python file in path /home/jan/cortex/main.py -/home/jan/cortex.python-runtime/build/python/lib/python/site-packages/ -/home/jan/cortex.python-runtime/build/python/lib/python/lib-dynload/ -/home/jan/cortex.python-runtime/build/python/lib/python/ +/home/jan/cortex.python/build/python/lib/python/site-packages/ +/home/jan/cortex.python/build/python/lib/python/lib-dynload/ +/home/jan/cortex.python/build/python/lib/python/ Hello from Cortex! /home/jan/cortex/main.py Created child process for Python embedding -No specified Python library path, using default Python library in /home/jan/cortex.python-runtime/build/python/ -Found dynamic library file /home/jan/cortex.python-runtime/build/python/libpython3.10.so.1.0 -Successully loaded Python dynamic library from file: /home/jan/cortex.python-runtime/build/python/libpython3.10.so.1.0 +No specified Python library path, using default Python library in /home/jan/cortex.python/build/python/ +Found dynamic library file /home/jan/cortex.python/build/python/libpython3.10.so.1.0 +Successully loaded Python dynamic library from file: /home/jan/cortex.python/build/python/libpython3.10.so.1.0 Trying to run Python file in path /home/jan/cortex/main.py -/home/jan/cortex.python-runtime/build/python/lib/python/site-packages/ -/home/jan/cortex.python-runtime/build/python/lib/python/lib-dynload/ -/home/jan/cortex.python-runtime/build/python/lib/python/ +/home/jan/cortex.python/build/python/lib/python/site-packages/ +/home/jan/cortex.python/build/python/lib/python/lib-dynload/ +/home/jan/cortex.python/build/python/lib/python/ Hello from Cortex! ``` ``` # With specific python version -~/cortex.python-runtime/build$ ./python-runtime /usr/lib/python3.10/config-3.10-x86_64-linux-gnu/ +~/cortex.python/build$ ./python-runtime /usr/lib/python3.10/config-3.10-x86_64-linux-gnu/ python-runtime started /home/jan/cortex/main.py diff --git a/examples/server/server.cc b/examples/server/server.cc index 99d6fc6..65b206c 100644 --- a/examples/server/server.cc +++ b/examples/server/server.cc @@ -15,7 +15,7 @@ class Server { public: Server() { - dylib_ = std::make_unique("./engines/cortex.python-runtime", "engine"); + dylib_ = std::make_unique("./engines/cortex.python", "engine"); auto func = dylib_->get_function("get_engine"); engine_ = func(); }