diff --git a/README.markdown b/README.markdown index cfc1273..5beded8 100644 --- a/README.markdown +++ b/README.markdown @@ -13,7 +13,7 @@ The goal of `pybloomfiltermmap3` is simple: to provide a fast, simple, scalable, ## Quickstart After you install, the interface to use is a cross between a file -interface and a ste interface. As an example: +interface and an ste interface. As an example: ```python >>> import pybloomfilter >>> fruit = pybloomfilter.BloomFilter(100000, 0.1, '/tmp/words.bloom') @@ -26,24 +26,25 @@ interface and a ste interface. As an example: True ``` -To create an in-memory filter, ditch the file location. +To create an in-memory filter, simply omit the file location: ```python >>> cakes = pybloomfilter.BloomFilter(10000, 0.1) ``` -*Caveates*: It is currently not possible to persist this filter later. +*Caveat*: It is currently not possible to persist this filter later. + ## Docs -Follow the *official* docs for `pybloomfiltermmap`. http://axiak.github.io/pybloomfiltermmap/ +Follow the *official* docs for `pybloomfiltermmap` at: http://axiak.github.io/pybloomfiltermmap/ + ## Install -Please have `Cython` installed. Please note that this version is **specifically** meant for Python 3. In case you need Python 2, please see https://github.com/axiak/pybloomfiltermmap. +Please note that this version is **specifically** meant for Python 3. In case you need Python 2, please see https://github.com/axiak/pybloomfiltermmap. To install: ```shell - $ pip install cython $ pip install pybloomfiltermmap3 ``` @@ -54,3 +55,9 @@ and you should be set. See the LICENSE file. It's under the MIT License. + +## Contributions and development + +When contributing, you should set up an appropriate Python 3 environment and install the dependencies listed in `requirements-dev.txt`. +This package depends on generation of `pybloomfilter.c` and requires Cython to be packaged. + diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..2f781c4 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1 @@ +Cython==0.29.13 \ No newline at end of file diff --git a/setup.py b/setup.py index f6fd9c2..e10f634 100644 --- a/setup.py +++ b/setup.py @@ -3,65 +3,71 @@ from setuptools import setup, Extension -try: - from Cython.Distutils import build_ext -except ImportError: - print("""Cannot find Cython! - Cython is required to correctly build pyBloomFilter's C extensions. - In most cases, running the following command should be sufficient: - $ pip install Cython - - Exception: ImportError - """) - exit() +if sys.version_info[0] < 3: + raise SystemError("This package is for Python version 3 and above.") here = os.path.dirname(__file__) + # Get the long description from the README file -with open(os.path.join(here, 'README.markdown'), encoding='utf-8') as fp: - long_description = fp.read() +with open(os.path.join(here, "README.markdown"), encoding="utf-8") as fp: + long_description = fp.read() +setup_kwargs = {} ext_files = [ - 'src/mmapbitarray.c', - 'src/bloomfilter.c', - 'src/md5.c', - 'src/primetester.c', - 'src/MurmurHash3.c', - 'src/pybloomfilter.pyx' + "src/mmapbitarray.c", + "src/bloomfilter.c", + "src/md5.c", + "src/primetester.c", + "src/MurmurHash3.c", ] -print("info: Building from Cython") +# Branch out based on `--no-cython` in `argv`. +# Assume `--cython` as default to avoid having to deal with both params being there. -ext_modules = [ - Extension("pybloomfilter", ext_files, libraries=['crypto']) -] +if "--no-cython" in sys.argv: + # Use the distributed `pybloomfilter.c`. + # Note that we let the exception bubble up if `pybloomfilter.c` doesn't exist. + ext_files.append("src/pybloomfilter.c") + sys.argv.remove("--no-cython") +else: + # Cythonize `pybloomfilter.pyx` + try: + from Cython.Distutils import build_ext + except ModuleNotFoundError: + print( + "Cython module not found. Hint: to build pybloomfilter using the distributed " + "source code, run 'python setup.py install --no-cython'." + ) + sys.exit(1) -if sys.version_info[0] < 3: - raise SystemError('This Package is for Python Version 3 and above.') + ext_files.append("src/pybloomfilter.pyx") + setup_kwargs["cmdclass"] = {"build_ext": build_ext} + +ext_modules = [Extension("pybloomfilter", ext_files)] setup( - name='pybloomfiltermmap3', - version="0.4.19", - author="Michael Axiak, Rob Stacey, Prashant Sinha", - author_email="prashant@noop.pw", - url="https://github.com/prashnts/pybloomfiltermmap3", - description="A Bloom filter (bloomfilter) for Python 3 built on mmap", - long_description=long_description, - long_description_content_type='text/markdown', - license="MIT License", - test_suite='tests.test_all', - install_requires=['Cython'], - ext_modules=ext_modules, - classifiers=[ - 'Development Status :: 4 - Beta', - 'Intended Audience :: Developers', - 'Intended Audience :: Science/Research', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: C', - 'Programming Language :: Cython', - 'Programming Language :: Python', - 'Programming Language :: Python :: 3', - 'Topic :: Software Development :: Libraries :: Python Modules', - ], - cmdclass={'build_ext': build_ext} + name="pybloomfiltermmap3", + version="0.4.19", + author="Michael Axiak, Rob Stacey, Prashant Sinha", + author_email="prashant@noop.pw", + url="https://github.com/prashnts/pybloomfiltermmap3", + description="A fast implementation of Bloom filter for Python 3 built on mmap", + long_description=long_description, + long_description_content_type="text/markdown", + license="MIT License", + test_suite="tests.test_all", + ext_modules=ext_modules, + classifiers=[ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "Intended Audience :: Science/Research", + "License :: OSI Approved :: MIT License", + "Programming Language :: C", + "Programming Language :: Cython", + "Programming Language :: Python", + "Programming Language :: Python :: 3", + "Topic :: Software Development :: Libraries :: Python Modules", + ], + **setup_kwargs )