From 109fa85614a2a66343bdb68253edadf8a879e0d7 Mon Sep 17 00:00:00 2001 From: Vishnu Ks Date: Fri, 22 Jun 2018 16:26:25 +0530 Subject: [PATCH] provision: Rename file_hash_updated to file_or_package_hash_updated. Check for changes in package version as well along with the files. --- scripts/lib/zulip_tools.py | 11 +++++++++-- tools/lib/provision.py | 8 ++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/scripts/lib/zulip_tools.py b/scripts/lib/zulip_tools.py index ed411d9413..692df66f58 100755 --- a/scripts/lib/zulip_tools.py +++ b/scripts/lib/zulip_tools.py @@ -313,13 +313,20 @@ def parse_lsb_release(): distro_info[k] = v return distro_info -def file_hash_updated(paths, hash_name, is_force): - # type: (List[str], str, bool) -> bool +def file_or_package_hash_updated(paths, hash_name, is_force, package_versions=[]): + # type: (List[str], str, bool, List[str]) -> bool + # Check whether the files or package_versions passed as arguments + # changed compared to the last execution. sha1sum = hashlib.sha1() for path in paths: with open(path, 'rb') as file_to_hash: sha1sum.update(file_to_hash.read()) + # The ouput of tools like build_pygments_data depends + # on the version of some pip packages as well. + for package_version in package_versions: + sha1sum.update(package_version.encode("utf-8")) + hash_path = os.path.join(get_dev_uuid_var_path(), hash_name) new_hash = sha1sum.hexdigest() run(['touch', hash_path]) diff --git a/tools/lib/provision.py b/tools/lib/provision.py index cf8f6c7d0f..04dd55df9a 100755 --- a/tools/lib/provision.py +++ b/tools/lib/provision.py @@ -14,7 +14,7 @@ ZULIP_PATH = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__f sys.path.append(ZULIP_PATH) from scripts.lib.zulip_tools import run, subprocess_text_output, OKBLUE, ENDC, WARNING, \ - get_dev_uuid_var_path, FAIL, parse_lsb_release, file_hash_updated + get_dev_uuid_var_path, FAIL, parse_lsb_release, file_or_package_hash_updated from scripts.lib.setup_venv import ( setup_virtualenv, VENV_DEPENDENCIES, THUMBOR_VENV_DEPENDENCIES ) @@ -296,7 +296,7 @@ def main(options): webfont_paths = ["tools/generate-custom-icon-webfont", "static/icons/fonts/template.hbs"] webfont_paths += glob.glob('static/assets/icons/*') - if file_hash_updated(webfont_paths, "webfont_files_hash", options.is_force): + if file_or_package_hash_updated(webfont_paths, "webfont_files_hash", options.is_force): run(["tools/generate-custom-icon-webfont"]) else: print("No need to run `tools/generate-custom-icon-webfont`.") @@ -307,7 +307,7 @@ def main(options): email_source_paths = ["tools/inline-email-css", "templates/zerver/emails/email.css"] email_source_paths += glob.glob('templates/zerver/emails/*.source.html') - if file_hash_updated(email_source_paths, "last_email_source_files_hash", options.is_force): + if file_or_package_hash_updated(email_source_paths, "last_email_source_files_hash", options.is_force): run(["tools/inline-email-css"]) else: print("No need to run `tools/inline-email-css`.") @@ -377,7 +377,7 @@ def main(options): paths += glob.glob('static/locale/*/LC_MESSAGES/*.po') paths += glob.glob('static/locale/*/translations.json') - if file_hash_updated(paths, "last_compilemessages_hash", options.is_force): + if file_or_package_hash_updated(paths, "last_compilemessages_hash", options.is_force): run(["./manage.py", "compilemessages"]) else: print("No need to run `manage.py compilemessages`.")