Python pydoc.ErrorDuringImport() Examples
The following are 5
code examples of pydoc.ErrorDuringImport().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pydoc
, or try the search function
.
Example #1
Source File: type_helpers.py From RAFCON with Eclipse Public License 1.0 | 5 votes |
def convert_string_to_type(string_value): """Converts a string into a type or class :param string_value: the string to be converted, e.g. "int" :return: The type derived from string_value, e.g. int """ # If the parameter is already a type, return it if string_value in ['None', type(None).__name__]: return type(None) if isinstance(string_value, type) or isclass(string_value): return string_value # Get object associated with string # First check whether we are having a built in type (int, str, etc) if sys.version_info >= (3,): import builtins as builtins23 else: import __builtin__ as builtins23 if hasattr(builtins23, string_value): obj = getattr(builtins23, string_value) if type(obj) is type: return obj # If not, try to locate the module try: obj = locate(string_value) except ErrorDuringImport as e: raise ValueError("Unknown type '{0}'".format(e)) # Check whether object is a type if type(obj) is type: return locate(string_value) # Check whether object is a class if isclass(obj): return obj # Raise error if none is the case raise ValueError("Unknown type '{0}'".format(string_value))
Example #2
Source File: generate_docs.py From tockloader with MIT License | 5 votes |
def generatedocs(module, filename): try: sys.path.insert(0, os.getcwd() + '/..') # Attempt import mod = pydoc.safeimport(module) if mod is None: print("Module not found") # Module imported correctly, let's create the docs with open(filename, 'w') as f: f.write(getmarkdown(mod)) except pydoc.ErrorDuringImport as e: print("Error while trying to import " + module) # if __name__ == '__main__':
Example #3
Source File: defopt.py From defopt with MIT License | 5 votes |
def main(argv=None): parser = ArgumentParser() parser.add_argument('function') parser.add_argument('args', nargs=REMAINDER) args = parser.parse_args(argv) try: func = pydoc.locate(args.function) except pydoc.ErrorDuringImport as exc: raise exc.value from None if func is None: raise ImportError('Failed to locate {!r}'.format(args.function)) argparse_kwargs = ( {'prog': ' '.join(sys.argv[:2])} if argv is None else {}) retval = run(func, argv=args.args, argparse_kwargs=argparse_kwargs) sys.displayhook(retval)
Example #4
Source File: gendoc.py From redisjson-py with BSD 2-Clause "Simplified" License | 5 votes |
def generatedocs(module): try: sys.path.append(os.getcwd()) # Attempt import mod = pydoc.safeimport(module) if mod is None: print("Module not found") # Module imported correctly, let's create the docs return getmarkdown(mod) except pydoc.ErrorDuringImport as e: print("Error while trying to import " + module)
Example #5
Source File: gendoc.py From redisearch-py with BSD 2-Clause "Simplified" License | 5 votes |
def generatedocs(module): try: sys.path.append(os.getcwd()) # Attempt import mod = pydoc.safeimport(module) if mod is None: print("Module not found") # Module imported correctly, let's create the docs return getmarkdown(mod) except pydoc.ErrorDuringImport as e: print("Error while trying to import " + module)