-
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.
- Loading branch information
0 parents
commit d705ca1
Showing
15 changed files
with
836 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,10 @@ | ||
.git | ||
.vscode | ||
|
||
build | ||
|
||
dist | ||
wheelhouse | ||
structura.egg-info | ||
|
||
MANIFEST |
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,22 @@ | ||
project(Structura) | ||
set(CMAKE_C_STANDARD 99) | ||
cmake_minimum_required(VERSION 3.0) | ||
|
||
add_subdirectory(src) | ||
include_directories(include) | ||
|
||
|
||
find_package(Python REQUIRED COMPONENTS Interpreter Development) | ||
include_directories(${Python_INCLUDE_DIRS}) | ||
|
||
include_directories(/usr/include/python3.8) | ||
|
||
add_library(_structura SHARED src/ringbuffer.c src/structura.c src/stack.c) | ||
|
||
set_target_properties( | ||
structura | ||
PROPERTIES | ||
PREFIX "" | ||
OUTPUT_NAME "structura" | ||
LINKER_LANGUAGE C | ||
) |
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 @@ | ||
MIT License | ||
|
||
Copyright (c) 2023 Alperen Serkan Aksöz | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,52 @@ | ||
Structura | ||
===================================== | ||
|
||
.. image:: https://github.com/sekomer/structura/workflows/Tests/badge.svg | ||
:alt: Structura build status on GitHub Actions | ||
:target: https://github.com/sekomer/structura/actions | ||
|
||
|
||
| | ||
.. contents:: | ||
|
||
|
||
.. highlight:: bash | ||
|
||
Installation | ||
------------ | ||
From The Python Package Index | ||
|
||
``pip install structura`` | ||
|
||
|
||
General Information | ||
------------------- | ||
- Source code: https://github.com/sekomer/structura | ||
- Documentation: [ TODO ] | ||
|
||
Contributing | ||
------------ | ||
All contributions, suggestions, and optimization ideas are welcome! | ||
|
||
Using Structura | ||
------------ | ||
[ TODO ] | ||
|
||
Build Instructions | ||
------------------ | ||
To build `structura` from source, you should clone the repo and run the following command | ||
|
||
``sudo python3 setup.py install`` | ||
|
||
What's New | ||
---------- | ||
Ring buffers have been added. | ||
|
||
What's Coming | ||
------------- | ||
Linked Lists, Queues, Stacks, Hash Tables, Trees. | ||
|
||
Proposals for enhancement | ||
------------------------- | ||
You can create an issue or mail me at [email protected] |
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,43 @@ | ||
function check_error { | ||
if [ $1 -ne 0 ]; then | ||
echo "Error: $2" | ||
sudo kill -9 $$ | ||
fi | ||
} | ||
|
||
# clean up | ||
sudo rm -rf dist wheelhouse | ||
check_error $? "Cleanup failed" | ||
|
||
# build | ||
sudo python setup.py install sdist bdist_wheel | ||
check_error $? "Build failed" | ||
|
||
# manylinux | ||
auditwheel repair dist/*.whl | ||
check_error $? "auditwheel failed" | ||
|
||
# remove wheel other than manylinux | ||
sudo rm dist/*.whl | ||
check_error $? "Failed to remove wheel" | ||
|
||
# copy manylinux to dist | ||
sudo cp wheelhouse/*.whl dist/ | ||
check_error $? "Failed to copy manylinux to dist" | ||
|
||
# remove wheelhouse | ||
sudo rm -rf wheelhouse | ||
check_error $? "Failed to remove wheelhouse" | ||
|
||
# upload if --upload is specified | ||
if [ "$1" == "--upload" ]; then | ||
sudo twine upload dist/* | ||
check_error $? "Failed to upload package" | ||
fi | ||
|
||
|
||
# run tests | ||
for file in test/*.py; do | ||
sudo python $file | ||
check_error $? "Failed to run $file" | ||
done |
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,18 @@ | ||
#ifndef RINGBUFFER_H | ||
#define RINGBUFFER_H | ||
|
||
#include <Python.h> | ||
|
||
extern PyTypeObject RingBufferType; | ||
|
||
typedef struct | ||
{ | ||
PyObject_HEAD; | ||
long capacity; | ||
long size; | ||
long head; | ||
long tail; | ||
PyObject **items; | ||
} RingBuffer; | ||
|
||
#endif /* RINGBUFFER_H */ |
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,17 @@ | ||
#ifndef STACK_H | ||
#define STACK_H | ||
|
||
#include <Python.h> | ||
|
||
extern PyTypeObject StackType; | ||
|
||
typedef struct | ||
{ | ||
PyObject_HEAD; | ||
long top; | ||
long size; | ||
long capacity; | ||
PyObject **items; | ||
} Stack; | ||
|
||
#endif /* STACK_H */ |
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,29 @@ | ||
import os | ||
import setuptools | ||
from distutils.core import setup, Extension | ||
|
||
|
||
module = Extension( | ||
"structura", | ||
# list comprehension to get all .c files in the src directory | ||
sources=[ | ||
f"./src/{file}" for file in os.listdir("./src") if file.endswith(".c")], | ||
include_dirs=['./include'], # list of directories containing header files | ||
) | ||
|
||
|
||
def main(): | ||
setup(name="structura", | ||
version="0.1.2", | ||
description="C extension module for common data structures", | ||
author="alperen serkan aksoz", | ||
author_email="[email protected]", | ||
url="https://github.com/sekomer/structura", | ||
license="MIT", | ||
ext_modules=[module], | ||
platforms=['manylinux1_x86_64'] | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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,26 @@ | ||
cmake_minimum_required(VERSION 3.0) | ||
|
||
project(Structura) | ||
|
||
set(CMAKE_C_STANDARD 99) | ||
|
||
include_directories(${PROJECT_SOURCE_DIR}/include) | ||
|
||
# Add all the source files | ||
set(SOURCES | ||
structura.c | ||
ringbuffer.c | ||
stack.c | ||
) | ||
|
||
# add headers from include directory | ||
file(GLOB HEADERS ${PROJECT_SOURCE_DIR}/include/*.h) | ||
|
||
|
||
# Create a library with all the source files | ||
add_library(structura ${SOURCES} ${HEADERS}) | ||
|
||
# Link the Python library | ||
find_package(Python REQUIRED COMPONENTS Interpreter Development) | ||
target_include_directories(structura PUBLIC ${Python_INCLUDE_DIRS}) | ||
target_link_libraries(structura ${Python_LIBRARIES}) |
Oops, something went wrong.