Usage

To use snakehouse just use the following in your setup.py:

from snakehouse import Multibuild, build

extensions = build([
                Multibuild('example_module', list_of_pyx_files)
                ], compiler_directives={
                   'language_level': '3',
                })

setup(name='example_module',
  version='0.1',
  packages=['example_module'],
  ext_modules=extensions
)

You can pass also setuptools’s Extensions objects, as detailed in example.

Full pydoc of Multibuild and build is here

class snakehouse.Multibuild(extension_name: str, files: Iterator[str], dont_snakehouse: bool = False, **kwargs)

This specifies a single Cython extension, called {extension_name}.__bootstrap__

All kwargs will be sent straight to Cython’s Extension

Parameters:
  • extension_name – the module name

  • files – list of pyx and c files

  • kwargs – extra arguments to be passed to Extension() object

  • dont_snakehouse – snakehouse won’t be enabled, each element will be built as a separate extension. It is for these cases when you’re testing and something segfaults.

snakehouse.build(extensions: List[Multibuild | Exception], *args, nthreads=None, **kwargs)

You should use dont_snakehouse for debugging and unit tests, as snakehouse has a sad tendency to dump core on unhandled exceptions. To prevent that from happening remember to handle your exceptions and debug using this flag.

If you need to locate all .pyx files in a certain directory, you can do the following:

from snakehouse import Multibuild, build, find_all

extensions = build([
                Multibuild('example_module', find_all('src'))
                ], compiler_directives={
                   'language_level': '3',
                })

The documentation to find_all is as follows:

class snakehouse.find_all(directory: str, include_c_files: bool = False, only_c_files: bool = False)

A directive for snakehouse.Multibuild to locate all .pyx files, and possibly all the .c files depending on the switch

Parameters:
  • directory – base directory to look for files in

  • include_c_files – whether to also hook up the located .c files (default False)

  • only_c_files – whether to look up only .c files (default False)