Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/ms3c/numlib
Browse files Browse the repository at this point in the history
  • Loading branch information
ms3c committed Jan 1, 2024
2 parents 129c953 + eeff38c commit 5b3e9be
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/c-cpp.yml
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
60 changes: 60 additions & 0 deletions README.md
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

```

0 comments on commit 5b3e9be

Please sign in to comment.