Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

loader.is_package is a optional method #487

Closed
RonnyPfannschmidt opened this Issue Apr 10, 2012 · 3 comments

Comments

Projects
None yet
4 participants
Contributor

RonnyPfannschmidt commented Apr 10, 2012

flask relies on loader.is_package in find_package(import_name) of flask.helpers

however that method is optional as per PEP 302, this it breaks with loaders that don't implement it

Owner

untitaker commented Oct 20, 2012

Would it be okay to replace

loader.is_package(root_mod_name)

with

package_path.endswith('__init__.py')

idella commented Aug 16, 2013

and..

import_name = 'tests'

    def find_package(import_name):
        """Finds a package and returns the prefix (or None if the package is
        not installed) as well as the folder that contains the package or
        module as a tuple.  The package path returned is the module that would
        have to be added to the pythonpath in order to make it possible to
        import the module.  The prefix is the path below which a UNIX like
        folder structure exists (lib, share etc.).
        """
        root_mod_name = import_name.split('.')[0]
        loader = pkgutil.get_loader(root_mod_name)
        if loader is None or import_name == '__main__':
            # import name is not found, or interactive/main module
            package_path = os.getcwd()
        else:
            # For .egg, zipimporter does not have get_filename until Python 2.7.
            if hasattr(loader, 'get_filename'):
                filename = loader.get_filename(root_mod_name)
            elif hasattr(loader, 'archive'):
                # zipimporter's loader.archive points to the .egg or .zip
                # archive filename is dropped in call to dirname below.
                filename = loader.archive
            else:
                # At least one loader is missing both get_filename and archive:
                # Google App Engine's HardenedModulesHook
                #
                # Fall back to imports.
                __import__(import_name)
                filename = sys.modules[import_name].__file__
            package_path = os.path.abspath(os.path.dirname(filename))
            # package_path ends with __init__.py for a package
>           if loader.is_package(root_mod_name):
E           AttributeError: 'AssertionRewritingHook' object has no attribute 'is_package'

/usr/lib64/python2.6/site-packages/flask/helpers.py:727: AttributeError
==========================6 error in 6.22 seconds ==================================

so indeed it happened. I edited the flask /usr/lib64/python2.7/site-packages/flask/helpers.py with the above;

flask $ PYTHON_TARGETS=python2_7 ebuild ../flask-script/flask-script-0.6.2.ebuild clean test

yields

 * python2_7: running distutils-r1_run_phase python_test
====================================================== test session starts =======================================================
platform linux2 -- Python 2.7.5 -- pytest-2.3.5 -- /usr/bin/python2.7
plugins: cov
collecting ... collected 36 items
--------------------------------------------------
==============================36 passed in 5.45 seconds =============================

so it works. Please do commit.

Contributor

DasIch commented Jul 26, 2014

This has been fixed some time ago.

@DasIch DasIch closed this Jul 26, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment