Repository: oppia/oppia

Issue:
Ignore copying python files when generating build directory
Ignore copying python files when generating build directory

As per our discussion over email.

/cc @seanlip @BenHenning 



Discussion:

Resolving patch:
diff --git a/scripts/build.py b/scripts/build.py
--- a/scripts/build.py
+++ b/scripts/build.py
@@ -28,7 +28,7 @@
 YUICOMPRESSOR_DIR = os.path.join(
     '..', 'oppia_tools', 'yuicompressor-2.4.8', 'yuicompressor-2.4.8.jar')
 
-FILE_EXTENSIONS_TO_COPY_WITHOUT_MINIFICATION = ['.json', '.png']
+FILE_EXTENSIONS_TO_IGNORE = ['.py']
 
 
 def _minify(source_path, target_path):
@@ -106,13 +106,11 @@ def copy_files_source_to_target(source, target):
             shutil.copyfile(source_path, target_path)
 
 
-def build_files(source, target, ignore):
+def build_files(source, target):
     """Minifies all css and js files, and removes whitespace from html in source
-    directory and copies it to target, ignoring paths/files mentioned in ignore.
-    Copies files in ignore to target without any changes.
+    directory and copies it to target.
     Arguments:
         source, target: strings
-        ignore: list of files/paths to ignore
     """
     print 'Processing %s' % os.path.join(os.getcwd(), source)
     print 'Generating into %s' % os.path.join(os.getcwd(), target)
@@ -130,22 +128,19 @@ def build_files(source, target, ignore):
                 continue
             target_path = source_path.replace(source, target)
 
-            # Only copy files in ignore or with extensions mentioned in
-            # FILE_EXTENSIONS_TO_COPY_WITHOUT_MINIFICATION variable.
-            file_patterns_to_ignore = (
-                ignore + FILE_EXTENSIONS_TO_COPY_WITHOUT_MINIFICATION)
-            if any(p in source_path for p in file_patterns_to_ignore):
-                ensure_directory_exists(target_path)
-                shutil.copyfile(source_path, target_path)
+            # Ignore files with certain extensions
+            if any(source_path.endswith(p) for p in FILE_EXTENSIONS_TO_IGNORE):
                 continue
 
             if filename.endswith('.html'):
                 process_html(source_path, target_path)
-            if filename.endswith('.css'):
+            elif filename.endswith('.css'):
                 process_css(source_path, target_path)
-            if filename.endswith('.js'):
+            elif filename.endswith('.js'):
                 process_js(source_path, target_path)
-
+            else:
+                ensure_directory_exists(target_path)
+                shutil.copyfile(source_path, target_path)
 
 def get_cache_slug():
     """Returns the cache slug read from file."""
@@ -179,15 +174,11 @@ def get_cache_slug():
     # build/[cache_slug]/extensions
     EXTENSIONS_SRC_DIR = os.path.join('extensions', '')
     EXTENSIONS_OUT_DIR = os.path.join(BUILD_DIR, 'extensions', '')
-    # Certain files' syntax become incorrect after minification and hence
-    # they are ignored.
-    IGNORE_PATHS = [os.path.join('extensions', 'interactions',
-                                 'LogicProof', 'static', 'js')]
-    build_files(EXTENSIONS_SRC_DIR, EXTENSIONS_OUT_DIR, IGNORE_PATHS)
+    build_files(EXTENSIONS_SRC_DIR, EXTENSIONS_OUT_DIR)
 
     TEMPLATES_HEAD_DIR = os.path.join('core', 'templates', 'dev', 'head', '')
     TEMPLATES_OUT_DIR = os.path.join('core', 'templates', 'prod', 'head', '')
-    build_files(TEMPLATES_HEAD_DIR, TEMPLATES_OUT_DIR, [])
+    build_files(TEMPLATES_HEAD_DIR, TEMPLATES_OUT_DIR)
 
     # Process core/templates/prod/head/css, copy it to build/[cache_slug]/css
     CSS_SRC_DIR = os.path.join('core', 'templates', 'prod', 'head', 'css', '')


Test patch: