From 9d794e78d5dea1d0846ce7823e4f0e34ca74a2d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Wed, 18 Mar 2020 16:18:01 +0100 Subject: [PATCH] Feature/pypy (#2) * try with pypy3.5 and python 3.6 and python 3.5 * add python 3.3 and 3.4 * allow standard C files * add python 3.4 * spelling mistake * add changelog * add changelog * v1.0.1 --- .gitignore | 3 +-- .travis.yml | 2 ++ CHANGELOG.md | 4 ++++ README.md | 5 ++++- example/example_module/test2.pyx | 7 +++++++ example/example_module/test_n.c | 3 +++ example/example_module/test_n.h | 1 + example/setup.py | 3 ++- example/tests/test_test.py | 5 ++++- setup.cfg | 2 ++ setup.py | 2 +- snakehouse/__init__.py | 2 +- snakehouse/multibuild.py | 13 +++++++++---- 13 files changed, 41 insertions(+), 11 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 example/example_module/test_n.c create mode 100644 example/example_module/test_n.h diff --git a/.gitignore b/.gitignore index 3dbc524..fa3d541 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ *.pyc -*.c *.pyd .idea/ *.egg-info @@ -8,4 +7,4 @@ build */dist dist .eggs -*.h + diff --git a/.travis.yml b/.travis.yml index feba3c2..b4f040e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,7 @@ language: python python: + - "3.5" + - "3.6" - "3.7" - "3.8" - "nightly" diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..77da452 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,4 @@ +# v1.0.1 + +* standard C files will be allowed in the builds +* added support for Pythons 3.5-3.6 diff --git a/README.md b/README.md index ad15983..45579e8 100644 --- a/README.md +++ b/README.md @@ -10,12 +10,15 @@ into a single extension. Inspired by [this StackOverflow discussion](https://stackoverflow.com/questions/30157363/collapse-multiple-submodules-to-one-cython-extension). -Tested and works on CPython 3.8 and CPython 3.7, +Tested and works on CPython 3.5-3.9, both Windows and [Linux](https://travis-ci.org/github/smok-serwis/snakehouse). +It doesn't work on PyPy. Contributions most welcome! If you contribute, feel free to attach a change to [CONTRIBUTORS.md](/CONTRIBUTORS.md) as a part of your pull request as well! +Note what have you changed in +[CHANGELOG.md](/CHANGELOG.md) as well! Usage ----- diff --git a/example/example_module/test2.pyx b/example/example_module/test2.pyx index 70db311..29fcd98 100644 --- a/example/example_module/test2.pyx +++ b/example/example_module/test2.pyx @@ -1,2 +1,9 @@ +cdef extern from "test_n.h": + float _times_five(float) + + +def times_five(x): + return _times_five(x) + def times_three(x): return x*3 diff --git a/example/example_module/test_n.c b/example/example_module/test_n.c new file mode 100644 index 0000000..a511066 --- /dev/null +++ b/example/example_module/test_n.c @@ -0,0 +1,3 @@ +float _times_five(float v) { + return v*5; +} \ No newline at end of file diff --git a/example/example_module/test_n.h b/example/example_module/test_n.h new file mode 100644 index 0000000..b03c011 --- /dev/null +++ b/example/example_module/test_n.h @@ -0,0 +1 @@ +float _times_five(float); diff --git a/example/setup.py b/example/setup.py index b9e88ef..ac57f4d 100644 --- a/example/setup.py +++ b/example/setup.py @@ -4,7 +4,8 @@ from snakehouse import Multibuild, build cython_multibuilds = [ Multibuild('example_module', ['example_module/test.pyx', 'example_module/test2.pyx', - 'example_module/test3/test3.pyx']) + 'example_module/test3/test3.pyx', + 'example_module/test_n.c']) ] # first argument is used directly by snakehouse, the rest and **kwargs are passed to diff --git a/example/tests/test_test.py b/example/tests/test_test.py index 5d8dbc1..b60c3cf 100644 --- a/example/tests/test_test.py +++ b/example/tests/test_test.py @@ -1,10 +1,13 @@ from example_module.test import times_two -from example_module.test2 import times_three +from example_module.test2 import times_three, times_five from example_module.test3.test3 import times_four import unittest class TestExample(unittest.TestCase): + def test_five(self): + self.assertEqual(times_five(2), 10) + def test_two(self): self.assertEqual(times_two(2), 4) diff --git a/setup.cfg b/setup.cfg index 56bf641..cb28f68 100644 --- a/setup.cfg +++ b/setup.cfg @@ -13,6 +13,8 @@ project-urls = Issue tracker = https://github.com/smok-serwis/snakehouse/issues classifier = Programming Language :: Python + Programming Language :: Python :: 3.5 + Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 diff --git a/setup.py b/setup.py index 1037108..203e2a9 100644 --- a/setup.py +++ b/setup.py @@ -8,5 +8,5 @@ setup(keywords=['cython', 'extension', 'multiple', 'pyx'], install_requires=[ 'Cython' ], - python_requires='!=2.7.*,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*', + python_requires='!=2.7.*,!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*', ) diff --git a/snakehouse/__init__.py b/snakehouse/__init__.py index bf484c0..40c1e2d 100644 --- a/snakehouse/__init__.py +++ b/snakehouse/__init__.py @@ -1,4 +1,4 @@ from .build import build from .multibuild import Multibuild -__version__ = '1.0.0' +__version__ = '1.0.1' diff --git a/snakehouse/multibuild.py b/snakehouse/multibuild.py index ea106ea..559ffde 100644 --- a/snakehouse/multibuild.py +++ b/snakehouse/multibuild.py @@ -1,23 +1,28 @@ -import typing as tp import os from setuptools import Extension class Multibuild: - def __init__(self, extension_name: str, files: tp.Iterable[str]): + def __init__(self, extension_name: str, files): + """ + :param extension_name: the module name + :param files: list of pyx and c files + """ self.files = list([file for file in files if not file.endswith('__bootstrap__.pyx')]) file_name_set = set(os.path.split(file)[1] for file in self.files) if len(self.files) != len(file_name_set): raise ValueError('Two modules with the same name cannot appear together in a single ' 'Multibuild') + self.sane_files = [file for file in files if file.endswith('.pyx')] + self.extension_name = extension_name self.bootstrap_directory = os.path.commonpath(self.files) self.modules = set() # tp.Set[tp.Tuple[str, str]] def generate_header_files(self): - for filename in self.files: + for filename in self.sane_files: path, name = os.path.split(filename) if not name.endswith('.pyx'): continue @@ -55,7 +60,7 @@ cdef extern from "Python.h": int PyModule_ExecDef(object module, PyModuleDef* definition) """] - for filename in self.files: + for filename in self.sane_files: path, name = os.path.split(filename) if path.startswith(self.bootstrap_directory): path = path[len(self.bootstrap_directory):] -- GitLab