Example #1
0
def generateModuleFilenamesInPythonPath(contextFilename):
    files = []
    rootdir = getRootDirectory(contextFilename)
    if rootdir in getPythonPath():
        # just search the pythonpath
        for path in getPythonPath():
            for file in getFilesForName(path):
                if file not in files:  # check for duplicates
                    files.append(file)
                    yield file
    else:
        # search the package hierarchy containing contextFilename
        # in addition to pythonpath
        basedir = getPackageBaseDirectory(contextFilename)
        for path in [basedir] + getPythonPath():
            for file in getFilesForName(path):
                if file not in files:  # check for duplicates
                    files.append(file)
                    yield file

        # and search the files immediately above the package hierarchy
        for file in getFilesForName(os.path.join(rootdir, "*.py")):
            if file not in files:  # check for duplicates
                files.append(file)
                yield file
def generateModuleFilenamesInPythonPath(contextFilename):
    files = []
    rootdir = getRootDirectory(contextFilename)
    if rootdir in getPythonPath():
        # just search the pythonpath
        for path in getPythonPath():
            for file in getFilesForName(path):
                if file not in files:   # check for duplicates
                    files.append(file)
                    yield file
    else:
        # search the package hierarchy containing contextFilename
        # in addition to pythonpath
        basedir = getPackageBaseDirectory(contextFilename)
        for path in [basedir] + getPythonPath():
            for file in getFilesForName(path):
                if file not in files:   # check for duplicates
                    files.append(file)
                    yield file

        # and search the files immediately above the package hierarchy
        for file in getFilesForName(os.path.join(rootdir,"*.py")):
            if file not in files:   # check for duplicates
                files.append(file)
                yield file
Example #3
0
def resolveImportedModuleOrPackage(scope,fqn):
    # try searching from directory containing scope module
    path = os.path.dirname(scope.module.filename)
    node = getModuleOrPackageUsingFQN(fqn,path)
    if node is not None:
        return node

    # try searching in same package hierarchy
    basedir = getPackageBaseDirectory(scope.module.filename)
    if fqn.split('.')[0] == os.path.split(basedir)[-1]:
        # base package in fqn matches base directory
        restOfFqn = ".".join(fqn.split('.')[1:])
        node = getModuleOrPackageUsingFQN(restOfFqn,basedir)
    if node is not None:
        return node

    # try searching the python path
    node = getModuleOrPackageUsingFQN(fqn)
    if node is not None:
        return node
Example #4
0
def resolveImportedModuleOrPackage(scope, fqn):
    # try searching from directory containing scope module
    path = os.path.dirname(scope.module.filename)
    node = getModuleOrPackageUsingFQN(fqn, path)
    if node is not None:
        return node

    # try searching in same package hierarchy
    basedir = getPackageBaseDirectory(scope.module.filename)
    if fqn.split('.')[0] == os.path.split(basedir)[-1]:
        # base package in fqn matches base directory
        restOfFqn = ".".join(fqn.split('.')[1:])
        node = getModuleOrPackageUsingFQN(restOfFqn, basedir)
    if node is not None:
        return node

    # try searching the python path
    node = getModuleOrPackageUsingFQN(fqn)
    if node is not None:
        return node
Example #5
0
def generatePackageDependencies(fileInPackage):
    rejectPackagePaths = [getPackageBaseDirectory(fileInPackage)]
    for fname in generateModuleFilenamesInPackage(fileInPackage):

        try:
            f = file(fname)
            src = f.read()
        finally:
            f.close()

        packagepath = None

        for line in src.splitlines():
            match = fromRegex.search(line) or importregex.search(line)
            if match is not None:
                modulepath = match.group(1)
                packagename = modulepath.split('.')[0]
                packagepath = getPathOfModuleOrPackage(packagename,
                                                       getPythonPath())
            if packagepath is not None and \
                   packagepath not in rejectPackagePaths:
                rejectPackagePaths.append(packagepath)  # avoid duplicates
                yield packagepath
def generatePackageDependencies(fileInPackage):
    rejectPackagePaths = [getPackageBaseDirectory(fileInPackage)]
    for fname in generateModuleFilenamesInPackage(fileInPackage):

        try:
            f = file(fname)
            src = f.read()
        finally:
            f.close()

        packagepath = None

        for line in src.splitlines():
            match = fromRegex.search(line) or importregex.search(line)
            if match is not None:
                modulepath = match.group(1)
                packagename = modulepath.split('.')[0]
                packagepath = getPathOfModuleOrPackage(packagename,
                                                       getPythonPath())
            if packagepath is not None and \
                   packagepath not in rejectPackagePaths:
                rejectPackagePaths.append(packagepath) # avoid duplicates
                yield packagepath
Example #7
0
def generateModuleFilenamesInPackage(filenameInPackage):
    basedir = getPackageBaseDirectory(filenameInPackage)
    for file in getFilesForName(basedir):
        yield file
def generateModuleFilenamesInPackage(filenameInPackage):
    basedir = getPackageBaseDirectory(filenameInPackage)
    for file in getFilesForName(basedir):
        yield file