DRYな備忘録

Don't Repeat Yourself.

【GAE/Go】goappで "There are too many files in your application" と怒られる

追記 2018/08/01

gcloud components update 来てたので、した。

追記

gcloud components updateするとgoogle-cloud-sdk以下のファイルが更新されて魔改造が吹っ飛ぶ。かなしみ。

問題

% goapp serve
INFO     2017-06-07 01:58:24,616 devappserver2.py:692] Skipping SDK update check.
INFO     2017-06-07 01:58:24,646 api_server.py:272] Starting API server at: http://localhost:52623
INFO     2017-06-07 01:58:24,648 dispatcher.py:205] Starting module "default" running at: http://localhost:8080
INFO     2017-06-07 01:58:24,650 admin_server.py:116] Starting admin server at: http://localhost:8000
/Users/otiai10/.google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/mtime_file_watcher.py:157: UserWarning: There are too many files in your application for changes in all of them to be monitored. You may have to restart the development server to see some changes to your files.
  'There are too many files in your application for '

となって、編集検知のオートビルドされなくてちょっと困る。

調査

なんかdevappserverのコード魔改造するしかなさそう。今んとこ。

解決

appengine/tools/devappserver2/mtime_file_watcher.pyを以下のように編集。まずはわかりやすいように。

diff --git a/watcher_common.py b/watcher_common.py
index fe47078..6541de6 100755
--- a/watcher_common.py
+++ b/watcher_common.py
@@ -47,6 +47,11 @@ def ignore_file(filename, skip_files_re=None):
   Returns:
     Boolean value, True if the filename can be ignored.
   """
+  if not filename.startswith(os.getcwd()):
+    return True
+  if filename.find('/node_modules/') is not -1:
+    return True
+
   if skip_files_re and skip_files_re.match(filename):
     return True
   filename = os.path.basename(filename)
  1. カレントディレクトリ以下のファイル以外は監視対象から除外
  2. node_modulesは監視対象から除外

適宜

適宜、たとえば

diff --git a/watcher_common.py b/watcher_common.py
index fe47078..ad1f641 100755
--- a/watcher_common.py
+++ b/watcher_common.py
@@ -47,6 +47,11 @@ def ignore_file(filename, skip_files_re=None):
   Returns:
     Boolean value, True if the filename can be ignored.
   """
+
+  # Watch ONLY current directory if env "GOAPP_WATCH_CWD" is found
+  if os.getenv('GOAPP_WATCH_CWD') and not filename.startswith(os.getcwd()):
+    return True
+
   if skip_files_re and skip_files_re.match(filename):
     return True
   filename = os.path.basename(filename)
@@ -67,7 +72,11 @@ def _remove_pred(lst, pred):

 def ignore_dir(dirpath, dirname, skip_files_re):
   """Report whether a directory should not be watched."""
+
+  # List of directory names to be ignored; e.g. "node_modules", "vendor" or so
+  _IGNORED_DIRS = ('node_modules')
   return (dirname.startswith(_IGNORED_PREFIX) or
+         (dirname in _IGNORED_DIRS) or
           skip_files_re and skip_files_re.match(os.path.join(dirpath, dirname)))

のようにしたらオシャレなのではないか。魔改造には変わりないけど。

DRYな備忘録として

はじめてのGoogle App Engine Go言語編 (I・O BOOKS)

はじめてのGoogle App Engine Go言語編 (I・O BOOKS)

Go言語プログラミング入門on Google App Engine

Go言語プログラミング入門on Google App Engine

プログラミング Google App Engine

プログラミング Google App Engine