commit 3b4fb2c996a41dbbf89e252f52cbc4086ea7866b
parent 082b9b6ade497906c5daa65cf4197182d2dd839e
Author: Nikolay Korotkiy <sikmir@gmail.com>
Date: Sun, 6 Dec 2020 22:27:10 +0300
tatoebatools: add cli tool
Diffstat:
3 files changed, 57 insertions(+), 9 deletions(-)
diff --git a/pkgs/tools/dict/tatoebatools/cli.patch b/pkgs/tools/dict/tatoebatools/cli.patch
@@ -0,0 +1,35 @@
+diff --git c/setup.py i/setup.py
+index ea690f5..9f316c2 100644
+--- c/setup.py
++++ i/setup.py
+@@ -21,8 +21,11 @@ setuptools.setup(
+ python_requires=">=3.6",
+ install_requires=[
+ "beautifulsoup4>=4.9.0",
++ "click",
+ "pandas>=1.1.1",
+ "requests>=2.23.0",
+ "tqdm>=4.46.0",
++ "xdg"
+ ],
++ entry_points={"console_scripts": "parallel_corpus=tatoebatools.cli:parallel_corpus"},
+ )
+diff --git c/tatoebatools/cli.py i/tatoebatools/cli.py
+new file mode 100644
+index 0000000..f128aec
+--- /dev/null
++++ i/tatoebatools/cli.py
+@@ -0,0 +1,13 @@
++import click
++from xdg import XDG_DATA_HOME
++from tatoebatools import ParallelCorpus, tatoeba
++
++tatoeba.dir = XDG_DATA_HOME / "tatoebatools"
++
++@click.command(short_help="Parallel corpus")
++@click.argument('source_language')
++@click.argument('target_language')
++@click.option('--update', type=click.BOOL, default=False)
++def parallel_corpus(source_language, target_language, update):
++ for sentence, translation in ParallelCorpus(source_language, target_language, update):
++ print("%s\t%s" % (sentence.text, translation.text));
diff --git a/pkgs/tools/dict/tatoebatools/default.nix b/pkgs/tools/dict/tatoebatools/default.nix
@@ -1,4 +1,4 @@
-{ lib, python3Packages, sources, withCli ? true }:
+{ lib, python3Packages, sources, withCli ? true, checkLang ? false }:
python3Packages.buildPythonApplication {
pname = "tatoebatools-unstable";
@@ -6,17 +6,17 @@ python3Packages.buildPythonApplication {
src = sources.tatoebatools;
- propagatedBuildInputs = with python3Packages; [ beautifulsoup4 pandas requests tqdm ];
+ patches = lib.optional checkLang ./dont-check-lang-validity.patch
+ ++ lib.optional withCli ./cli.patch;
+
+ propagatedBuildInputs = with python3Packages; [ beautifulsoup4 pandas requests setuptools tqdm ]
+ ++ lib.optionals withCli [ click xdg ];
checkInputs = with python3Packages; [ pytestCheckHook ];
- disabledTests = [
- "test_iter_with_file"
- "test_update_sentences_detailed"
- "test_update_links"
- "test_update_queries"
- "test_update_up_to_date"
- "test_update_with_not_language_pair"
+ disabledTests = lib.optionals checkLang [
+ "test_init_with_not_language_1"
+ "test_init_with_not_language_2"
];
meta = with lib; {
diff --git a/pkgs/tools/dict/tatoebatools/dont-check-lang-validity.patch b/pkgs/tools/dict/tatoebatools/dont-check-lang-validity.patch
@@ -0,0 +1,13 @@
+diff --git i/tatoebatools/table.py w/tatoebatools/table.py
+index f900fd4..fd445fb 100644
+--- i/tatoebatools/table.py
++++ w/tatoebatools/table.py
+@@ -74,7 +74,7 @@ class Table:
+
+ # check validity of arguments
+ self._check_table_name_validity()
+- self._check_language_codes_validity()
++ #self._check_language_codes_validity()
+
+ # unlike other cases, the links from sentences in one language to
+ # sentences in every language are not loaded from a bilingual