From 9eae107f63ec8e12769a75ff288d4348223b3d81 Mon Sep 17 00:00:00 2001
From: Alexandre Iooss <erdnaxe@crans.org>
Date: Sat, 28 Nov 2020 09:15:36 +0100
Subject: [PATCH] Do not use subprocess to compile locales and make them
 optional

---
 README.rst |  2 +-
 setup.py   | 11 ++++++++---
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/README.rst b/README.rst
index 509c494..05535aa 100644
--- a/README.rst
+++ b/README.rst
@@ -14,7 +14,7 @@ Debian-based distribution
 ~~~~~~~~~~~~~~~~~~~~~~~~~
 
 -  Install some requirements,
-   ``apt install git python3 gettext python3-paramiko python3-pyperclip python3-gpg python3-pip libgpgme-dev``.
+   ``apt install git python3 python3-polib python3-paramiko python3-pyperclip python3-gpg python3-pip libgpgme-dev``.
 
 -  Clone the code,
    ``git clone https://gitlab.crans.org/nounous/cranspasswords.git && cd cranspasswords``,
diff --git a/setup.py b/setup.py
index bbdee59..49e0a3d 100755
--- a/setup.py
+++ b/setup.py
@@ -2,7 +2,6 @@
 
 from setuptools import setup
 from os import getenv, path
-from subprocess import call
 
 # Enable the user to install cpasswords
 # with another command and config path
@@ -19,8 +18,14 @@ def compile_messages():
     for po_file in locales:
         filename, _ = path.splitext(po_file)
         mo_file = filename + '.mo'
-        call("msgfmt %s -o %s" % (po_file, mo_file), shell=True)
-        mo_files.append(mo_file)
+        try:
+            from polib import pofile
+            po = pofile(po_file)
+            po.save_as_mofile(mo_file)
+            mo_files.append(mo_file)
+        except ImportError:
+            print("Polib is not installed, tranlation will not be compiled.")
+            break
     return [('locale', mo_files), ]
 
 
-- 
GitLab