Skip to content

Commit

Permalink
Add eq-translations check (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
petechd authored Apr 6, 2020
1 parent daa4058 commit c8f392f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 13 deletions.
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 5 additions & 5 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions scripts/eq_translations_check.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 8 additions & 4 deletions scripts/extract_translation_templates.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#!/usr/bin/env python3

import os
import sys
import subprocess
import tempfile
import logging
import argparse
Expand Down Expand Up @@ -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)))

Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit c8f392f

Please sign in to comment.