-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathsetup.py
60 lines (50 loc) · 1.85 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""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 = []
for root in root_list:
for dirname, _, files in os.walk(os.path.join(pkg, root)):
for fname in files:
data.append(os.path.relpath(os.path.join(dirname, fname), pkg))
return {pkg: data}
setup(
name='recommender-xblock',
version='1.2',
description='recommender XBlock', # TODO: write a better description.
packages=[
'recommender',
],
entry_points={
'xblock.v1': [
'recommender = recommender:RecommenderXBlock',
]
},
package_data=package_data("recommender", ["static", "translations"]),
cmdclass={
'install': XBlockInstall,
},
)