Ticket #5060: 5060-deps.patch

File 5060-deps.patch, 3.2 KB (added by Robert Bradshaw, 14 years ago)
  • setup.py

    # HG changeset patch
    # User Robert Bradshaw <robertwb@math.washington.edu>
    # Date 1232716149 28800
    # Node ID 0966e86fcef063ebacfe0af482ca68a0ac359a80
    # Parent  d12b1725c08b06f128fe93897e33e76afad214fc
    More complete dependancy checking
    
    It would miss "cdef extern from" and "cimport a, b" and accidently catch commented cimports.
    
    diff -r d12b1725c08b -r 0966e86fcef0 setup.py
    a b  
    225225
    226226# matches any dependency
    227227import re
    228 dep_regex = re.compile(r'^ *(?:cimport +(\S+))|(?:from +(\S+) *cimport)|(?:include *[\'"]([^\'"]+)[\'"])', re.M)
     228dep_regex = re.compile(r'^ *(?:(?:cimport +([\S ,]+))|(?:from +(\S+) *cimport)|(?:include *[\'"]([^\'"]+)[\'"])|(?:cdef *extern *from *[\'"]([^\'"]+)[\'"]))', re.M)
    229229
    230230class DependencyTree:
    231231    """
     
    294294            if os.path.exists(pxd_file):
    295295                deps.add(pxd_file)
    296296       
     297        raw_deps = []
    297298        f = open(filename)
    298299        for m in dep_regex.finditer(open(filename).read()):
    299300            groups = m.groups()
    300             module = groups[0] or groups[1] # cimport or from ... cimport
    301             if module is not None:
    302                 if '.' in module:
    303                     path = module.replace('.', '/') + '.pxd'
    304                     base_dependency_name = path
    305                 else:
    306                     path = "%s/%s.pxd" % (dirname, module)
    307                     base_dependency_name = "%s.pxd"%module
    308             else:
    309                 path = '%s/%s'%(dirname, groups[2])
     301            modules = groups[0] or groups[1] # cimport or from ... cimport
     302            if modules is not None:
     303                for module in modules.split(','):
     304                    module = module.strip().split(' ')[0] # get rid of 'as' clause
     305                    if '.' in module:
     306                        path = module.replace('.', '/') + '.pxd'
     307                        base_dependency_name = path
     308                    else:
     309                        path = "%s/%s.pxd" % (dirname, module)
     310                        base_dependency_name = "%s.pxd"%module
     311                    raw_deps.append((path, base_dependency_name))
     312            else: # include or extern from
     313                extern_file = groups[2] or groups[3]
     314                path = '%s/%s'%(dirname, extern_file)
    310315                if not os.path.exists(path):
    311                     path = groups[2]
    312                 base_dependency_name = groups[2]
     316                    path = extern_file
     317                raw_deps.append((path, extern_file))
    313318
     319        for path, base_dependency_name in raw_deps:
    314320            # if we can find the file, add it to the dependencies.
    315321            path = os.path.normpath(path)
    316322            if os.path.exists(path):
     
    328334                # so we really couldn't find the dependency -- raise
    329335                # an exception.
    330336                if not found_include:
    331                     raise IOError, "could not find dependency %s included in %s."%(path, filename)
     337                    if path[-2:] != '.h':  # there are implicit headers from distutils, etc
     338                        raise IOError, "could not find dependency %s included in %s."%(path, filename)
    332339        f.close()
    333340        return list(deps)
    334341