pyt/path.py
def module_path(self, filepath):
        """given a filepath like /base/path/to/module.py this will convert it to
        path.to.module so it can be imported"""
        possible_modbits = re.split('[\\/]', filepath.strip('\\/'))
        basename = possible_modbits[-1]
        prefixes = possible_modbits[0:-1]
        modpath = []
        discarded = []

        # find the first directory that has an __init__.py
        for i in range(len(prefixes)):
            path_args = ["/"]
            path_args.extend(prefixes[0:i+1])
            path_args.append('__init__.py')
            prefix_module = os.path.join(*path_args)
            #logger.debug("Checking prefix modulepath: {}".format(prefix_module))
            if os.path.isfile(prefix_module):
                #logger.debug("Found start of modulepath: {}".format(prefixes[i]))
                modpath = prefixes[i:]
                break

            else:
                discarded = path_args[0:-1]

        modpath.append(basename)

        # convert the remaining file path to a python module path that can be imported
        module_name = '.'.join(modpath)
        module_name = re.sub(r'(?:\.__init__)?\.py$', '', module_name, flags=re.I)
        logger.debug("Module path {} found in filepath {}".format(module_name, filepath))
        return module_name
def module_path(self, filepath):
        """given a filepath like /base/path/to/module.py this will convert it to
        path.to.module so it can be imported"""
        possible_modbits = re.split('[\\/]', filepath.strip('\\/'))
        basename = possible_modbits[-1]
        prefixes = possible_modbits[0:-1]
        modpath = []
        discarded = []

        # find the first directory that has an __init__.py
        for i in range(len(prefixes)):
            path_args = ["/"]
            path_args.extend(prefixes[0:i+1])
            path_args.append('__init__.py')
            prefix_module = os.path.join(*path_args)
            #logger.debug("Checking prefix modulepath: {}".format(prefix_module))
            if os.path.isfile(prefix_module):
                #logger.debug("Found start of modulepath: {}".format(prefixes[i]))
                modpath = prefixes[i:]
                break

            else:
                discarded = path_args[0:-1]

        modpath.append(basename)

        # convert the remaining file path to a python module path that can be imported
        module_name = '.'.join(modpath)
        module_name = re.sub(r'(?:\.__init__)?\.py$', '', module_name, flags=re.I)
        logger.debug("Module path {} found in filepath {}".format(module_name, filepath))
        return module_name
def module_path ( self , filepath ) : possible_modbits = re . split ( '[\\/]' , filepath . strip ( '\\/' ) ) basename = possible_modbits [ - 1 ] prefixes = possible_modbits [ 0 : - 1 ] modpath = [ ] discarded = [ ] # find the first directory that has an __init__.py for i in range ( len ( prefixes ) ) : path_args = [ "/" ] path_args . extend ( prefixes [ 0 : i + 1 ] ) path_args . append ( '__init__.py' ) prefix_module = os . path . join ( * path_args ) #logger.debug("Checking prefix modulepath: {}".format(prefix_module)) if os . path . isfile ( prefix_module ) : #logger.debug("Found start of modulepath: {}".format(prefixes[i])) modpath = prefixes [ i : ] break else : discarded = path_args [ 0 : - 1 ] modpath . append ( basename ) # convert the remaining file path to a python module path that can be imported module_name = '.' . join ( modpath ) module_name = re . sub ( r'(?:\.__init__)?\.py$' , '' , module_name , flags = re . I ) logger . debug ( "Module path {} found in filepath {}" . format ( module_name , filepath ) ) return module_name
given a filepath like /base/path/to/module.py this will convert it to
        path.to.module so it can be imported
given a filepath like / base / path / to / module . py this will convert it to path . to . module so it can be imported