Skip to content

Commit

Permalink
Merge pull request #46 from ziafazal/ziafazal/custom-build-steps
Browse files Browse the repository at this point in the history
This PR compiles translations during the XBlock install process. A future PR will remove them during uninstall :)
  • Loading branch information
Piotr Mitros authored Jan 19, 2017
2 parents 8d10afe + 32e16a0 commit 0e744b3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
"""Setup for recommender XBlock."""

import os
import subprocess
from setuptools.command.install import install as _install
from setuptools import setup


class XBlockInstall(_install):
"""Custom XBlock install command."""

def run(self):
_install.run(self)
self.compile_translations()

def compile_translations(self):
"""
Compiles textual translations files(.po) to binary(.mo) files.
"""
self.announce('Compiling translations')
try:
for dirname, _, files in os.walk(os.path.join('recommender', 'translations')):
for fname in files:
if os.path.splitext(fname)[1] == '.po':
po_path = os.path.join(dirname, fname)
mo_path = os.path.splitext(po_path)[0] + '.mo'
self.announce('Compiling translation at %s' % po_path)
subprocess.check_call(['msgfmt', po_path, '-o', mo_path], cwd=self.install_lib)
except Exception as ex:
self.announce('Translations compilation failed: %s', ex.message)


def package_data(pkg, root_list):
"""Generic function to find package_data for `pkg` under `root`."""
data = []
Expand All @@ -28,4 +54,7 @@ def package_data(pkg, root_list):
]
},
package_data=package_data("recommender", ["static", "translations"]),
cmdclass={
'install': XBlockInstall,
},
)

0 comments on commit 0e744b3

Please sign in to comment.