Skip to content
Snippets Groups Projects
Commit 931ced43 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

add find_all

parent bfd7e01b
No related branches found
No related tags found
No related merge requests found
Coverage
========
:code:`snakehouse` is fully compatible with coverage. Go see how it's done
in tempsdb_.
.. _tempsdb: https://github.com/smok-serwis/tempsdb
...@@ -7,6 +7,7 @@ Welcome to snakehouse's documentation! ...@@ -7,6 +7,7 @@ Welcome to snakehouse's documentation!
usage usage
utilities utilities
coverage
accelerating accelerating
What is snakehouse? What is snakehouse?
......
...@@ -34,3 +34,19 @@ Full pydoc of :code:`Multibuild` and :code:`build` is here ...@@ -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 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 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. 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
import pkg_resources import pkg_resources
from .build import build from .build import build
from .multibuild import Multibuild from .multibuild import Multibuild, find_all
from .faster_builds import monkey_patch_parallel_compilation from .faster_builds import monkey_patch_parallel_compilation
from .requirements import read_requirements_txt, find_c, find_pyx_and_c, find_pyx from .requirements import read_requirements_txt, find_c, find_pyx_and_c, find_pyx
......
import hashlib import hashlib
import itertools
import os import os
import logging import logging
import collections import collections
...@@ -6,7 +7,7 @@ import typing as tp ...@@ -6,7 +7,7 @@ import typing as tp
import warnings import warnings
import pkg_resources import pkg_resources
from satella.files import split from satella.files import split, find_files
from mako.template import Template from mako.template import Template
from setuptools import Extension from setuptools import Extension
...@@ -44,6 +45,27 @@ def render_mako(template_name: str, **kwargs) -> str: ...@@ -44,6 +45,27 @@ def render_mako(template_name: str, **kwargs) -> str:
LINES_IN_HFILE = len(load_mako_lines('hfile.mako').split('\n')) 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: class Multibuild:
""" """
This specifies a single Cython extension, called {extension_name}.__bootstrap__ This specifies a single Cython extension, called {extension_name}.__bootstrap__
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment