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


Python compat.npy_load_module方法代碼示例

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


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

示例1: _get_configuration_from_setup_py

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import npy_load_module [as 別名]
def _get_configuration_from_setup_py(self, setup_py,
                                         subpackage_name,
                                         subpackage_path,
                                         parent_name,
                                         caller_level = 1):
        # In case setup_py imports local modules:
        sys.path.insert(0, os.path.dirname(setup_py))
        try:
            setup_name = os.path.splitext(os.path.basename(setup_py))[0]
            n = dot_join(self.name, subpackage_name, setup_name)
            setup_module = npy_load_module('_'.join(n.split('.')),
                                           setup_py,
                                           ('.py', 'U', 1))
            if not hasattr(setup_module, 'configuration'):
                if not self.options['assume_default_configuration']:
                    self.warn('Assuming default configuration '\
                              '(%s does not define configuration())'\
                              % (setup_module))
                config = Configuration(subpackage_name, parent_name,
                                       self.top_path, subpackage_path,
                                       caller_level = caller_level + 1)
            else:
                pn = dot_join(*([parent_name] + subpackage_name.split('.')[:-1]))
                args = (pn,)
                def fix_args_py2(args):
                    if setup_module.configuration.__code__.co_argcount > 1:
                        args = args + (self.top_path,)
                    return args
                def fix_args_py3(args):
                    if setup_module.configuration.__code__.co_argcount > 1:
                        args = args + (self.top_path,)
                    return args
                if sys.version_info[0] < 3:
                    args = fix_args_py2(args)
                else:
                    args = fix_args_py3(args)
                config = setup_module.configuration(*args)
            if config.name!=dot_join(parent_name, subpackage_name):
                self.warn('Subpackage %r configuration returned as %r' % \
                          (dot_join(parent_name, subpackage_name), config.name))
        finally:
            del sys.path[0]
        return config 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:45,代碼來源:misc_util.py

示例2: rundocs

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import npy_load_module [as 別名]
def rundocs(filename=None, raise_on_error=True):
    """
    Run doctests found in the given file.

    By default `rundocs` raises an AssertionError on failure.

    Parameters
    ----------
    filename : str
        The path to the file for which the doctests are run.
    raise_on_error : bool
        Whether to raise an AssertionError when a doctest fails. Default is
        True.

    Notes
    -----
    The doctests can be run by the user/developer by adding the ``doctests``
    argument to the ``test()`` call. For example, to run all tests (including
    doctests) for `numpy.lib`:

    >>> np.lib.test(doctests=True)  # doctest: +SKIP
    """
    from numpy.compat import npy_load_module
    import doctest
    if filename is None:
        f = sys._getframe(1)
        filename = f.f_globals['__file__']
    name = os.path.splitext(os.path.basename(filename))[0]
    m = npy_load_module(name, filename)

    tests = doctest.DocTestFinder().find(m)
    runner = doctest.DocTestRunner(verbose=False)

    msg = []
    if raise_on_error:
        out = lambda s: msg.append(s)
    else:
        out = None

    for test in tests:
        runner.run(test, out=out)

    if runner.failures > 0 and raise_on_error:
        raise AssertionError("Some doctests failed:\n%s" % "\n".join(msg)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:46,代碼來源:utils.py

示例3: _init_info_modules

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import npy_load_module [as 別名]
def _init_info_modules(self, packages=None):
        """Initialize info_modules = {<package_name>: <package info.py module>}.
        """
        from numpy.compat import npy_load_module
        info_files = []
        info_modules = self.info_modules

        if packages is None:
            for path in self.parent_path:
                info_files.extend(self._get_info_files('*', path))
        else:
            for package_name in packages:
                package_dir = os.path.join(*package_name.split('.'))
                for path in self.parent_path:
                    names_files = self._get_info_files(package_dir, path)
                    if names_files:
                        info_files.extend(names_files)
                        break
                else:
                    try:
                        exec('import %s.info as info' % (package_name))
                        info_modules[package_name] = info
                    except ImportError as msg:
                        self.warn('No scipy-style subpackage %r found in %s. '\
                                  'Ignoring: %s'\
                                  % (package_name, ':'.join(self.parent_path), msg))

        for package_name, info_file in info_files:
            if package_name in info_modules:
                continue
            fullname = self.parent_name +'.'+ package_name
            if info_file[-1]=='c':
                filedescriptor = ('.pyc', 'rb', 2)
            else:
                filedescriptor = ('.py', 'U', 1)

            try:
                info_module = npy_load_module(fullname + '.info',
                                              info_file,
                                              filedescriptor)
            except Exception as msg:
                self.error(msg)
                info_module = None

            if info_module is None or getattr(info_module, 'ignore', False):
                info_modules.pop(package_name, None)
            else:
                self._init_info_modules(getattr(info_module, 'depends', []))
                info_modules[package_name] = info_module

        return 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:53,代碼來源:_import_tools.py

示例4: rundocs

# 需要導入模塊: from numpy import compat [as 別名]
# 或者: from numpy.compat import npy_load_module [as 別名]
def rundocs(filename=None, raise_on_error=True):
    """
    Run doctests found in the given file.

    By default `rundocs` raises an AssertionError on failure.

    Parameters
    ----------
    filename : str
        The path to the file for which the doctests are run.
    raise_on_error : bool
        Whether to raise an AssertionError when a doctest fails. Default is
        True.

    Notes
    -----
    The doctests can be run by the user/developer by adding the ``doctests``
    argument to the ``test()`` call. For example, to run all tests (including
    doctests) for `numpy.lib`:

    >>> np.lib.test(doctests=True) #doctest: +SKIP
    """
    from numpy.compat import npy_load_module
    import doctest
    if filename is None:
        f = sys._getframe(1)
        filename = f.f_globals['__file__']
    name = os.path.splitext(os.path.basename(filename))[0]
    m = npy_load_module(name, filename)

    tests = doctest.DocTestFinder().find(m)
    runner = doctest.DocTestRunner(verbose=False)

    msg = []
    if raise_on_error:
        out = lambda s: msg.append(s)
    else:
        out = None

    for test in tests:
        runner.run(test, out=out)

    if runner.failures > 0 and raise_on_error:
        raise AssertionError("Some doctests failed:\n%s" % "\n".join(msg)) 
開發者ID:ryfeus,項目名稱:lambda-packs,代碼行數:46,代碼來源:utils.py


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