Commit b1628e1e authored by Xavier Thompson's avatar Xavier Thompson

Add helloworld.pyx demo

parent e8e83de2
%.so: %.pyx
python3 setup.py build_ext --inplace $* && mv $*.*.so $@
%: %.so
@echo ">>> import $@" && python3 -c "import $@"
clean:
rm -rf build
rm -rf *.cpp *.c
rm -rf *.so
.PHONY: clean
.PRECIOUS: %.so
.SUFFIXES:
from stdlib.string cimport Str
from libc.stdio cimport puts
def main():
with nogil:
hello = Str("hello")
world = Str("world")
hello_world = hello + world
puts(Str.to_c_str(hello_world))
hello_again = hello_world.substr(0, 5)
puts(Str.to_c_str(hello_again))
world_again = hello_world.substr(5, 10)
puts(Str.to_c_str(world_again))
main()
from distutils.core import setup
from distutils.extension import Extension
from Cython.Build import cythonize
import sys
src = sys.argv[-1]
sys.argv[:] = sys.argv[:-1]
extensions = [
Extension(
src,
language='c++',
sources=[src + '.pyx'],
extra_compile_args=['-std=c++17'],
)
]
setup(
ext_modules = cythonize(extensions)
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment