-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/ms3c/numlib
- Loading branch information
Showing
2 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: C/C++ CI | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: build shared library | ||
run: make | ||
- name: run tests | ||
run: make check | ||
- name: make distcheck | ||
run: make distcheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# addnums | ||
|
||
This is a simple tutorial on how to write python extension in C through a process called "wrapping" or creating a Python extension module. | ||
## Installation | ||
|
||
Use the package manager [pip](https://pip.pypa.io/en/stable/) to install python-config and apt for installing python3-dev. | ||
|
||
```bash | ||
pip install python-config | ||
sudo apt-get install python3-dev | ||
``` | ||
|
||
## Compiling the shared library | ||
|
||
To compile this you will need the GNU C compiler Collection [gcc](https://gcc.gnu.org/) | ||
|
||
```bash | ||
sudo apt-get install build-essential gcc | ||
|
||
gcc add.c $(python3-config --includes) -shared -fPIC -o addnums.so | ||
|
||
OR | ||
|
||
gcc -o addnums.so -shared -fPIC add.c -I/path/to/python/include -lpython3.x | ||
``` | ||
## Usage | ||
|
||
```python | ||
import addnums # make sure you are in same directory as addnums.so | ||
result = addnums.add_numbers(5, 4) | ||
print(result) # Output: 9 | ||
``` | ||
|
||
## Distributing the package | ||
|
||
```plaintext | ||
addnums/ | ||
├── addnums.so | ||
├── add.c | ||
├── add.py | ||
└── setup.py | ||
``` | ||
```python | ||
from setuptools import setup, Extension | ||
|
||
setup( | ||
name='addnums', | ||
version='1.0', | ||
ext_modules=[Extension('addnums', ['addnums.so'])], | ||
packages=['addnums'], | ||
license='GPL', | ||
long_description=open('README.md').read(), | ||
) | ||
|
||
``` | ||
```bash | ||
python3 setup.py bdist_wheel | ||
|
||
``` |