Skip to content

Commit

Permalink
tools/minify-js: Improve type checking.
Browse files Browse the repository at this point in the history
* Use Optional where needed.
* Add type to variables because otherwise it'll be Any.
  • Loading branch information
sharmaeklavya2 authored and timabbott committed May 24, 2017
1 parent b805e0c commit 2314c0f
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions tools/minify-js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ prev_deploy = args.prev_deploy
# JavaScript source files to minify (and what output files to create).
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
import scripts.lib.setup_path_on_import
from typing import Optional, Set
from typing import Any, Dict, Optional, Set

os.environ['DJANGO_SETTINGS_MODULE'] = 'zproject.settings'
from django.conf import settings
Expand All @@ -37,7 +37,7 @@ subprocess.check_call(['tools/compile-handlebars-templates'])
subprocess.check_call(['tools/webpack'])

def get_changed_source_files(other_checkout):
# type: (Optional[str]) -> Optional[Set[str]]
# type: (str) -> Optional[Set[str]]
""" Get list of changed static files since other_checkout.
If git fails to return a reasonable looking list, this returns None,
in which case it should be assumed no files can be reused from
Expand Down Expand Up @@ -78,9 +78,11 @@ def get_changed_source_files(other_checkout):

changed_files = set() # type: Set[str]
if prev_deploy:
changed_files = get_changed_source_files(prev_deploy)
if changed_files is None:
changed_files_tmp = get_changed_source_files(prev_deploy)
if changed_files_tmp is None:
prev_deploy = None
else:
changed_files = changed_files_tmp

# Always use the newly compiled handlebars templates and webpack bundle.
if prev_deploy:
Expand All @@ -102,7 +104,10 @@ MIN_DIR = os.path.join(STATIC_PATH, 'min/')
MAP_DIR = os.path.join(STATIC_PATH, 'source-map/')
subprocess.check_call(['mkdir', '-p', MIN_DIR, MAP_DIR])

for js_group, filespec in six.iteritems(JS_SPECS):
for js_group_filespec_pair in six.iteritems(JS_SPECS):
# JS_SPECS is not typed, so forcefully type keys and values being read from JS_SPECS
js_group = js_group_filespec_pair[0] # type: str
filespec = js_group_filespec_pair[1] # type: Dict[str, Any]
# JS_SPECS look like 'js/foobar.js'.
# changed_files look like 'static/js/foobar.js'.
# So we prepend 'static/' to the JS_SPECS so these match up.
Expand Down

0 comments on commit 2314c0f

Please sign in to comment.