Source code for bob.extension.utils

#!/usr/bin/env python
# encoding: utf-8
# Andre Anjos <andre.dos.anjos@gmail.com>
# Fri 21 Mar 2014 10:37:40 CET

"""General utilities for building extensions"""

import os
import re
import sys

import pkg_resources


[docs]def load_requirements(f=None): """Loads the contents of requirements.txt on the given path. Defaults to "./requirements.txt" """ def readlines(f): retval = [str(k.strip()) for k in f] return [k for k in retval if k and k[0] not in ("#", "-")] # if f is None, use the default ('requirements.txt') if f is None: f = "requirements.txt" if isinstance(f, str): f = open(f, "rt") # read the contents return readlines(f)
[docs]def find_packages(directories=["bob"]): """This function replaces the ``find_packages`` command from ``setuptools`` to search for packages only in the given directories. Using this function will increase the building speed, especially when you have (links to) deep non-code-related directory structures inside your package directory. The given ``directories`` should be a list of top-level sub-directories of your package, where package code can be found. By default, it uses ``'bob'`` as the only directory to search. """ from setuptools import find_packages as _original if isinstance(directories, str): directories = [directories] packages = [] for d in directories: packages += [d] packages += ["%s.%s" % (d, p) for p in _original(d)] return packages