-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure npm install runs once at a time #9
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import os | ||
import threading | ||
|
||
from lektor.pluginsystem import Plugin | ||
from lektor.reporter import reporter | ||
|
@@ -11,6 +12,7 @@ class WebpackSupportPlugin(Plugin): | |
|
||
def __init__(self, *args, **kwargs): | ||
Plugin.__init__(self, *args, **kwargs) | ||
self.npm_lock = threading.Lock() | ||
self.webpack_process = None | ||
|
||
def is_enabled(self, extra_flags): | ||
|
@@ -24,9 +26,13 @@ def run_webpack(self, watch=False): | |
return portable_popen(args, cwd=webpack_root) | ||
|
||
def npm_install(self): | ||
reporter.report_generic('Running npm install') | ||
webpack_root = os.path.join(self.env.root_path, 'webpack') | ||
portable_popen(['npm', 'install'], cwd=webpack_root).wait() | ||
if self.npm_lock.acquire(False): | ||
reporter.report_generic('Running npm install') | ||
webpack_root = os.path.join(self.env.root_path, 'webpack') | ||
portable_popen(['npm', 'install'], cwd=webpack_root).wait() | ||
else: | ||
self.npm_lock.acquire() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you acquiring the lock here, if you're not doing anything with it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To maintain the behavior that this method does not exit until the |
||
self.npm_lock.release() | ||
|
||
def on_server_spawn(self, **extra): | ||
extra_flags = extra.get("extra_flags") or extra.get("build_flags") or {} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you specify
blocking=False
here? I had to look up the documentation forthreading.Lock
to understand what thisFalse
was for.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly, no:
Would an inline comment be useful?