Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
66ac9b01
Commit
66ac9b01
authored
Apr 04, 2016
by
Omar Khan
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #11849 from open-craft/omar/watch-assets
Fix paver watch_assets
parents
9baae2ff
53642579
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
12 deletions
+41
-12
pavelib/assets.py
+35
-6
pavelib/paver_tests/test_assets.py
+5
-5
requirements/edx/base.txt
+1
-1
No files found.
pavelib/assets.py
View file @
66ac9b01
...
...
@@ -4,13 +4,15 @@ Asset compilation and collection.
from
__future__
import
print_function
from
datetime
import
datetime
from
functools
import
wraps
from
threading
import
Timer
import
argparse
import
glob
import
traceback
from
paver
import
tasks
from
paver.easy
import
sh
,
path
,
task
,
cmdopts
,
needs
,
consume_args
,
call_task
,
no_help
from
watchdog.observers
import
Observer
from
watchdog.observers
.polling
import
Polling
Observer
from
watchdog.events
import
PatternMatchingEventHandler
from
.utils.envs
import
Env
...
...
@@ -239,6 +241,29 @@ def get_watcher_dirs(themes_base_dir=None, themes=None):
return
dirs
def
debounce
(
seconds
=
1
):
"""
Prevents the decorated function from being called more than every `seconds`
seconds. Waits until calls stop coming in before calling the decorated
function.
"""
def
decorator
(
func
):
# pylint: disable=missing-docstring
func
.
timer
=
None
@wraps
(
func
)
def
wrapper
(
*
args
,
**
kwargs
):
# pylint: disable=missing-docstring
def
call
():
# pylint: disable=missing-docstring
func
(
*
args
,
**
kwargs
)
func
.
timer
=
None
if
func
.
timer
:
func
.
timer
.
cancel
()
func
.
timer
=
Timer
(
seconds
,
call
)
func
.
timer
.
start
()
return
wrapper
return
decorator
class
CoffeeScriptWatcher
(
PatternMatchingEventHandler
):
"""
Watches for coffeescript changes
...
...
@@ -256,7 +281,8 @@ class CoffeeScriptWatcher(PatternMatchingEventHandler):
for
dirname
in
dirnames
:
observer
.
schedule
(
self
,
dirname
)
def
on_modified
(
self
,
event
):
@debounce
()
def
on_any_event
(
self
,
event
):
print
(
'
\t
CHANGED:'
,
event
.
src_path
)
try
:
compile_coffeescript
(
event
.
src_path
)
...
...
@@ -289,7 +315,8 @@ class SassWatcher(PatternMatchingEventHandler):
for
dirname
in
paths
:
observer
.
schedule
(
self
,
dirname
,
recursive
=
True
)
def
on_modified
(
self
,
event
):
@debounce
()
def
on_any_event
(
self
,
event
):
print
(
'
\t
CHANGED:'
,
event
.
src_path
)
try
:
compile_sass
()
# pylint: disable=no-value-for-parameter
...
...
@@ -304,7 +331,8 @@ class XModuleSassWatcher(SassWatcher):
ignore_directories
=
True
ignore_patterns
=
[]
def
on_modified
(
self
,
event
):
@debounce
()
def
on_any_event
(
self
,
event
):
print
(
'
\t
CHANGED:'
,
event
.
src_path
)
try
:
process_xmodule_assets
()
...
...
@@ -325,7 +353,8 @@ class XModuleAssetsWatcher(PatternMatchingEventHandler):
"""
observer
.
schedule
(
self
,
'common/lib/xmodule/'
,
recursive
=
True
)
def
on_modified
(
self
,
event
):
@debounce
()
def
on_any_event
(
self
,
event
):
print
(
'
\t
CHANGED:'
,
event
.
src_path
)
try
:
process_xmodule_assets
()
...
...
@@ -635,7 +664,7 @@ def watch_assets(options):
themes
=
themes
if
isinstance
(
themes
,
list
)
else
[
themes
]
sass_directories
=
get_watcher_dirs
(
theme_base_dir
,
themes
)
observer
=
Observer
()
observer
=
Polling
Observer
()
CoffeeScriptWatcher
()
.
register
(
observer
)
SassWatcher
()
.
register
(
observer
,
sass_directories
)
...
...
pavelib/paver_tests/test_assets.py
View file @
66ac9b01
...
...
@@ -6,7 +6,7 @@ from unittest import TestCase
from
paver.easy
import
call_task
from
paver.easy
import
path
from
mock
import
patch
from
watchdog.observers
import
Observer
from
watchdog.observers
.polling
import
Polling
Observer
from
.utils
import
PaverTestCase
ROOT_PATH
=
path
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
os
.
path
.
dirname
(
__file__
))))
...
...
@@ -161,7 +161,7 @@ class TestPaverWatchAssetTasks(TestCase):
Test the "compile_sass" task.
"""
with
patch
(
'pavelib.assets.SassWatcher.register'
)
as
mock_register
:
with
patch
(
'pavelib.assets.Observer.start'
):
with
patch
(
'pavelib.assets.
Polling
Observer.start'
):
call_task
(
'pavelib.assets.watch_assets'
,
options
=
{
"background"
:
True
},
...
...
@@ -170,7 +170,7 @@ class TestPaverWatchAssetTasks(TestCase):
sass_watcher_args
=
mock_register
.
call_args_list
[
0
][
0
]
self
.
assertIsInstance
(
sass_watcher_args
[
0
],
Observer
)
self
.
assertIsInstance
(
sass_watcher_args
[
0
],
Polling
Observer
)
self
.
assertIsInstance
(
sass_watcher_args
[
1
],
list
)
self
.
assertItemsEqual
(
sass_watcher_args
[
1
],
self
.
expected_sass_directories
)
...
...
@@ -186,7 +186,7 @@ class TestPaverWatchAssetTasks(TestCase):
])
with
patch
(
'pavelib.assets.SassWatcher.register'
)
as
mock_register
:
with
patch
(
'pavelib.assets.Observer.start'
):
with
patch
(
'pavelib.assets.
Polling
Observer.start'
):
call_task
(
'pavelib.assets.watch_assets'
,
options
=
{
"background"
:
True
,
"themes_dir"
:
TEST_THEME
.
dirname
(),
...
...
@@ -195,7 +195,7 @@ class TestPaverWatchAssetTasks(TestCase):
self
.
assertEqual
(
mock_register
.
call_count
,
2
)
sass_watcher_args
=
mock_register
.
call_args_list
[
0
][
0
]
self
.
assertIsInstance
(
sass_watcher_args
[
0
],
Observer
)
self
.
assertIsInstance
(
sass_watcher_args
[
0
],
Polling
Observer
)
self
.
assertIsInstance
(
sass_watcher_args
[
1
],
list
)
self
.
assertItemsEqual
(
sass_watcher_args
[
1
],
self
.
expected_sass_directories
)
...
...
requirements/edx/base.txt
View file @
66ac9b01
...
...
@@ -114,7 +114,7 @@ reportlab==3.1.44
pdfminer==20140328
# Used for development operation
watchdog==0.
7.1
watchdog==0.
8.3
# Metrics gathering and monitoring
dogapi==1.2.1
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment