Exemplo n.º 1
0
    def test_importfile(self):
        loaded_pydoc = pydoc.importfile(pydoc.__file__)

        self.assertIsNot(loaded_pydoc, pydoc)
        self.assertEqual(loaded_pydoc.__name__, 'pydoc')
        self.assertEqual(loaded_pydoc.__file__, pydoc.__file__)
        self.assertEqual(loaded_pydoc.__spec__, pydoc.__spec__)
Exemplo n.º 2
0
def helpsql(line):
    """
    IPython extension function for getting documentaion on sql related functions in readSqlExt extension.
    :return: None
    """
    module_ = pydoc.importfile(__file__)
    pydoc.doc(module_)
Exemplo n.º 3
0
def get_doc(pyjdoxobj, filepath):
    """
    Get code documentation
    """
    mod = pydoc.importfile(filepath)
    jdata = pyjdoxobj.describe(mod, filepath)
    return jdata
Exemplo n.º 4
0
    def test_importfile(self):
        loaded_pydoc = pydoc.importfile(pydoc.__file__)

        self.assertIsNot(loaded_pydoc, pydoc)
        self.assertEqual(loaded_pydoc.__name__, 'pydoc')
        self.assertEqual(loaded_pydoc.__file__, pydoc.__file__)
        self.assertEqual(loaded_pydoc.__spec__, pydoc.__spec__)
Exemplo n.º 5
0
 def import_module(self, filename):
     """Tries to import the specified file. Returns the python module on succes.
     Primarily for internal use."""
     try:
         mod = pydoc.importfile(filename)
     except Exception, e:
         LOGGER.error("Error loading the file: %s.", filename)
         LOGGER.exception(e)
         return
Exemplo n.º 6
0
 def import_module (self, filename):
     """Tries to import the specified file. Returns the python module on succes.
     Primarily for internal use."""
     try:
         mod = pydoc.importfile (filename)
     except Exception, e:
         LOGGER.error("Error loading the file: %s.", filename)
         LOGGER.exception(e)
         return
Exemplo n.º 7
0
def maybe_create_instance() -> Optional[ModelInferenceAPI]:
    """This function tries to re-create the user `ModelInferenceAPI` if the environment associated with multi
    workers are present."""
    render_fn_name = os.getenv("LIGHTNING_MODEL_INFERENCE_API_CLASS_NAME", None)
    render_fn_module_file = os.getenv("LIGHTNING_MODEL_INFERENCE_API_FILE", None)
    if render_fn_name is None or render_fn_module_file is None:
        return None
    module = pydoc.importfile(render_fn_module_file)
    cls = getattr(module, render_fn_name)
    input = os.getenv("LIGHTNING_MODEL_INFERENCE_API_INPUT", None)
    output = os.getenv("LIGHTNING_MODEL_INFERENCE_API_OUTPUT", None)
    return cls(input=input, output=output)
Exemplo n.º 8
0
def generate_docs(module):
    try:
        sys.path.append(os.getcwd())
        # Attempt import
        mod = importfile(module)
        if mod is None:
            print("Module not found")

        # Module imported correctly, let's create the docs
        return get_markdown(mod)
    except ErrorDuringImport:
        print("Error while trying to import " + module)
Exemplo n.º 9
0
def test():
    module = importfile("ext_doc.py")
    tmp_obj, name = resolve(module)
    print "GOT_C: ", find_class("foo", tmp_obj)
    print "GOT_F: ", find_func("find_func", tmp_obj)
    print "GOT_CF: ", find_func("foo:bar", tmp_obj)
    print "GOT_RF: ", find_func("find_.*", tmp_obj, as_regexp=True)
    print "GOT_CRF: \n", find_func("foo:.*", tmp_obj, as_regexp=True)
    funcs = find_func("foo:.*", tmp_obj, as_regexp=True)
    for f_name, f_ref in funcs:
        dump_func_doc(f_name, f_ref)
    dump_object(name, tmp_obj)
Exemplo n.º 10
0
 def _import_file(self, filename):
     """
     Tries to import the specified file. Returns the python module on succes.
     Primarily for internal use. Note that the python module returned may actually
     contain several more loadable modules.
     """
     mods = pydoc.importfile (filename)
     try:
         if (mods.MODULES): pass
     except AttributeError:
         log.warn("The file %s is not a valid module. Skipping." % (filename))
         log.warn("A module must have the variable MODULES defined as a dictionary.")
         raise
     for modules, infos in mods.MODULES.items():
         for i in ModuleWrapper.COMPULSORY_ATTRIBUTES:
             if i not in infos:
                 log.warn("Class %s in file %s does define a %s attribute. Skipping." % (modules, filename, i))
                 raise Exception
     return mods
Exemplo n.º 11
0
 def _import_file(self, filename):
     """
     Tries to import the specified file. Returns the python module on succes.
     Primarily for internal use. Note that the python module returned may actually
     contain several more loadable modules.
     """
     mods = pydoc.importfile (filename)
     try:
         if (mods.MODULES): pass
     except AttributeError:
         log.warn("The file %s is not a valid module. Skipping." % (filename))
         log.warn("A module must have the variable MODULES defined as a dictionary.")
         raise
     for modules, infos in mods.MODULES.items():
         for i in ModuleWrapper.COMPULSORY_ATTRIBUTES:
             if i not in infos:
                 log.warn("Class %s in file %s does define a %s attribute. Skipping." % (modules, filename, i))
                 raise Exception
     return mods
Exemplo n.º 12
0
def determine():

    # Import everything we can find
    hash = HashThing()
    for dirpath, dirnames, filenames in os.walk('muddled'):

        if DEBUG: print
        if DEBUG: print '%d directories in %s'%(len(dirnames), dirpath)
        for dirname in dirnames:
            if os.path.exists(os.path.join(dirpath, dirname, '__init__.py')):
                parts = dirpath.split(os.sep)
                module_name = '.'.join(parts) + '.' + dirname
                module_path = os.path.join(dirpath, dirname)
                if DEBUG: print '---', module_name, 'from', module_path
                # This works, but relies on module_name being in our path...
                module = pydoc.locate(module_name, forceload=1)
                if DEBUG: print '   ', module_name, ':', module
                hash.add(module_name, module)
                dissect(module_name, module, hash)

        if DEBUG: print
        if DEBUG: print '%d files in %s'%(len(filenames), dirpath)
        for filename in filenames:
            name, ext = os.path.splitext(filename)
            if ext == '.py':
                # We assert that the __init__.py files in muddle do not
                # contain anything we need to report.
                if name in ('__init__', '__main__'):
                        continue
                parts = dirpath.split(os.sep)
                module_name = '.'.join(parts) + '.' + name
                module_path = os.path.join(dirpath, filename)

                if DEBUG: print '---', module_name, 'from', module_path
                module = pydoc.importfile(module_path)

                if DEBUG: print '   ', module_name, ':', module
                hash.add(module_name, module)
                dissect(module_name, module, hash)

    return hash
Exemplo n.º 13
0
def cli():
    if '' not in sys.path:
        script_dir = os.path.dirname(sys.argv[0])
        if script_dir in sys.path:
            sys.path.remove(script_dir)
        sys.path.insert(0, '.')

    parser = argparse.ArgumentParser(
        description='API Blueprint from python docstring.')

    parser.add_argument('-w', '--write', dest='name', nargs='*',
                        help='''Write out the API Blueprint documentation
                        for a module to a file in the current directory.
                        If <name> contains a '{sep}',
                        it is treated as a filename;
                        if it names a directory,
                        documentation is written for all the contents.''')
    parser.add_argument('--host', dest='host',
                        help='Your host server address.')

    args = parser.parse_args()
    if args.host:
        global metadata_host
        metadata_host = 'HOST: %s' % args.host + os.linesep
    for arg in args.name:
        if pydoc.ispath(arg) and not os.path.exists(arg):
            print('path %r does not exist.' % arg)
            break
        if pydoc.ispath(arg):
            if os.path.isfile(arg):
                obj = pydoc.importfile(arg)
                module, name = resolve(obj)
                module_list = [module]
                writedoc(module_list)
            else:
                sys.path.insert(0, arg)
                writedocs(arg)
        else:
            module, name = resolve(arg)
            module_list = [module]
            writedoc(module_list)
Exemplo n.º 14
0
    def __init__(self, conf, dirs):
        gtk.ListStore.__init__(
            self,
            str,  # COL_PATH
            str,  # COL_INTERNAL_NAME
            str,  # COL_ICON_NAME
            gobject.TYPE_PYOBJECT,  # COL_MODULE
            gobject.TYPE_PYOBJECT,  # COL_OBJECT
            bool,  # COL_ENABLED
            int,  # COL_HANDLER
            str,  # COL_ERROR
            gobject.TYPE_PYOBJECT,  # COL_DIALOG
            str)  # COL_DISPLAY_NAME
        self.__active = None
        self.__preferred = None
        self.__conf = conf

        self.__dirs = dirs
        avail = {}
        for dir in dirs:
            try:
                for file in os.listdir(dir):
                    try:
                        path = os.path.join(dir, file)
                        module = pydoc.importfile(path)
                        module.INFO["path"] = path
                        name = module.INFO.get(
                            "internal-name") or module.INFO["name"]
                        if name not in avail.keys() or self.__better_plugin(
                                module, avail[name]):
                            avail[name] = module
                    except Exception, detail:
                        if not file.startswith("__init__.py"):
                            print "Failed to open module at %s: %s" % (path,
                                                                       detail)
            except OSError, detail:
                if dir.find("/.mate2/music-applet/plugins") == -1:
                    print "Failed to scan %s: %s" % (dir, detail)
Exemplo n.º 15
0
def main():
    try:
        opts, args = getopt.getopt(sys.argv[1:], '',
                                   ['test', 'module=', 'func=',
                                    'class_doc=', 'module_doc',
                                    'as_regexp=', 'func_template='])
    except getopt.GetoptError:
        usage(1)

    as_regexp = True
    for opt, val in opts:
        if opt == '--help':
            usage()
        elif opt == '--test':
            test()
        elif opt == '--module':
            module = importfile(val)
            module_ref, module_name = resolve(module)
        elif opt == '--as_regexp':
            as_regexp = int(val)
        elif opt == '--func':
            funcs = find_func(val, module_ref, as_regexp=as_regexp)
            for f_name, f_ref in funcs:
                dump_func_doc(f_name, f_ref)
        elif opt == '--class_doc':
            class_ref = find_class(val, module_ref)
            if not class_ref:
                print "Unknown class: ", val
            else:
                doc = inspect.getdoc(class_ref) or inspect.getcomments(class_ref)
                print doc
        elif opt == '--module_doc':
            print inspect.getdoc(module_ref)
        elif opt == '--func_template':
            global func_template
            file = open(val, "r")
            func_template = "".join(file.readlines())
Exemplo n.º 16
0
    def __init__(self, conf, dirs):
        gtk.ListStore.__init__(
            self,
            str,  # COL_PATH
            str,  # COL_INTERNAL_NAME
            str,  # COL_ICON_NAME
            gobject.TYPE_PYOBJECT,  # COL_MODULE
            gobject.TYPE_PYOBJECT,  # COL_OBJECT
            bool,  # COL_ENABLED
            int,  # COL_HANDLER
            str,  # COL_ERROR
            gobject.TYPE_PYOBJECT,  # COL_DIALOG
            str,
        )  # COL_DISPLAY_NAME
        self.__active = None
        self.__preferred = None
        self.__conf = conf

        self.__dirs = dirs
        avail = {}
        for dir in dirs:
            try:
                for file in os.listdir(dir):
                    try:
                        path = os.path.join(dir, file)
                        module = pydoc.importfile(path)
                        module.INFO["path"] = path
                        name = module.INFO.get("internal-name") or module.INFO["name"]
                        if name not in avail.keys() or self.__better_plugin(module, avail[name]):
                            avail[name] = module
                    except Exception, detail:
                        if not file.startswith("__init__.py"):
                            print "Failed to open module at %s: %s" % (path, detail)
            except OSError, detail:
                if dir.find("/.mate2/music-applet/plugins") == -1:
                    print "Failed to scan %s: %s" % (dir, detail)
Exemplo n.º 17
0
def main():
  """Report bug find/fix rate statistics for Subversion."""

  global verbose
  global update
  global _types
  global _milestone_filter
  global noncore_milestone_filter

  try:
      opts, args = my_getopt(sys.argv[1:], "", [x[0] for x in long_opts])
  except getopt.GetoptError as e:
      sys.stderr.write("Error: %s\n" % e.msg)
      shortusage()
      sys.stderr.write("%s --help for options.\n" % me)
      sys.exit(1)

  for opt, arg in opts:
    if opt == "--help":
      usage()
      sys.exit(0)
    elif opt == "--verbose":
      verbose = 1
    elif opt == "--milestones":
      for mstone in arg.split(","):
        if mstone == "noncore":
          _milestone_filter = noncore_milestone_filter
        elif mstone == "beta":
          _milestone_filter = beta_milestone_filter
        elif mstone == "one":
          _milestone_filter = one_point_oh_milestone_filter
        elif mstone[0] == '-':
          if mstone[1:] in _milestone_filter:
            spot = _milestone_filter.index(mstone[1:])
            _milestone_filter = _milestone_filter[:spot] \
                                + _milestone_filter[(spot+1):]
        else:
          _milestone_filter += [mstone]

    elif opt == "--update":
      update = 1
    elif opt == "--doc":
      pydoc.doc(pydoc.importfile(sys.argv[0]))
      sys.exit(0)

  if len(_milestone_filter) == 0:
    _milestone_filter = noncore_milestone_filter

  if verbose:
    sys.stderr.write("%s: Filtering out milestones %s.\n"
                     % (me, ", ".join(_milestone_filter)))

  if len(args) == 2:
    if verbose:
      sys.stderr.write("%s: Generating gnuplot data.\n" % me)
    if update:
      if verbose:
        sys.stderr.write("%s: Updating %s from %s.\n" % (me, args[0], DATA_FILE))
      if os.system("curl " + DATA_FILE + "> " + args[0]):
        os.system("wget " + DATA_FILE)
    plot(args[0], args[1])

  elif len(args) == 3:
    if verbose:
      sys.stderr.write("%s: Generating summary from %s to %s.\n"
                       % (me, args[1], args[2]))
    if update:
      if verbose:
        sys.stderr.write("%s: Updating %s from %s.\n" % (me, args[0], DATA_FILE))
      if os.system("curl " + DATA_FILE + "> " + args[0]):
        os.system("wget " + DATA_FILE)

    try:
      t_start = parse_time(args[1] + " 00:00:00")
    except ValueError:
      sys.stderr.write('%s: ERROR: bad time value: %s\n' % (me, args[1]))
      sys.exit(1)

    try:
      t_end = parse_time(args[2] + " 00:00:00")
    except ValueError:
      sys.stderr.write('%s: ERROR: bad time value: %s\n' % (me, args[2]))
      sys.exit(1)

    summary(args[0], t_start, t_end)
  else:
    usage()

  sys.exit(0)
Exemplo n.º 18
0
def main():
    """Run find-fix.py with arguments du jour for drawing pretty
manager-speak pictures."""

    global verbose

    try:
        opts, args = my_getopt(sys.argv[1:], "", [x[0] for x in long_opts])
    except getopt.GetoptError as e:
        print("Error: %s" % e.msg)
        shortusage()
        print(me + " --help for options.")
        sys.exit(1)

    for opt, arg in opts:
        if opt == "--help":
            usage()
            sys.exit(0)
        elif opt == "--verbose":
            verbose = 1
        elif opt == "--doc":
            pydoc.doc(pydoc.importfile(sys.argv[0]))
            sys.exit(0)

    # do something fruitful with your life
    if len(args) == 0:
        args = ["query-set-1.tsv", "core-history.csv"]
        print(("ff2csv %s %s" % args))

    if len(args) != 2:
        print("%s: Wrong number of args." % me)
        shortusage()
        sys.exit(1)

    if os.system("curl " + DATA_FILE + "> " + args[0]):
        os.system("wget " + DATA_FILE)

    outfile = open(args[1], "w")
    outfile.write("Date,found,fixed,inval,dup,other,remain\n")

    totalsre = re.compile("totals:.*found= +([0-9]+) +"
                          "fixed= +([0-9]+) +"
                          "inval= +([0-9]+) +"
                          "dup= +([0-9]+) +"
                          "other= +([0-9]+) +"
                          "remain= *([0-9]+)")
    for year in ("2001", "2002", "2003", "2004"):
        for month in ("01", "02", "03", "04", "05", "06", "07", "08", "09",
                      "10", "11", "12"):
            for dayrange in (("01", "08"), ("08", "15"), ("15", "22"), ("22",
                                                                        "28")):
                if verbose:
                    print("searching %s-%s-%s to %s" %
                          (year, month, dayrange[0], dayrange[1]))
                ffpy = os.popen("python ./find-fix.py --m=beta "
                                "%s %s-%s-%s %s-%s-%s" %
                                (args[0], year, month, dayrange[0], year,
                                 month, dayrange[1]))
                if verbose:
                    print("ffpy: %s" % ffpy)

                line = ffpy.readline()
                if verbose:
                    print("initial line is: %s" % line)
                matches = totalsre.search(line)
                if verbose:
                    print("initial match is: %s" % matches)
                while line and not matches:
                    line = ffpy.readline()
                    if verbose:
                        print("%s: read line '%s'" % (me, line))
                    matches = totalsre.search(line)
                    if verbose:
                        print("subsequent line is: %s" % line)

                ffpy.close()

                if verbose:
                    print("line is %s" % line)

                if matches.group(1) != "0" \
                   or matches.group(2) != "0" \
                   or matches.group(3) != "0" \
                   or matches.group(4) != "0" \
                   or matches.group(5) != "0":

                    outfile.write("%s-%s-%s,%s,%s,%s,%s,%s,%s\n" % (
                        year,
                        month,
                        dayrange[1],
                        matches.group(1),
                        matches.group(2),
                        matches.group(3),
                        matches.group(4),
                        matches.group(5),
                        matches.group(6),
                    ))
                elif matches.group(6) != "0":
                    # quit at first nothing-done week
                    # allows slop in loop controls
                    break
    outfile.close()
Exemplo n.º 19
0
    try:
        opts, args = my_getopt(sys.argv[1:], "", [x[0] for x in long_opts])
    except getopt.GetoptError, e:
        print("Error: %s" % e.msg)
        shortusage()
        print(me + " --help for options.")
        sys.exit(1)

    for opt, arg in opts:
        if opt == "--help":
            usage()
            sys.exit(0)
        elif opt == "--verbose":
            verbose = 1
        elif opt == "--doc":
            pydoc.doc(pydoc.importfile(sys.argv[0]))
            sys.exit(0)

    # do something fruitful with your life
    if len(args) == 0:
        args = ["query-set-1.tsv", "core-history.csv"]
        print(("ff2csv %s %s" % args))

    if len(args) != 2:
        print("%s: Wrong number of args." % me)
        shortusage()
        sys.exit(1)

    if os.system("curl " + DATA_FILE + "> " + args[0]):
        os.system("wget " + DATA_FILE)
def _get_render_fn_from_environment() -> Callable:
    render_fn_name = os.environ["LIGHTNING_RENDER_FUNCTION"]
    render_fn_module_file = os.environ["LIGHTNING_RENDER_MODULE_FILE"]
    module = pydoc.importfile(render_fn_module_file)
    return getattr(module, render_fn_name)
Exemplo n.º 21
0
 def update_event(self, inp=-1):
     self.set_output_val(0, pydoc.importfile(self.input(0)))
Exemplo n.º 22
0
def main():
    """Report bug find/fix rate statistics for Subversion."""

    global verbose
    global update
    global _types
    global _milestone_filter
    global noncore_milestone_filter

    try:
        opts, args = my_getopt(sys.argv[1:], "", [x[0] for x in long_opts])
    except getopt.GetoptError as e:
        sys.stderr.write("Error: %s\n" % e.msg)
        shortusage()
        sys.stderr.write("%s --help for options.\n" % me)
        sys.exit(1)

    for opt, arg in opts:
        if opt == "--help":
            usage()
            sys.exit(0)
        elif opt == "--verbose":
            verbose = 1
        elif opt == "--milestones":
            for mstone in arg.split(","):
                if mstone == "noncore":
                    _milestone_filter = noncore_milestone_filter
                elif mstone == "beta":
                    _milestone_filter = beta_milestone_filter
                elif mstone == "one":
                    _milestone_filter = one_point_oh_milestone_filter
                elif mstone[0] == '-':
                    if mstone[1:] in _milestone_filter:
                        spot = _milestone_filter.index(mstone[1:])
                        _milestone_filter = _milestone_filter[:spot] \
                                            + _milestone_filter[(spot+1):]
                else:
                    _milestone_filter += [mstone]

        elif opt == "--update":
            update = 1
        elif opt == "--doc":
            pydoc.doc(pydoc.importfile(sys.argv[0]))
            sys.exit(0)

    if len(_milestone_filter) == 0:
        _milestone_filter = noncore_milestone_filter

    if verbose:
        sys.stderr.write("%s: Filtering out milestones %s.\n" %
                         (me, ", ".join(_milestone_filter)))

    if len(args) == 2:
        if verbose:
            sys.stderr.write("%s: Generating gnuplot data.\n" % me)
        if update:
            if verbose:
                sys.stderr.write("%s: Updating %s from %s.\n" %
                                 (me, args[0], DATA_FILE))
            if os.system("curl " + DATA_FILE + "> " + args[0]):
                os.system("wget " + DATA_FILE)
        plot(args[0], args[1])

    elif len(args) == 3:
        if verbose:
            sys.stderr.write("%s: Generating summary from %s to %s.\n" %
                             (me, args[1], args[2]))
        if update:
            if verbose:
                sys.stderr.write("%s: Updating %s from %s.\n" %
                                 (me, args[0], DATA_FILE))
            if os.system("curl " + DATA_FILE + "> " + args[0]):
                os.system("wget " + DATA_FILE)

        try:
            t_start = parse_time(args[1] + " 00:00:00")
        except ValueError:
            sys.stderr.write('%s: ERROR: bad time value: %s\n' % (me, args[1]))
            sys.exit(1)

        try:
            t_end = parse_time(args[2] + " 00:00:00")
        except ValueError:
            sys.stderr.write('%s: ERROR: bad time value: %s\n' % (me, args[2]))
            sys.exit(1)

        summary(args[0], t_start, t_end)
    else:
        usage()

    sys.exit(0)
Exemplo n.º 23
0


if __name__ == '__main__':
    import getopt
    class BadUsage: pass

    try:
        opts, args = getopt.getopt(sys.argv[1:], 'k:p:w')

        print "<html>"
        print "<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
        print "</head><body>"

        if args:
            for arg in args:
                try:
                    if os.path.isdir(arg): writedocs(arg)
                    
                    if os.path.isfile(arg):
                        arg = pydoc.importfile(arg)
                    writedoc(arg, True)
                except pydoc.ErrorDuringImport, value:
                    print 'problem in %s - %s' % (
                        cgi.escape(value.filename), cgi.escape(value.exc))
        else:
                raise BadUsage

    except (getopt.error, BadUsage):
        print "need parameters\n"
Exemplo n.º 24
0
        elif mstone == "beta":
          _milestone_filter = beta_milestone_filter
        elif mstone == "one":
          _milestone_filter = one_point_oh_milestone_filter
        elif mstone[0] == '-':
          if mstone[1:] in _milestone_filter:
            spot = _milestone_filter.index(mstone[1:])
            _milestone_filter = _milestone_filter[:spot] \
                                + _milestone_filter[(spot+1):]
        else:
          _milestone_filter += [mstone]

    elif opt == "--update":
      update = 1
    elif opt == "--doc":
      pydoc.doc(pydoc.importfile(sys.argv[0]))
      sys.exit(0)

  if len(_milestone_filter) == 0:
    _milestone_filter = noncore_milestone_filter

  if verbose:
    sys.stderr.write("%s: Filtering out milestones %s.\n"
                     % (me, string.join(_milestone_filter, ", ")))

  if len(args) == 2:
    if verbose:
      sys.stderr.write("%s: Generating gnuplot data.\n" % me)
    if update:
      if verbose:
        sys.stderr.write("%s: Updating %s from %s.\n" % (me, args[0], DATA_FILE))