[damned-lies] Made the translate-toolkit dependency mandatory
- From: Claude Paroz <claudep src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [damned-lies] Made the translate-toolkit dependency mandatory
- Date: Mon, 26 Mar 2018 14:03:22 +0000 (UTC)
commit 41ee6c69b5ba587a19aa588c7afaeda3e09ae723
Author: Claude Paroz <claude 2xlibre net>
Date: Mon Mar 26 15:03:18 2018 +0200
Made the translate-toolkit dependency mandatory
README | 5 ++---
requirements.txt | 2 +-
stats/tests/tests.py | 26 ++++++--------------------
stats/utils.py | 45 ++++++++++++++++++++++-----------------------
4 files changed, 31 insertions(+), 47 deletions(-)
---
diff --git a/README b/README
index 9492e1c..91ebfd6 100644
--- a/README
+++ b/README
@@ -8,11 +8,12 @@ You can find the Data model in the /docs directory.
Requirements
============
-1 - Django > 1.11.X
+1 - Django > 2.0.X
2 - Python 3.4 (minimal)
pillow (python-pillow) for hackergotchi checks.
Markdown (python-markdown) for Team presentation markup rendering.
+ translate-toolkit >= 2.2
3 - gettext, intltool, gnome-doc-utils (for stats generation), itstool
@@ -25,8 +26,6 @@ Requirements
6 - [Optional] python-pyicu for correct sorting in various languages
-7 - [Optional] translate-toolkit >= 2.0 for reduced po files.
-
Installing all requirements using pip:
pip install -r requirements.txt
diff --git a/requirements.txt b/requirements.txt
index 43704da..583efec 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,4 @@
-django>=1.11
+django>=2.0
mysqlclient
django-debug-toolbar
markdown
diff --git a/stats/tests/tests.py b/stats/tests/tests.py
index 9755ae2..463ea6a 100644
--- a/stats/tests/tests.py
+++ b/stats/tests/tests.py
@@ -136,8 +136,13 @@ class ModuleTestCase(TestCase):
self.branch.update_stats(force=True)
fr_po_stat = Statistics.objects.get(branch=self.branch, domain__name='po', language__locale='fr')
self.assertEqual(fr_po_stat.translated(), 44)
+ self.assertEqual(fr_po_stat.translated(scope='part'), 44)
self.assertEqual(fr_po_stat.translated_words(), 131)
self.assertEqual(fr_po_stat.full_po, fr_po_stat.part_po)
+ self.assertEqual(fr_po_stat.pot_url(), "/POT/gnome-hello.master/gnome-hello.master.pot")
+ self.assertEqual(fr_po_stat.po_url(), "/POT/gnome-hello.master/gnome-hello.master.fr.po")
+ self.assertEqual(fr_po_stat.po_url(reduced=True),
"/POT/gnome-hello.master/gnome-hello.master.fr.reduced.po")
+
# Partial translated file
it_po_stat = Statistics.objects.get(branch=self.branch, domain__name='po', language__locale='it')
self.assertEqual(it_po_stat.translated(), 9)
@@ -148,8 +153,6 @@ class ModuleTestCase(TestCase):
fr_doc_stat = Statistics.objects.get(branch=self.branch, domain__name='help', language__locale='fr')
self.assertEqual(fr_doc_stat.translated(), 41)
self.assertEqual(len(pot_doc_stat.full_po.figures), len(fr_doc_stat.full_po.figures))
- self.assertEqual(fr_po_stat.po_url(), "/POT/gnome-hello.master/gnome-hello.master.fr.po")
- self.assertEqual(fr_po_stat.pot_url(), "/POT/gnome-hello.master/gnome-hello.master.pot")
self.assertEqual(fr_doc_stat.po_url(), "/POT/gnome-hello.master/docs/gnome-hello-help.master.fr.po")
with self.assertRaises(Statistics.DoesNotExist):
Statistics.objects.get(pk=ghost_stat.pk)
@@ -159,10 +162,6 @@ class ModuleTestCase(TestCase):
self.assertTrue(stats['help'][0].is_pot_stats()) # POT first
self.assertEqual(stats['help'][-1].language.locale, 'xxx') # Fake stat last
- if utils.has_toolkit:
- self.assertEqual(fr_po_stat.po_url(reduced=True),
"/POT/gnome-hello.master/gnome-hello.master.fr.reduced.po")
- self.assertEqual(fr_po_stat.translated(scope='part'), 44)
-
@test_scratchdir
def test_branch_exists(self):
branch = Branch.objects.get(name='master', module__name='zenity')
@@ -279,17 +278,7 @@ class ModuleTestCase(TestCase):
# This file is distributed under the same license as the gnome-hello package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.""" % date.today().year)
self.assertContains(response, "Language-Team: Tamil <ta li org>")
- try:
- response = self.client.get('/module/po/gnome-hello/po/master/ta-reduced.po')
- except OSError as e:
- if "msginit" in str(e):
- self.fail(
- "You are probably running an unpatched version of the translate-toolkit. "
- "See http://bugs.locamotion.org/show_bug.cgi?id=2129"
- )
- return
- else:
- raise
+ response = self.client.get('/module/po/gnome-hello/po/master/ta-reduced.po')
self.assertContains(response, """# Tamil translation for gnome-hello.""")
@test_scratchdir
@@ -626,11 +615,8 @@ class UtilsTests(TestCase):
utils.insert_locale_in_linguas(linguas_path, 'xx')
self.assertTrue(linguas_path.read_text().endswith('xx\n'))
- @skipUnless(utils.has_toolkit, "The Translate Toolkit is required for this test")
@test_scratchdir
def test_po_grep(self):
- # This test fails, unless translate-toolkit is patched as presented in
- # https://github.com/translate/translate/issues/2129
# Take it.po, because desktop.in.h strings are not yet translated
it_path = os.path.join(settings.SCRATCHDIR, 'git/gnome-hello/po/it.po')
temp_file = tempfile.NamedTemporaryFile(delete=False)
diff --git a/stats/utils.py b/stats/utils.py
index a931908..0115de4 100644
--- a/stats/utils.py
+++ b/stats/utils.py
@@ -10,22 +10,7 @@ from pathlib import Path
from subprocess import Popen, PIPE
from unittest.mock import MagicMock
-try:
- from translate.tools import pogrep, pocount
- # monkey-patch ttk (https://github.com/translate/translate/issues/2129)
- from translate.storage.base import TranslationStore
- orig_addunit = TranslationStore.addunit
- def patchedAddunit(self, unit):
- # Prevent two header units in the same store
- if unit.isheader() and len(self.units) and self.units[0].isheader():
- unit._store = self
- self.units[0] = unit
- else:
- orig_addunit(self, unit)
- TranslationStore.addunit = patchedAddunit
- has_toolkit = True
-except ImportError:
- has_toolkit = False
+from translate.tools import pogrep, pocount
from django.conf import settings
from django.core.files.base import File
@@ -47,6 +32,21 @@ CHANGED_NO_ADDITIONS = 3
ITSTOOL_PATH = getattr(settings, 'ITSTOOL_PATH', '')
ITS_DATA_DIR = os.path.join(settings.SCRATCHDIR, 'data', 'its')
+# monkey-patch ttk (https://github.com/translate/translate/issues/2129)
+from translate.storage.base import TranslationStore
+orig_addunit = TranslationStore.addunit
+
+def patchedAddunit(self, unit):
+ # Prevent two header units in the same store
+ if unit.isheader() and len(self.units) and self.units[0].isheader():
+ unit._store = self
+ self.units[0] = unit
+ else:
+ orig_addunit(self, unit)
+
+TranslationStore.addunit = patchedAddunit
+
+
class DocFormat:
itstool_regex = re.compile("^msgid \"external ref=\'(?P<path>[^\']*)\' md5=\'(?P<hash>[^\']*)\'\"")
xml2po_regex = re.compile("^msgid \"@@image: \'(?P<path>[^\']*)\'; md5=(?P<hash>[^\"]*)\"")
@@ -352,7 +352,7 @@ def check_program_presence(prog_name):
return status == 0
def po_grep(in_file, out_file, filter_):
- if not has_toolkit or filter_ == "-":
+ if filter_ == "-":
return
if not filter_:
filter_loc, filter_str = "locations", "gschema.xml(.in)?|schemas.in"
@@ -492,12 +492,11 @@ def po_file_stats(pofile, msgfmt_checks=True):
input_data = None
input_file = str(pofile)
- if has_toolkit:
- status = pocount.calcstats_old(input_file)
- if status:
- res['fuzzy_words'] = status['fuzzysourcewords']
- res['translated_words'] = status['translatedsourcewords']
- res['untranslated_words'] = status['untranslatedsourcewords']
+ status = pocount.calcstats_old(input_file)
+ if status:
+ res['fuzzy_words'] = status['fuzzysourcewords']
+ res['translated_words'] = status['translatedsourcewords']
+ res['untranslated_words'] = status['untranslatedsourcewords']
elif isinstance(pofile, File):
input_data = pofile.read()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]