# -*- coding: utf-8 -*-
from __future__ import absolute_import

import glob
import os
import copy

from distutils.core import Extension

def get_zmq_include_path():
    """Get the ZMQ include path in an import-safe manner."""
    try:
        import zmq
        return zmq.get_includes()
    except ImportError as e:
        return []

def get_extensions(**kwargs):
    """Get the Cython extensions"""
    
    this_directory = os.path.dirname(__file__)
    this_name = __name__.split(".")[:-1]
    
    extension_args = {
        'include_dirs' : [this_directory] + ['numpy'] + get_zmq_include_path(),
        'libraries' : [],
        'sources' : []
    }
    extension_args.update(kwargs)
    
    
    extensions = []
    
    for component in glob.iglob(os.path.join(this_directory, "*.pyx")):
        # Component name and full module name.
        this_extension_args = copy.deepcopy(extension_args)
        cname = os.path.splitext(os.path.basename(component))[0]
        if cname.startswith("_"):
            cname = cname[1:]
            name = ".".join(this_name + ["_{0:s}".format(cname)])
        else:
            name = ".".join(this_name + [cname])
        this_extension_args['sources'].append(component)
        
        # Extension object.
        extension = Extension(name, **this_extension_args)
        extensions.append(extension)
    
    return extensions
# -*- coding: utf-8 -*-
from __future__ import absolute_import

import glob
import os
import copy

from distutils.core import Extension
from zeeko._build_helpers import get_utils_extension_args, get_zmq_extension_args, _generate_cython_extensions

HERE = os.path.dirname(__file__)

pjoin = os.path.join
pxd = lambda *path : os.path.relpath(pjoin(HERE, *path) + ".pxd")
h = lambda *path : os.path.relpath(pjoin(HERE, *path) + ".h")

dependencies = {
    'condition' : [pxd("condition"), pxd("pthread"), pxd("clock"), h("mclock")]
}

def get_extensions(**kwargs):
    """Get the Cython extensions"""
    
    extension_args = setup_helpers.DistutilsExtensionArgs()
    extension_args.update(get_utils_extension_args())
    extension_args.update(get_zmq_extension_args())
    extension_args['include_dirs'].append('numpy')
    
    package_name = __name__.split(".")[:-1]
    extensions = [e for e in _generate_cython_extensions(extension_args, os.path.dirname(__file__), package_name)]
    for extension in extensions:
        name = extension.name.split(".")[-1]
        if name in dependencies:
            extension.depends.extend(dependencies[name])
    return extensions
    
Fix setup_package for utils