Anonymous avatar Anonymous committed c167478

werkzeug.__version__ is now loaded on first access to speed up imports.

Comments (0)

Files changed (2)

     description='The Swiss Army knife of Python web development',
     long_description=__doc__,
     classifiers=[
-        'Development Status :: 4 - Beta',
+        'Development Status :: 5 - Production/Stable',
         'Environment :: Web Environment',
         'Intended Audience :: Developers',
         'License :: OSI Approved :: BSD License',

werkzeug/__init__.py

         object_origins[item] = module
 
 
+#: the cached version of the library.  We get the distribution from
+#: pkg_resources the first time this attribute is accessed.  Because
+#: this operation is quite slow it speeds up importing a lot.
+version = None
+
 class module(ModuleType):
     """Automatically import objects from the modules."""
 
             __import__('werkzeug.' + name)
         return ModuleType.__getattribute__(self, name)
 
+    @property
+    def __version__(self):
+        global version
+        if version is None:
+            try:
+                version = __import__('pkg_resources') \
+                          .get_distribution('Werkzeug').version
+            except:
+                version = 'unknown'
+        return version
 
 # keep a reference to this module so that it's not garbage collected
 old_module = sys.modules['werkzeug']
 
-# figure out the version
-try:
-    version = __import__('pkg_resources').get_distribution('Werkzeug').version
-except:
-    version = 'unknown'
 
 # setup the new module and patch it into the dict of loaded modules
 new_module = sys.modules['werkzeug'] = module('werkzeug')
     '__path__':         __path__,
     '__doc__':          __doc__,
     '__all__':          tuple(object_origins) + tuple(attribute_modules),
-    '__docformat__':    'restructuredtext en',
-    '__version__':      version
+    '__docformat__':    'restructuredtext en'
 })
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.