ya2 · news · projects · code · about

housekeeping (L10nCommand)
[pmachines.git] / setup.py
1 '''e.g. python setup.py bdist_apps --cores=1 --nowindows=1'''
2
3
4 from ya2.utils.log import LogManagerBase
5 LogManagerBase.pre_init_logging()
6 from os import system
7 from sys import argv, executable
8 from subprocess import Popen
9 from setuptools import setup, Command
10 from setuptools.command.develop import develop
11 from multiprocessing import cpu_count
12 from direct.dist.commands import bdist_apps
13 from p3d_appimage import AppImageBuilder
14 from ya2.build.build import _branch, find_file_names, _version, FindFileNamesInfo
15 from ya2.build.models import ModelsBuilder
16 from ya2.build.images import build_images
17 from ya2.build.screenshots import build_screenshots
18 from ya2.build.lang import LanguageBuilder
19 from pmachines.app import Pmachines
20
21
22 app_name = long_name = 'pmachines'
23
24
25
26 assets_creation_message = '''NOTE: please be sure that you've already created the assets with:
27 * python setup.py images models lang'''
28
29
30 class SetupDevelopmentCommand(develop):
31
32 def run(self):
33 develop.run(self)
34 Popen([executable, __file__, 'lang']).communicate()
35 Popen([executable, __file__, 'models']).communicate()
36 Popen([executable, __file__, 'images']).communicate()
37
38
39 class BaseCommand(Command):
40
41 user_options = [('cores=', None, '#cores')]
42 cores = cpu_count()
43
44 def initialize_options(self):
45 for a in argv[:]: self.__process_argument(a)
46
47 def __process_argument(self, argument):
48 if argument.startswith('--cores='):
49 BaseCommand.cores = int(argument.split('=')[1])
50
51 def finalize_options(self): # must override
52 pass
53
54
55 class ModelsCommand(BaseCommand):
56
57 def run(self):
58 ModelsBuilder().build('assets/models', int(BaseCommand.cores))
59
60
61 class ImagesCommand(BaseCommand):
62
63 def run(self):
64 build_screenshots(Pmachines.scenes)
65 find_info = FindFileNamesInfo(
66 ['jpg', 'png'],
67 ['models', 'gltf', 'bam'],
68 ['_png.png'])
69 images = find_file_names(find_info)
70 build_images(images, int(BaseCommand.cores))
71
72
73 class L10nCommand(BaseCommand):
74
75 l10n_path = 'assets/locale/'
76
77 def run(self):
78 self.__language_builder = LanguageBuilder(app_name, 'assets/locale/po/', 'assets/locale/')
79 self.__language_builder.build_pot()
80 for l in ['it_IT']: self.__process_language(l)
81
82 def __process_language(self, language_code):
83 self.__language_builder.merge(language_code)
84 self.__language_builder.build_mo(language_code)
85
86
87 class BDistAppsCommand(bdist_apps):
88
89 user_options = bdist_apps.user_options + [
90 ('cores', None, '#cores'),
91 ('nowindows=', None, "don't build for windows"),
92 ('nolinux=', None, "don't build for linux")]
93
94 def initialize_options(self):
95 bdist_apps.initialize_options(self)
96 self.nowindows, self.nolinux = None, None
97
98 def run(self):
99 print(assets_creation_message)
100 self.__patch_commands_py()
101 bdist_apps.run(self)
102 self.__eventually_build_appimage()
103
104 def __patch_commands_py(self):
105 command = 'patch --forward ' + \
106 '../venv/lib/python3.7/site-packages/direct/dist/commands.py' + \
107 ' ya2/build/commands.patch'
108 system(command)
109
110 def __eventually_build_appimage(self):
111 if not self.nolinux:
112 hbranch = {'master': 'alpha', 'rc': 'rc', 'stable': ''}[_branch()]
113 AppImageBuilder(self).build(long_name, hbranch,
114 'https://www.ya2.it/downloads/')
115
116
117 def platform_list():
118 platforms = []
119 if all('--nowindows' not in a for a in argv):
120 platforms += ['win_amd64']
121 if all('--nolinux' not in a for a in argv):
122 platforms += ['manylinux2010_x86_64']
123 return platforms
124
125
126 def installers_dictionary():
127 installers = {}
128 if all('--nowindows' not in a for a in argv):
129 installers['win_amd64'] = ['nsis']
130 if all('--nolinux' not in a for a in argv):
131 installers['manylinux2010_x86_64'] = []
132 return installers
133
134
135 if __name__ == '__main__':
136 setup(
137 name=app_name,
138 version=_version(),
139 cmdclass={
140 'develop': SetupDevelopmentCommand,
141 'models': ModelsCommand,
142 'images': ImagesCommand,
143 'lang': L10nCommand,
144 'bdist_apps': BDistAppsCommand},
145 install_requires=['panda3d'],
146 options={
147 'build_apps': {
148 'exclude_patterns': [
149 'build/*', 'built/*', 'setup.py', 'requirements.txt',
150 'venv/*', '.git*', '*.pyc', 'options.ini', '__pycache__',
151 'assets/models/gltf/*', 'assets/models/**/*.blend',
152 'assets/models/**/models/*.png',
153 'assets/models/**/models/*.jpg'],
154 'log_filename_strftime': True,
155 'log_filename': '$USER_APPDATA/pmachines/logs/%Y/%B/%d/%H_%M_%S.log',
156 'plugins': ['pandagl', 'p3openal_audio', 'pandadx9'],
157 'gui_apps': {app_name: 'main.py'},
158 'package_data_dirs': {'simplepbr': [('simplepbr/shaders*', '', {})]},
159 'icons': {
160 app_name: [
161 'assets/images/icon/icon256.png',
162 'assets/images/icon/icon128.png',
163 'assets/images/icon/icon48.png',
164 'assets/images/icon/icon32.png',
165 'assets/images/icon/icon16.png']},
166 'include_patterns': [
167 '**/ya2/licenses/*',
168 '**/licenses/*',
169 '**/*.bam',
170 '**/*.dds',
171 '**/*.bin',
172 #'**/*.png',
173 #'**/*.jpg',
174 '**/*.ico',
175 '**/*.json',
176 '**/track_tr.py',
177 '**/*.txt',
178 '**/*.ttf',
179 '**/*.vert',
180 '**/*.frag',
181 '**/*.ogg',
182 '**/*.wav',
183 '**/*.mo'],
184 'platforms': platform_list(),
185 'include_modules': {'*': ['encodings.hex_codec']}},
186 'bdist_apps': {'installers': installers_dictionary()}})