diff --git a/.gitignore b/.gitignore index 3dbc524eccbea836c2a47f0a28549e658149cc35..fa3d541cb1750b471a3251bb24fcb32dcdd817fb 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 feba3c28f3b26157d36feba77a27c8374aeb15bf..b4f040ec2ad66772a06f5a2026642f18b93278e2 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 0000000000000000000000000000000000000000..77da452414aad1e3470d99bf26627ab43417dc04 --- /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 ad159837b23aab7aa0ca80f4c61c77ffcb9502da..45579e8f52c513f07242bc58c5bbac69fa90555a 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 70db3117f0b819aca58883e4ffeac974325cea37..29fcd98a06327644c064bd040def06b67dfb5c67 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 0000000000000000000000000000000000000000..a511066d49471ba9d91b94fb54996e418680c89e --- /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 0000000000000000000000000000000000000000..b03c01152c0bbc326d64e2d8981a8baf561e7290 --- /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 b9e88ef445805e70d7b7af5275c166f408f5c2a1..ac57f4d215e8c54d95eb98953e8927fd0551c06c 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 5d8dbc19e991b7c53a2e78272271ab3c8d111166..b60c3cfe0144c6d56a4c1277ffc1131b7b11a3a2 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 56bf6415a4a9977a97bca70a94aa7df2af4464a6..cb28f68678751ddfd239dec15455ddccf71e3b2a 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 1037108e1e6e79d497be3eaac53a8e81f8412e29..203e2a939cbfa3c903a06eff41e0f04b509a1b01 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 bf484c0ba7868d43fd6789bae10ebb4624e4469b..40c1e2d24571c7317082f26a2b463b4583477b23 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 ea106eae4f4196574dd24052d3d52a704c60e7e8..559ffde3ec7b137f732658cd3fc6507680cfb8ad 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):]