diff --git a/Makefile b/Makefile index 7bfd521a..704b5cce 100644 --- a/Makefile +++ b/Makefile @@ -15,11 +15,14 @@ lint-jsonnet: validate-schemas: ./scripts/validate_schemas.sh -translate-schemas: +eq-translations-check: + pipenv run python -m scripts.eq_translations_check + +translate-schemas: eq-translations-check pipenv run python -m scripts.translate_schemas -translation-templates: +translation-templates: eq-translations-check pipenv run python -m scripts.extract_translation_templates -test-translation-templates: +test-translation-templates: eq-translations-check pipenv run python -m scripts.extract_translation_templates --test diff --git a/Pipfile b/Pipfile index 3e2e92e0..1da08c76 100644 --- a/Pipfile +++ b/Pipfile @@ -7,7 +7,7 @@ verify_ssl = true coloredlogs = "*" [packages] -eq-translations = {editable = true,git = "https://github.com/ONSDigital/eq-translations.git",ref = "master"} +eq-translations = {editable = true,git = "https://github.com/ONSDigital/eq-translations.git",ref = "v2.0.0"} [requires] python_version = "3.8" diff --git a/Pipfile.lock b/Pipfile.lock index 4012207e..13e04454 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "583a4890b94f6e0d4204d5572708bb961e439c6dc06cff950efb564e5a79138d" + "sha256": "b0e79a188d47e3837729c16237a40901797b579328bcc598d1fc695570458aa3" }, "pipfile-spec": 6, "requires": { @@ -40,7 +40,7 @@ "eq-translations": { "editable": true, "git": "https://github.com/ONSDigital/eq-translations.git", - "ref": "88cc5756ddf6166653f2c5695370f6727facd62c" + "ref": "002886e15594a3042f478250a6fbf290c7ca38b3" }, "idna": { "hashes": [ @@ -78,10 +78,10 @@ }, "tqdm": { "hashes": [ - "sha256:0d8b5afb66e23d80433102e9bd8b5c8b65d34c2a2255b2de58d97bd2ea8170fd", - "sha256:f35fb121bafa030bd94e74fcfd44f3c2830039a2ddef7fc87ef1c2d205237b24" + "sha256:00339634a22c10a7a22476ee946bbde2dbe48d042ded784e4d88e0236eca5d81", + "sha256:ea9e3fd6bd9a37e8783d75bfc4c1faf3c6813da6bd1c3e776488b41ec683af94" ], - "version": "==4.43.0" + "version": "==4.45.0" }, "urllib3": { "hashes": [ diff --git a/scripts/eq_translations_check.py b/scripts/eq_translations_check.py new file mode 100644 index 00000000..f791d72e --- /dev/null +++ b/scripts/eq_translations_check.py @@ -0,0 +1,30 @@ +import logging +import requests +import sys + +import eq_translations + +from requests.exceptions import RequestException + +logger = logging.getLogger(__name__) + +try: + response = requests.get( + "https://api.github.com/repos/ONSdigital/eq-translations/releases" + ) + if response.status_code == 200: + version = f'v{eq_translations.__version__}' + latest_tag = response.json()[0]["tag_name"] + if latest_tag != version: + logger.error( + f'eq-translations is out of date. Update using: "pipenv install -e git+https://github.com/ONSDigital' + f'/eq-translations.git@{version}#egg=eq_translations". ' + ) + sys.exit(1) + else: + logger.error("Can't check eq-translations version") + sys.exit(0) + +except RequestException: + logger.error("Can't check eq-translations version") + sys.exit(0) diff --git a/scripts/extract_translation_templates.py b/scripts/extract_translation_templates.py index 7ea5a203..f7115c1d 100644 --- a/scripts/extract_translation_templates.py +++ b/scripts/extract_translation_templates.py @@ -1,8 +1,6 @@ #!/usr/bin/env python3 - import os import sys -import subprocess import tempfile import logging import argparse @@ -60,7 +58,10 @@ def compare_files(source_dir, target_dir, filename): if not contents_match: diff_results = difflib.unified_diff( - source_contents, target_contents, fromfile=source_file, tofile=target_file + source_contents, + target_contents, + fromfile=source_file, + tofile=target_file, ) logger.info("".join(list(diff_results))) @@ -90,11 +91,14 @@ def check_schema_templates(source_dir, target_dir): if __name__ == "__main__": + parser = argparse.ArgumentParser( description="Extract translation templates from runner" ) parser.add_argument( - "--test", help="Test the templates without making changes", action="store_true" + "--test", + help="Test the templates without making changes", + action="store_true", ) args = parser.parse_args()