Merge lp:~rharding/launchpad/watch_jsbuild into lp:launchpad

Proposed by Richard Harding
Status: Merged
Approved by: Richard Harding
Approved revision: no longer in the source branch.
Merged at revision: 14881
Proposed branch: lp:~rharding/launchpad/watch_jsbuild
Merge into: lp:launchpad
Prerequisite: lp:~rharding/launchpad/use_lpjsmin
Diff against target: 93 lines (+40/-1)
4 files modified
Makefile (+5/-1)
buildout-templates/bin/watch_jsbuild.in (+31/-0)
buildout.cfg (+2/-0)
versions.cfg (+2/-0)
To merge this branch: bzr merge lp:~rharding/launchpad/watch_jsbuild
Reviewer Review Type Date Requested Status
j.c.sackett (community) Approve
Review via email: mp+94379@code.launchpad.net

Commit message

[r=jcsackett][no-qa] Add a new make command `jsbuild_watch` that uses a running python script to auto build js files as changed.

Description of the change

= Summary =
In order to test and work with JS changes, you need to rebuild the JS files into the combo root, minimize, etc. This is done from the command `make jsbuild`, but it's a manual command that severly slows down development.

This adds a new make command `make jsbuild_watch` that will run a constant process, watching for changed JS files, and auto building them on the fly. In this way you shouldn't have to manually run `make jsbuild` while the process is running.

The only works for the combo loader and so isn't helpful if that feature flag isn't enabled.

== Proposed Fix ==
Adds a watch script and a make command to start it up manually. It runs and is killed with just a ctrl-c for now.

== Implementation Details ==
The watch_jsbuild.py script watching any changed files in lib. It checks them to see if they're non-test JS files. If so, it copies and minifies them into the build directory for the combo loader.

The script uses pyinotify to watch the lib directory and all sub directories for changed files.

To post a comment you must log in.
Revision history for this message
j.c.sackett (jcsackett) wrote :

As we discussed in IRC, the event.mask == pyinotify.IN_MODIFY should be changed to .IN_CREATE in the process_IN_CREATE method.

review: Needs Fixing
Revision history for this message
Robert Collins (lifeless) wrote :

Also, you have both made this a buildout template *and manually* run
it via bin/py: pick one.

-Rob

Revision history for this message
j.c.sackett (jcsackett) wrote :

Thanks for making that change.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Makefile'
2--- Makefile 2012-02-23 12:15:01 +0000
3+++ Makefile 2012-02-28 19:50:37 +0000
4@@ -63,7 +63,8 @@
5 bin/harness bin/iharness bin/ipy bin/jsbuild bin/lpjsmin\
6 bin/killservice bin/kill-test-services bin/lint.sh bin/retest \
7 bin/run bin/run-testapp bin/sprite-util bin/start_librarian bin/stxdocs \
8- bin/tags bin/test bin/tracereport bin/twistd bin/update-download-cache
9+ bin/tags bin/test bin/tracereport bin/twistd bin/update-download-cache \
10+ bin/watch_jsbuild
11
12 BUILDOUT_TEMPLATES = buildout-templates/_pythonpath.py.in
13
14@@ -179,6 +180,9 @@
15 --srcdir lib/lp/app/javascript \
16 --builddir $(LP_BUILT_JS_ROOT)
17
18+jsbuild_watch:
19+ $(PY) bin/watch_jsbuild
20+
21 $(JS_LP): jsbuild_widget_css
22 $(JS_YUI):
23 cp -a lib/canonical/launchpad/icing/yui_2.7.0b/build build/js/yui2
24
25=== added file 'buildout-templates/bin/watch_jsbuild.in'
26--- buildout-templates/bin/watch_jsbuild.in 1970-01-01 00:00:00 +0000
27+++ buildout-templates/bin/watch_jsbuild.in 2012-02-28 19:50:37 +0000
28@@ -0,0 +1,31 @@
29+#!/usr/bin/env python
30+import os
31+import re
32+from jsautobuild import YUIBuilder
33+
34+# Using ionotify we watch our sources of JavaScript in order to know we should
35+# build when the files change.
36+
37+def lp_path_builder(changed_path, **builder_props):
38+ """The custom bit of LP code that determines where files get moved to"""
39+ # to start out let's assume your CWD is where we're referencing things from
40+ CWD = os.getcwd()
41+ JSDIR = os.path.join(CWD, builder_props['build_dir'])
42+ RENAME = re.compile("^.*lib/lp/(.*)/javascript")
43+
44+ match = RENAME.search(changed_path)
45+ js_dir = match.groups()[0]
46+ return os.path.join(JSDIR, RENAME.sub(js_dir, changed_path))
47+
48+
49+if __name__ == "__main__":
50+ build_dir = 'build/js/lp'
51+ meta_name = 'LP_MODULES'
52+ watch_dir = 'lib'
53+
54+ builder = YUIBuilder(lp_path_builder,
55+ build_dir,
56+ watch_dir=watch_dir,
57+ meta_jsmodule=meta_name)
58+
59+ builder.run()
60
61=== modified file 'buildout.cfg'
62--- buildout.cfg 2012-02-21 20:48:55 +0000
63+++ buildout.cfg 2012-02-28 19:50:37 +0000
64@@ -67,7 +67,9 @@
65 eggs = lp
66 funkload
67 zc.zservertracelog
68+ pyinotify
69 lpjsmin
70+ jsautobuild
71 # XXX gary 2009-5-12 bug 375751:
72 # Make mailman built and installed in a more normal way.
73 extra-paths =
74
75=== modified file 'versions.cfg'
76--- versions.cfg 2012-02-24 14:15:47 +0000
77+++ versions.cfg 2012-02-28 19:50:37 +0000
78@@ -28,6 +28,7 @@
79 httplib2 = 0.6.0
80 ipython = 0.9.1
81 iso8601 = 0.1.4
82+jsautobuild = 0.2
83 Jinja2 = 2.2
84 keyring = 0.6.2
85 launchpadlib = 1.9.12
86@@ -69,6 +70,7 @@
87 pyasn1 = 0.0.9a
88 pycrypto = 2.0.1
89 pydkim = 0.3-mbp-r7
90+pyinotify = 0.9.3
91 # Unreleased Pygments trunk which includes fixes for issues 618 and 697 (LP
92 # bug 834427). Can be replaced with Pygments 1.5 once it is released.
93 Pygments = 1.4dev-20111007