Skip to content

Commit 869311c

Browse files
committed
Added workflow for python
1 parent bafc814 commit 869311c

3 files changed

Lines changed: 69 additions & 0 deletions

File tree

.github/workflows/python.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Python Binding CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-and-verify-python:
11+
runs-on: windows-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Python 3.12
18+
uses: actions/setup-python@v5
19+
with:
20+
python-version: '3.12'
21+
22+
- name: Install pybind11 dependency
23+
run: |
24+
python -m pip install --upgrade pip
25+
pip install pybind11
26+
27+
- name: Add MSBuild to PATH
28+
uses: microsoft/setup-msbuild@v2
29+
30+
- name: Build Python Binding Module
31+
run: msbuild python/neuralnetwork_py.sln /p:Configuration=Release /p:Platform=x64
32+
env:
33+
PYTHON_HOME: ${{ env.pythonLocation }}
34+
35+
- name: Verify Module Import and Functionality
36+
run: python python/import_check.py

python/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This subdirectory contains the Visual Studio 2022 C++ project and code necessary
1111
* `neuralnetwork_py.vcxproj.filters`: Project filters mapping for Solution Explorer organization.
1212
* `neuralnetwork_py.sln`: Main Visual Studio solution.
1313
* `example.py`: Python script illustrating options configuration, model instantiation, callback monitoring, training, inference, and serialization.
14+
* `import_check.py`: A lightweight validation script that verifies the binary module loads, initializes enums, and starts up correctly (used in CI).
1415

1516
---
1617

python/import_check.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
import sys
3+
4+
# Add the directory containing the compiled .pyd module to the import search path
5+
# The module is built in x64/Release by MSBuild in python/x64/Release/
6+
module_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "x64", "Release")
7+
sys.path.append(module_dir)
8+
9+
try:
10+
import neuralnetwork as nn
11+
print("Successfully imported neuralnetwork library!")
12+
print(f"Docstring: {nn.__doc__}")
13+
14+
# Check activation enum and class instantiation
15+
print("Verifying ActivationMethod...")
16+
sigmoid_method = nn.ActivationMethod.Sigmoid
17+
print(f"Sigmoid enum value: {sigmoid_method}")
18+
19+
print("Instantiating Activation class...")
20+
act = nn.Activation(sigmoid_method, 1.0)
21+
print(f"Activation instantiation success: method={act.method}, alpha={act.alpha}")
22+
23+
# Verify Options
24+
print("Verifying NeuralNetworkOptions creation...")
25+
options = nn.NeuralNetworkOptions.create([3, 2, 1])
26+
print("NeuralNetworkOptions created successfully!")
27+
28+
print("All checks passed successfully!")
29+
sys.exit(0)
30+
except Exception as e:
31+
print(f"Verification failed: {e}", file=sys.stderr)
32+
sys.exit(1)

0 commit comments

Comments
 (0)