Skip to content

Commit

Permalink
refactor: rename
Browse files Browse the repository at this point in the history
  • Loading branch information
sangjanai committed May 21, 2024
1 parent d586b54 commit b0034ca
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 40 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,15 @@ 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/[email protected]
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
env:
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
4 changes: 2 additions & 2 deletions .github/workflows/quality-gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
20 changes: 10 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,31 +35,31 @@ 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:
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
44 changes: 22 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 `<process.h>` on Windows and `<spawn.h>` on UNIX (Linux and MacOS).
Expand All @@ -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
Expand All @@ -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 ..
Expand All @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/server/server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class Server {
public:
Server() {
dylib_ = std::make_unique<dylib>("./engines/cortex.python-runtime", "engine");
dylib_ = std::make_unique<dylib>("./engines/cortex.python", "engine");
auto func = dylib_->get_function<EngineI*()>("get_engine");
engine_ = func();
}
Expand Down

0 comments on commit b0034ca

Please sign in to comment.