provision: Extract need_to_run_build_pygments_data.

This is more encapsulated and more efficient.

In the cases where `is_force` is `True` or
`pygments_data.json` is missing, we now avoid
the unnecessary step of importing `pygments`, at
least up front.

(Of course, we probably import that once we generate
the artifacts.)
This commit is contained in:
Steve Howell 2020-04-16 13:00:48 +00:00 committed by Tim Abbott
parent 796351ed9e
commit 66234850ba
1 changed files with 18 additions and 6 deletions

View File

@ -94,6 +94,23 @@ def setup_bash_profile() -> None:
# no existing bash profile found; claim .bash_profile # no existing bash profile found; claim .bash_profile
setup_shell_profile(BASH_PROFILES[0]) setup_shell_profile(BASH_PROFILES[0])
def need_to_run_build_pygments_data() -> bool:
if not os.path.exists("static/generated/pygments_data.json"):
return True
build_pygments_data_paths = [
"tools/setup/build_pygments_data",
"tools/setup/lang.json",
]
from pygments import __version__ as pygments_version
return file_or_package_hash_updated(
build_pygments_data_paths,
"build_pygments_data_hash",
[pygments_version]
)
def need_to_run_compilemessages() -> bool: def need_to_run_compilemessages() -> bool:
if not os.path.exists('locale/language_name_map.json'): if not os.path.exists('locale/language_name_map.json'):
# User may have cleaned their git checkout. # User may have cleaned their git checkout.
@ -139,12 +156,7 @@ def main(options: argparse.Namespace) -> int:
# copy over static files from the zulip_bots package # copy over static files from the zulip_bots package
generate_zulip_bots_static_files() generate_zulip_bots_static_files()
build_pygments_data_paths = ["tools/setup/build_pygments_data", "tools/setup/lang.json"] if options.is_force or need_to_run_build_pygments_data():
from pygments import __version__ as pygments_version
if (options.is_force or
not os.path.exists("static/generated/pygments_data.json") or
file_or_package_hash_updated(
build_pygments_data_paths, "build_pygments_data_hash", [pygments_version])):
run(["tools/setup/build_pygments_data"]) run(["tools/setup/build_pygments_data"])
else: else:
print("No need to run `tools/setup/build_pygments_data`.") print("No need to run `tools/setup/build_pygments_data`.")