diff --git a/path_properties.py b/path_properties.py index e0b201c..271b46d 100644 --- a/path_properties.py +++ b/path_properties.py @@ -698,6 +698,7 @@ path_properties_tuples = ( 'libs': ( {'requires_dynamic_library': True}, { + 'cython': {'no_build': True}, 'libdrm': {'requires_sudo': True}, 'hdf5': ( {}, diff --git a/requirements.txt b/requirements.txt index a56d1bf..6fcb625 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ +Cython==0.29.15 pexpect==4.6.0 diff --git a/userland/libs/cython/helloworld.pyx b/userland/libs/cython/helloworld.pyx new file mode 100644 index 0000000..ad35e5a --- /dev/null +++ b/userland/libs/cython/helloworld.pyx @@ -0,0 +1 @@ +print("Hello World") diff --git a/userland/libs/cython/main.py b/userland/libs/cython/main.py new file mode 100755 index 0000000..9cd99eb --- /dev/null +++ b/userland/libs/cython/main.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python3 + +import helloworld +import primes + +print(primes.primes(4)) diff --git a/userland/libs/cython/primes.pyx b/userland/libs/cython/primes.pyx new file mode 100644 index 0000000..96ecdb5 --- /dev/null +++ b/userland/libs/cython/primes.pyx @@ -0,0 +1,23 @@ +def primes(int nb_primes): + cdef int n, i, len_p + cdef int p[1000] + if nb_primes > 1000: + nb_primes = 1000 + + len_p = 0 # The current number of elements in p. + n = 2 + while len_p < nb_primes: + # Is n prime? + for i in p[:len_p]: + if n % i == 0: + break + + # If no break occurred in the loop, we have a prime. + else: + p[len_p] = n + len_p += 1 + n += 1 + + # Let's return the result in a python list: + result_as_list = [prime for prime in p[:len_p]] + return result_as_list diff --git a/userland/libs/cython/setup.py b/userland/libs/cython/setup.py new file mode 100644 index 0000000..a1ea613 --- /dev/null +++ b/userland/libs/cython/setup.py @@ -0,0 +1,6 @@ +from distutils.core import setup +from Cython.Build import cythonize + +setup( + ext_modules = cythonize(['*.pyx']), +) diff --git a/userland/libs/cython/test b/userland/libs/cython/test new file mode 100755 index 0000000..5c41298 --- /dev/null +++ b/userland/libs/cython/test @@ -0,0 +1,4 @@ +#!/usr/bin/env bash +set -eux +python3 setup.py build_ext --inplace +./main.py