當前位置: 首頁>>代碼示例>>Python>>正文


Python inspect.getabsfile方法代碼示例

本文整理匯總了Python中inspect.getabsfile方法的典型用法代碼示例。如果您正苦於以下問題:Python inspect.getabsfile方法的具體用法?Python inspect.getabsfile怎麽用?Python inspect.getabsfile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在inspect的用法示例。


在下文中一共展示了inspect.getabsfile方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: lines_without_stdlib

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def lines_without_stdlib(self):
        """Filters code from standard library from self.lines."""
        prev_line = None
        current_module_path = inspect.getabsfile(inspect.currentframe())
        for module_path, lineno, runtime in self.lines:
            module_abspath = os.path.abspath(module_path)
            if not prev_line:
                prev_line = [module_abspath, lineno, runtime]
            else:
                if (not check_standard_dir(module_path) and
                        module_abspath != current_module_path):
                    yield prev_line
                    prev_line = [module_abspath, lineno, runtime]
                else:
                    prev_line[2] += runtime
        yield prev_line 
開發者ID:nvdv,項目名稱:vprof,代碼行數:18,代碼來源:code_heatmap.py

示例2: testRequest

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def testRequest(self):
        runner.run(
            self._func, 'p', ('foo', 'bar'), host=_HOST, port=_PORT)
        response = urllib.request.urlopen(
            'http://%s:%s/profile' % (_HOST, _PORT))
        response_data = gzip.decompress(response.read())
        stats = json.loads(response_data.decode('utf-8'))
        curr_filename = inspect.getabsfile(inspect.currentframe())
        self.assertEqual(stats['p']['objectName'],
                         '_func @ %s (function)' % curr_filename)
        self.assertTrue(len(stats['p']['callStats']) > 0)
        self.assertTrue(stats['p']['totalTime'] > 0)
        self.assertTrue(stats['p']['primitiveCalls'] > 0)
        self.assertTrue(stats['p']['totalCalls'] > 0)


# pylint: enable=missing-docstring, blacklisted-name 
開發者ID:nvdv,項目名稱:vprof,代碼行數:19,代碼來源:profiler_e2e.py

示例3: testRequest

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def testRequest(self):
        runner.run(
            self._func, 'h', ('foo', 'bar'), host=_HOST, port=_PORT)
        response = urllib.request.urlopen(
            'http://%s:%s/profile' % (_HOST, _PORT))
        response_data = gzip.decompress(response.read())
        stats = json.loads(response_data.decode('utf-8'))
        self.assertTrue(stats['h']['runTime'] > 0)
        heatmaps = stats['h']['heatmaps']
        curr_filename = inspect.getabsfile(inspect.currentframe())
        self.assertEqual(stats['h']['objectName'],
                         '_func @ %s (function)' % curr_filename)
        self.assertEqual(len(heatmaps), 1)
        self.assertDictEqual(
            heatmaps[0]['executionCount'], {'101': 1, '102': 1})
        self.assertListEqual(
            heatmaps[0]['srcCode'],
            [['line', 100, u'        def _func(foo, bar):\n'],
             ['line', 101, u'            baz = foo + bar\n'],
             ['line', 102, u'            return baz\n']])

# pylint: enable=missing-docstring, blacklisted-name 
開發者ID:nvdv,項目名稱:vprof,代碼行數:24,代碼來源:code_heatmap_e2e.py

示例4: testRequest

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def testRequest(self):
        runner.run(
            self._func, 'c', ('foo', 'bar'), host=_HOST, port=_PORT)
        response = urllib.request.urlopen(
            'http://%s:%s/profile' % (_HOST, _PORT))
        response_data = gzip.decompress(response.read())
        stats = json.loads(response_data.decode('utf-8'))
        curr_filename = inspect.getabsfile(inspect.currentframe())
        self.assertEqual(stats['c']['objectName'],
                         '_func @ %s (function)' % curr_filename)
        self.assertEqual(
            stats['c']['sampleInterval'], flame_graph._SAMPLE_INTERVAL)
        self.assertTrue(stats['c']['runTime'] > 0)
        self.assertTrue(len(stats['c']['callStats']) >= 0)
        self.assertTrue(stats['c']['totalSamples'] >= 0)

# pylint: enable=missing-docstring, blacklisted-name, protected-access 
開發者ID:nvdv,項目名稱:vprof,代碼行數:19,代碼來源:flame_graph_e2e.py

示例5: testRequest

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def testRequest(self):
        runner.run(
            self._func, 'm', ('foo', 'bar'), host=_HOST, port=_PORT)
        response = urllib.request.urlopen(
            'http://%s:%s/profile' % (_HOST, _PORT))
        response_data = gzip.decompress(response.read())
        stats = json.loads(response_data.decode('utf-8'))
        curr_filename = inspect.getabsfile(inspect.currentframe())
        self.assertEqual(stats['m']['objectName'],
                         '_func @ %s (function)' % curr_filename)
        self.assertEqual(stats['m']['totalEvents'], 2)
        self.assertEqual(stats['m']['codeEvents'][0][0], 1)
        self.assertEqual(stats['m']['codeEvents'][0][1], 91)
        self.assertEqual(stats['m']['codeEvents'][0][3], '_func')
        self.assertEqual(stats['m']['codeEvents'][1][0], 2)
        self.assertEqual(stats['m']['codeEvents'][1][1], 92)
        self.assertEqual(stats['m']['codeEvents'][1][3], '_func')

# pylint: enable=missing-docstring, blacklisted-name 
開發者ID:nvdv,項目名稱:vprof,代碼行數:21,代碼來源:memory_profiler_e2e.py

示例6: main

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def main():
    args = parse_args()

    plugins = parse_plugins(args.plugins)
    for p in plugins:
        dr.load_components(p, continue_on_error=False)

    results = defaultdict(list)
    for comp, delegate in dr.DELEGATES.items():
        if isinstance(delegate, rule):
            results[dr.get_base_module_name(comp)].append(comp)

    results = dict((key, comps) for key, comps in results.items() if len(comps) > 1)

    if results:
        print("Potential key conflicts:")
        print()
        for key in sorted(results):
            print("{key}:".format(key=key))
            for comp in sorted(results[key], key=dr.get_name):
                name = comp.__name__
                path = inspect.getabsfile(comp)
                print("    {name} in {path}".format(name=name, path=path))
            print() 
開發者ID:RedHatInsights,項目名稱:insights-core,代碼行數:26,代碼來源:dupkeycheck.py

示例7: run

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def run(self):
        """Turn everything on."""
        self.roaster.auto_connect()
        self.window = mainwindow.MainWindow(
            self.recipes,
            self.roaster)
        self.window.show()
        sys.exit(self.app.exec_())


# def get_script_dir(follow_symlinks=True):
    # """Checks where the script is being executed from to verify the imports
    # will work properly."""
    # if getattr(sys, 'frozen', False):
        # path = os.path.abspath(sys.executable)
    # else:
        # path = inspect.getabsfile(get_script_dir)

    # if follow_symlinks:
        # path = os.path.realpath(path)

    # return os.path.dirname(path) 
開發者ID:Roastero,項目名稱:Openroast,代碼行數:24,代碼來源:openroastapp.py

示例8: getdocloc

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def getdocloc(self, object):
        """Return the location of module docs or None"""

        try:
            file = inspect.getabsfile(object)
        except TypeError:
            file = '(built-in)'

        docloc = os.environ.get("PYTHONDOCS", self.PYTHONDOCS)

        basedir = os.path.join(sys.base_exec_prefix, "lib",
                               "python%d.%d" %  sys.version_info[:2])
        if (isinstance(object, type(os)) and
            (object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
                                 'marshal', 'posix', 'signal', 'sys',
                                 '_thread', 'zipimport') or
             (file.startswith(basedir) and
              not file.startswith(os.path.join(basedir, 'site-packages')))) and
            object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
            if docloc.startswith("http://"):
                docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__)
            else:
                docloc = os.path.join(docloc, object.__name__ + ".html")
        else:
            docloc = None
        return docloc

# -------------------------------------------- HTML documentation generator 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:30,代碼來源:pydoc.py

示例9: _get_script_dir

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def _get_script_dir(follow_symlinks: bool = True) -> Path:
    # Getting the path to the trust stores is tricky due to subtle differences on OS X, Linux and Windows
    if getattr(sys, "frozen", False):
        # py2exe, PyInstaller, cx_Freeze
        path = Path(sys.executable).absolute()
    else:
        path = Path(inspect.getabsfile(_get_script_dir))
    if follow_symlinks:
        path = Path(realpath(path))
    return path.parent 
開發者ID:nabla-c0d3,項目名稱:sslyze,代碼行數:12,代碼來源:trust_store_repository.py

示例10: _get_position_of_obj

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def _get_position_of_obj(self, obj, quiet=False):
        if hasattr(inspect, "unwrap"):
            obj = inspect.unwrap(obj)
        if isinstance(obj, str):
            return obj, 1, None
        try:
            filename = inspect.getabsfile(obj)
            lines, lineno = inspect.getsourcelines(obj)
        except (IOError, TypeError) as e:
            if not quiet:
                print('** Error: %s **' % e, file=self.stdout)
            return None, None, None
        return filename, lineno, lines 
開發者ID:pdbpp,項目名稱:pdbpp,代碼行數:15,代碼來源:pdbpp.py

示例11: getdocloc

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def getdocloc(self, object):
        """Return the location of module docs or None"""

        try:
            file = inspect.getabsfile(object)
        except TypeError:
            file = '(built-in)'

        docloc = os.environ.get("PYTHONDOCS",
                                "http://docs.python.org/library")
        basedir = os.path.join(sys.exec_prefix, "lib",
                               "python"+sys.version[0:3])
        if (isinstance(object, type(os)) and
            (object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
                                 'marshal', 'posix', 'signal', 'sys',
                                 'thread', 'zipimport') or
             (file.startswith(basedir) and
              not file.startswith(os.path.join(basedir, 'site-packages')))) and
            object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
            if docloc.startswith("http://"):
                docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__)
            else:
                docloc = os.path.join(docloc, object.__name__ + ".html")
        else:
            docloc = None
        return docloc

# -------------------------------------------- HTML documentation generator 
開發者ID:glmcdona,項目名稱:meddle,代碼行數:30,代碼來源:pydoc.py

示例12: getdocloc

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def getdocloc(self, object,
                  basedir=os.path.join(sys.exec_prefix, "lib",
                                       "python"+sys.version[0:3])):
        """Return the location of module docs or None"""

        try:
            file = inspect.getabsfile(object)
        except TypeError:
            file = '(built-in)'

        docloc = os.environ.get("PYTHONDOCS",
                                "https://docs.python.org/library")
        basedir = os.path.normcase(basedir)
        if (isinstance(object, type(os)) and
            (object.__name__ in ('errno', 'exceptions', 'gc', 'imp',
                                 'marshal', 'posix', 'signal', 'sys',
                                 'thread', 'zipimport') or
             (file.startswith(basedir) and
              not file.startswith(os.path.join(basedir, 'site-packages')))) and
            object.__name__ not in ('xml.etree', 'test.pydoc_mod')):
            if docloc.startswith(("http://", "https://")):
                docloc = "%s/%s" % (docloc.rstrip("/"), object.__name__.lower())
            else:
                docloc = os.path.join(docloc, object.__name__.lower() + ".html")
        else:
            docloc = None
        return docloc

# -------------------------------------------- HTML documentation generator 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:31,代碼來源:pydoc.py

示例13: test_html_doc

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def test_html_doc(self):
        result, doc_loc = get_pydoc_html(pydoc_mod)
        mod_file = inspect.getabsfile(pydoc_mod)
        if sys.platform == 'win32':
            import nturl2path
            mod_url = nturl2path.pathname2url(mod_file)
        else:
            mod_url = mod_file
        expected_html = expected_html_pattern % (
                        (mod_url, mod_file, doc_loc) +
                        expected_html_data_docstrings)
        if result != expected_html:
            print_diffs(expected_html, result)
            self.fail("outputs are not equal, see diff above") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:16,代碼來源:test_pydoc.py

示例14: test_text_doc

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def test_text_doc(self):
        result, doc_loc = get_pydoc_text(pydoc_mod)
        expected_text = expected_text_pattern % (
                        (inspect.getabsfile(pydoc_mod), doc_loc) +
                        expected_text_data_docstrings)
        if result != expected_text:
            print_diffs(expected_text, result)
            self.fail("outputs are not equal, see diff above") 
開發者ID:IronLanguages,項目名稱:ironpython2,代碼行數:10,代碼來源:test_pydoc.py

示例15: sys_path

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import getabsfile [as 別名]
def sys_path():
    """Detect installation path of exopy.

    Automtically called, DOES NOT use directly. Use exopy_path to get the path
    to the exopy directory.

    """
    import exopy

    # Hiding current app_directory.ini to avoid losing user choice.
    path = os.path.dirname(getabsfile(exopy))
    pref_path = os.path.join(path, APP_PREFERENCES)
    app_dir = os.path.join(pref_path, APP_DIR_CONFIG)
    new = os.path.join(pref_path, '_' + APP_DIR_CONFIG)

    # If a hidden file exists already assume it is because previous test
    # failed and do nothing.
    if os.path.isfile(app_dir) and not os.path.isfile(new):
        os.rename(app_dir, new)

    global EXOPY
    EXOPY = path

    yield

    # Remove created app_directory.ini and put hold one back in place.
    app_dir = os.path.join(pref_path, APP_DIR_CONFIG)
    if os.path.isfile(app_dir):
        os.remove(app_dir)

    # Put user file back in place.
    protected = os.path.join(pref_path, '_' + APP_DIR_CONFIG)
    if os.path.isfile(protected):
        os.rename(protected, app_dir) 
開發者ID:Exopy,項目名稱:exopy,代碼行數:36,代碼來源:fixtures.py


注:本文中的inspect.getabsfile方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。