Merge lp:~cjwatson/lazr.config/faster-version into lp:lazr.config

Proposed by Colin Watson on 2017-10-05
Status: Merged
Merged at revision: 18
Proposed branch: lp:~cjwatson/lazr.config/faster-version
Merge into: lp:lazr.config
Diff against target: 81 lines (+14/-7)
7 files modified
MANIFEST.in (+1/-1)
conf.py (+3/-1)
setup.py (+2/-1)
src/lazr/config/__init__.py (+2/-3)
src/lazr/config/_version.py (+1/-0)
src/lazr/config/docs/NEWS.rst (+5/-0)
src/lazr/config/version.txt (+0/-1)
To merge this branch: bzr merge lp:~cjwatson/lazr.config/faster-version
Reviewer Review Type Date Requested Status
William Grant code 2017-10-05 Approve on 2017-10-19
Review via email: mp+331833@code.launchpad.net

Commit message

Adjust versioning strategy to avoid importing pkg_resources, which is slow in large environments.

Description of the change

With this and a collection of other changes, I can get the startup time of Launchpad's bin/py down from about 0.95 seconds (after conversion to virtualenv and pip) to about 0.27 seconds on my laptop. pkg_resources accounts for about half a second of that, so is well worth avoiding on the fast path.

To post a comment you must log in.
William Grant (wgrant) :
review: Approve (code)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'MANIFEST.in'
2--- MANIFEST.in 2017-02-08 22:55:13 +0000
3+++ MANIFEST.in 2017-10-05 03:49:07 +0000
4@@ -1,3 +1,3 @@
5 include *.py *.txt *.rst MANIFEST.in *.ini
6-recursive-include src/lazr *.txt *.rst *.conf
7+recursive-include src/lazr *.rst *.conf
8 exclude .bzrignore
9
10=== modified file 'conf.py'
11--- conf.py 2017-02-09 15:31:05 +0000
12+++ conf.py 2017-10-05 03:49:07 +0000
13@@ -49,7 +49,9 @@
14 # built documents.
15 #
16 # The short X.Y version.
17-version = open('src/lazr/config/version.txt').read().strip()
18+with open('src/lazr/config/_version.py') as version_file:
19+ exec(version_file.read()) # sets __version__
20+version = __version__
21 # The full version, including alpha/beta/rc tags.
22 release = version
23
24
25=== modified file 'setup.py'
26--- setup.py 2017-02-08 22:55:13 +0000
27+++ setup.py 2017-10-05 03:49:07 +0000
28@@ -16,7 +16,8 @@
29
30 from setuptools import setup, find_packages
31
32-__version__ = open("src/lazr/config/version.txt").read().strip()
33+with open('src/lazr/config/_version.py') as version_file:
34+ exec(version_file.read()) # sets __version__
35
36 setup(
37 name='lazr.config',
38
39=== modified file 'src/lazr/config/__init__.py'
40--- src/lazr/config/__init__.py 2017-02-07 22:55:50 +0000
41+++ src/lazr/config/__init__.py 2017-10-05 03:49:07 +0000
42@@ -16,9 +16,8 @@
43
44 """A configuration file system."""
45
46-import pkg_resources
47-__version__ = pkg_resources.resource_string(
48- "lazr.config", "version.txt").strip()
49+from lazr.config._version import __version__
50+__version__
51
52 # While we generally frown on "*" imports, this, combined with the fact we
53 # only test code from this module, means that we can verify what has been
54
55=== added file 'src/lazr/config/_version.py'
56--- src/lazr/config/_version.py 1970-01-01 00:00:00 +0000
57+++ src/lazr/config/_version.py 2017-10-05 03:49:07 +0000
58@@ -0,0 +1,1 @@
59+__version__ = '2.2.1'
60
61=== modified file 'src/lazr/config/docs/NEWS.rst'
62--- src/lazr/config/docs/NEWS.rst 2017-02-08 22:55:13 +0000
63+++ src/lazr/config/docs/NEWS.rst 2017-10-05 03:49:07 +0000
64@@ -2,6 +2,11 @@
65 NEWS for lazr.config
66 ====================
67
68+2.2.1 (2017-XX-XX)
69+==================
70+- Adjust versioning strategy to avoid importing pkg_resources, which is slow
71+ in large environments.
72+
73 2.2 (2017-02-07)
74 ================
75 - Fix tox import failure related to https://github.com/tox-dev/tox/issues/453
76
77=== removed file 'src/lazr/config/version.txt'
78--- src/lazr/config/version.txt 2017-02-07 22:55:50 +0000
79+++ src/lazr/config/version.txt 1970-01-01 00:00:00 +0000
80@@ -1,1 +0,0 @@
81-2.2

Subscribers

People subscribed via source and target branches