Better support for namespace packages.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Armin Ronacher · committed by Armin Ronacher · parent a293b99 · Browse files · 4 files·+37 added−7 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+37 added−7 removed
- other:+37 added−7 removed
Provenance
- Commit
d4b3d16- Tree
475fcca- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
a293b99
4 files changed+37 added−7 removed
modified:flask/app.py+12 added-2 removed
116 unmodified lines117 .. versionadded:: 0.8118 The `instance_path` and `instance_relative_config` parameters were119 added.120 121+ .. versionadded:: 1.0122+ The `root_path` parameter was added.123+124 :param import_name: the name of the application package125 :param static_url_path: can be used to specify a different path for the126 static files on the web. Defaults to the name127 of the `static_folder` folder.11 unmodified lines139 :param instance_relative_config: if set to `True` relative filenames140 for loading the config are assumed to141 be relative to the instance path instead142 of the application root.143+ :param root_path: Flask by default will automatically calculate the path144+ to the root of the application. In certain situations145+ this cannot be achieved (for instance if the package146+ is a Python 3 namespace package) and needs to be147+ manually defined.148 """149 150 #: The class that is used for request objects. See :class:`~flask.Request`151 #: for more information.182 unmodified lines334 session_interface = SecureCookieSessionInterface()335 336 def __init__(self, import_name, static_path=None, static_url_path=None,337 static_folder='static', template_folder='templates',330- instance_path=None, instance_relative_config=False):338+ instance_path=None, instance_relative_config=False,339+ root_path=None):340 _PackageBoundObject.__init__(self, import_name,332- template_folder=template_folder)341+ template_folder=template_folder,342+ root_path=root_path)343 if static_path is not None:344 from warnings import warn345 warn(DeprecationWarning('static_path is now called '346 'static_url_path'), stacklevel=2)1535 unmodified linesmodified:flask/blueprints.py+4 added-2 removed
89 unmodified lines90 _got_registered_once = False91 92 def __init__(self, name, import_name, static_folder=None,93 static_url_path=None, template_folder=None,94- url_prefix=None, subdomain=None, url_defaults=None):95- _PackageBoundObject.__init__(self, import_name, template_folder)94+ url_prefix=None, subdomain=None, url_defaults=None,95+ root_path=None):96+ _PackageBoundObject.__init__(self, import_name, template_folder,97+ root_path=root_path)98 self.name = name99 self.url_prefix = url_prefix100 self.subdomain = subdomain101 self.static_folder = static_folder313 unmodified linesmodified:flask/helpers.py+19 added-3 removed
648 unmodified lines649 filepath = loader.get_filename(import_name)650 else:651 # Fall back to imports.652 __import__(import_name)653- filepath = sys.modules[import_name].__file__653+ mod = sys.modules[import_name]654+ filepath = getattr(mod, '__file__', None)655 656+ # If we don't have a filepath it might be because we are a657+ # namespace package. In this case we pick the root path from the658+ # first module that is contained in our package.659+ if filepath is None:660+ raise RuntimeError('No root path can be found for the provided '661+ 'module "%s". This can happen because the '662+ 'module came from an import hook that does '663+ 'not provide file name information or because '664+ 'it\'s a namespace package. In this case '665+ 'the root path needs to be explictly '666+ 'provided.' % import_name)667+668 # filepath is import_name.py for a module, or __init__.py for a package.669 return os.path.dirname(os.path.abspath(filepath))670 671 102 unmodified lines774 775 776 class _PackageBoundObject(object):777 765- def __init__(self, import_name, template_folder=None):778+ def __init__(self, import_name, template_folder=None, root_path=None):779 #: The name of the package or module. Do not change this once780 #: it was set by the constructor.781 self.import_name = import_name782 783 #: location of the templates. `None` if templates should not be784 #: exposed.785 self.template_folder = template_folder786 787+ if root_path is None:788+ root_path = get_root_path(self.import_name)789+790 #: Where is the app root located?775- self.root_path = get_root_path(self.import_name)791+ self.root_path = root_path792 793 self._static_folder = None794 self._static_url_path = None795 104 unmodified linesmodified:CHANGES+2 added
22 unmodified lines23 - Added ``TEMPLATES_AUTO_RELOAD`` config key. If disabled the 24 templates will be reloaded only if the application is running in 25 debug mode. For higher performance it’s possible to disable that.26 - Added a workaround for a limitation in Python 3.3's namespace loader.27+- Added support for explicit root paths when using Python 3.3's namespace28+ packages.29 30 Version 0.10.231 --------------32 478 unmodified lines