From 931ced43ebcb97ff83402bb8405a281c2d460dac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Piotr=20Ma=C5=9Blanka?= <piotr.maslanka@henrietta.com.pl> Date: Thu, 1 Jul 2021 16:52:39 +0200 Subject: [PATCH] add find_all --- docs/coverage.rst | 7 +++++++ docs/index.rst | 1 + docs/usage.rst | 16 ++++++++++++++++ snakehouse/__init__.py | 2 +- snakehouse/multibuild.py | 24 +++++++++++++++++++++++- 5 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 docs/coverage.rst diff --git a/docs/coverage.rst b/docs/coverage.rst new file mode 100644 index 0000000..120dca2 --- /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 3ab63ce..d7fad24 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 873fc57..7b58d17 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 a2a8fbf..7b3277b 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 7840ef8..3ca65d8 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__ -- GitLab