diff --git a/docs/coverage.rst b/docs/coverage.rst new file mode 100644 index 0000000000000000000000000000000000000000..120dca27fb91771095ed5bc2990804f9e22a6f3f --- /dev/null +++ b/docs/coverage.rst @@ -0,0 +1,7 @@ +Coverage +======== + +:code:`snakehouse` is fully compatible with coverage. Go see how it's done +in tempsdb_. + +.. _tempsdb: https://github.com/smok-serwis/tempsdb diff --git a/docs/index.rst b/docs/index.rst index 3ab63ceb8887b460a4a7534c8ba236c6f3dac568..d7fad24941e23a7ed86305d050fd845e5cd5216c 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -7,6 +7,7 @@ Welcome to snakehouse's documentation! usage utilities + coverage accelerating What is snakehouse? diff --git a/docs/usage.rst b/docs/usage.rst index 873fc57b2ca870412fe76441cf685aa2af73213a..7b58d170d336d53e4bbe890019b369b5343f562f 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -34,3 +34,19 @@ Full pydoc of :code:`Multibuild` and :code:`build` is here You should use :code:`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: + +.. code-block:: python + + from snakehouse import Multibuild, build, find_all + + extensions = build([ + Multibuild('example_module', find_all('src')) + ], compiler_directives={ + 'language_level': '3', + }) + +The documentation to :class:`~snakehouse.find_all` is as follows: + +.. autoclass:: snakehouse.find_all diff --git a/snakehouse/__init__.py b/snakehouse/__init__.py index a2a8fbf3530959228469659b1ac2596b73a14404..7b3277b74bb0cf8e0c1573a48631da7c5b1cfa5f 100644 --- a/snakehouse/__init__.py +++ b/snakehouse/__init__.py @@ -1,6 +1,6 @@ import pkg_resources from .build import build -from .multibuild import Multibuild +from .multibuild import Multibuild, find_all from .faster_builds import monkey_patch_parallel_compilation from .requirements import read_requirements_txt, find_c, find_pyx_and_c, find_pyx diff --git a/snakehouse/multibuild.py b/snakehouse/multibuild.py index 7840ef883a8e3edf813bbe708676e3dda75480cc..3ca65d8e21ae0a2f9ded97df43e6916256f002d5 100644 --- a/snakehouse/multibuild.py +++ b/snakehouse/multibuild.py @@ -1,4 +1,5 @@ import hashlib +import itertools import os import logging import collections @@ -6,7 +7,7 @@ import typing as tp import warnings import pkg_resources -from satella.files import split +from satella.files import split, find_files from mako.template import Template from setuptools import Extension @@ -44,6 +45,27 @@ def render_mako(template_name: str, **kwargs) -> str: LINES_IN_HFILE = len(load_mako_lines('hfile.mako').split('\n')) +class find_all: + """ + A directive for :class:`snakehouse.Multibuild` to locate all .pyx + files, and possibly all the .c files depending on the switch + + :param dir: base directory to look for files in + :param include_c_files: whether to also hook up the located .c files + """ + + def __init__(self, dir: str, include_c_files: bool = False): + self.dir = dir + self.include_c_files = include_c_files + + def __iter__(self): + pyx_files = find_files(self.dir, r'(.*)\.pyx', scan_subdirectories=True) + c_files = find_files(self.dir, r'(.*)\.c', scan_subdirectories=True) + if self.include_c_files: + pyx_files = itertools.chain(pyx_files, c_files) + return pyx_files + + class Multibuild: """ This specifies a single Cython extension, called {extension_name}.__bootstrap__