Commit | Line | Data |
---|---|---|
288c0ffb | 1 | '''e.g. python setup.py bdist_apps --cores=1 --nowindows=1''' |
8ee66edd FC |
2 | |
3 | ||
d3ef798c FC |
4 | from ya2.utils.log import LogManagerBase |
5 | LogManagerBase.pre_init_logging() | |
c991401b | 6 | from os import system |
8ee66edd | 7 | from sys import argv, executable |
8ee66edd | 8 | from subprocess import Popen |
5d67a04d | 9 | from setuptools import setup, Command |
8ee66edd | 10 | from setuptools.command.develop import develop |
a747111f | 11 | from multiprocessing import cpu_count |
8ee66edd | 12 | from direct.dist.commands import bdist_apps |
d3ef798c FC |
13 | from p3d_appimage import AppImageBuilder |
14 | from ya2.build.build import _branch, find_file_names, _version, FindFileNamesInfo | |
53ddf3c3 | 15 | from ya2.build.models import ModelsBuilder |
288c0ffb FC |
16 | from ya2.build.images import build_images |
17 | from ya2.build.screenshots import build_screenshots | |
53ddf3c3 | 18 | from ya2.build.lang import LanguageBuilder |
aad6ced2 | 19 | from pmachines.app import Pmachines |
8ee66edd FC |
20 | |
21 | ||
d3ef798c | 22 | app_name = long_name = 'pmachines' |
8ee66edd FC |
23 | |
24 | ||
25 | ||
d3ef798c | 26 | assets_creation_message = '''NOTE: please be sure that you've already created the assets with: |
8ee66edd FC |
27 | * python setup.py images models lang''' |
28 | ||
29 | ||
288c0ffb | 30 | class SetupDevelopmentCommand(develop): |
8ee66edd FC |
31 | |
32 | def run(self): | |
8ee66edd FC |
33 | develop.run(self) |
34 | Popen([executable, __file__, 'lang']).communicate() | |
35 | Popen([executable, __file__, 'models']).communicate() | |
36 | ||
37 | ||
d3ef798c | 38 | class BaseCommand(Command): |
8ee66edd FC |
39 | |
40 | user_options = [('cores=', None, '#cores')] | |
a747111f | 41 | cores = cpu_count() |
8ee66edd FC |
42 | |
43 | def initialize_options(self): | |
288c0ffb FC |
44 | for a in argv[:]: self.__process_argument(a) |
45 | ||
46 | def __process_argument(self, argument): | |
47 | if argument.startswith('--cores='): | |
d3ef798c | 48 | BaseCommand.cores = int(argument.split('=')[1]) |
8ee66edd FC |
49 | |
50 | def finalize_options(self): # must override | |
51 | pass | |
52 | ||
53 | ||
d3ef798c | 54 | class ModelsCommand(BaseCommand): |
8ee66edd FC |
55 | |
56 | def run(self): | |
d3ef798c | 57 | ModelsBuilder().build('assets/models', int(BaseCommand.cores)) |
8ee66edd FC |
58 | |
59 | ||
d3ef798c | 60 | class ImagesCommand(BaseCommand): |
8ee66edd FC |
61 | |
62 | def run(self): | |
288c0ffb | 63 | build_screenshots(Pmachines.scenes) |
d3ef798c FC |
64 | find_info = FindFileNamesInfo( |
65 | ['jpg', 'png'], | |
66 | ['models', 'gltf', 'bam'], | |
67 | ['_png.png']) | |
68 | images = find_file_names(find_info) | |
69 | build_images(images, int(BaseCommand.cores)) | |
8ee66edd FC |
70 | |
71 | ||
d3ef798c | 72 | class L10nCommand(BaseCommand): |
8ee66edd | 73 | |
288c0ffb | 74 | l10n_path = 'assets/locale/' |
8ee66edd FC |
75 | |
76 | def run(self): | |
d3ef798c | 77 | LanguageBuilder.build_pot(app_name, 'assets/locale/po/') |
288c0ffb FC |
78 | list(map(self.__process_language, ['it_IT'])) |
79 | ||
80 | def __process_language(self, lang_code): | |
d3ef798c | 81 | LanguageBuilder.merge(lang_code, 'assets/locale/po/', self.l10n_path, app_name) |
288c0ffb | 82 | mo_template = '%s%s/LC_MESSAGES/%s.mo' |
d3ef798c FC |
83 | mo_name = mo_template % (self.l10n_path, lang_code, app_name) |
84 | LanguageBuilder.build_mo(mo_name, self.l10n_path, app_name) | |
8ee66edd FC |
85 | |
86 | ||
288c0ffb | 87 | class BDistAppsCommand(bdist_apps): |
8ee66edd FC |
88 | |
89 | user_options = bdist_apps.user_options + [ | |
90 | ('cores', None, '#cores'), | |
288c0ffb | 91 | ('nowindows=', None, "don't build for windows"), |
8ee66edd FC |
92 | ('nolinux=', None, "don't build for linux")] |
93 | ||
94 | def initialize_options(self): | |
8ee66edd | 95 | bdist_apps.initialize_options(self) |
288c0ffb | 96 | self.nowindows, self.nolinux = None, None |
8ee66edd FC |
97 | |
98 | def run(self): | |
d3ef798c | 99 | print(assets_creation_message) |
288c0ffb FC |
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 ' + \ | |
8ee66edd | 106 | '../venv/lib/python3.7/site-packages/direct/dist/commands.py' + \ |
53ddf3c3 | 107 | ' ya2/build/commands.patch' |
288c0ffb FC |
108 | system(command) |
109 | ||
110 | def __eventually_build_appimage(self): | |
8ee66edd | 111 | if not self.nolinux: |
a7f2fc93 | 112 | hbranch = {'master': 'alpha', 'rc': 'rc', 'stable': ''}[_branch()] |
d3ef798c | 113 | AppImageBuilder(self).build(long_name, hbranch, |
1ba5e7f0 | 114 | 'https://www.ya2.it/downloads/') |
288c0ffb FC |
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 | |
8ee66edd FC |
133 | |
134 | ||
135 | if __name__ == '__main__': | |
8ee66edd | 136 | setup( |
d3ef798c | 137 | name=app_name, |
ea71df6e | 138 | version=_version(), |
8ee66edd | 139 | cmdclass={ |
288c0ffb FC |
140 | 'develop': SetupDevelopmentCommand, |
141 | 'models': ModelsCommand, | |
142 | 'images': ImagesCommand, | |
143 | 'lang': L10nCommand, | |
144 | 'bdist_apps': BDistAppsCommand}, | |
8ee66edd FC |
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__', | |
420ce99a | 151 | 'assets/models/gltf/*', 'assets/models/**/*.blend', |
8ee66edd FC |
152 | 'assets/models/**/models/*.png', |
153 | 'assets/models/**/models/*.jpg'], | |
154 | 'log_filename_strftime': True, | |
288c0ffb | 155 | 'log_filename': '$USER_APPDATA/pmachines/logs/%Y/%B/%d/%H_%M_%S.log', |
8ee66edd | 156 | 'plugins': ['pandagl', 'p3openal_audio', 'pandadx9'], |
d3ef798c | 157 | 'gui_apps': {app_name: 'main.py'}, |
288c0ffb | 158 | 'package_data_dirs': {'simplepbr': [('simplepbr/shaders*', '', {})]}, |
94a18c21 | 159 | 'icons': { |
d3ef798c | 160 | app_name: [ |
7e487769 FC |
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']}, | |
8ee66edd | 166 | 'include_patterns': [ |
53ddf3c3 | 167 | '**/ya2/licenses/*', |
8ee66edd FC |
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'], | |
288c0ffb | 184 | 'platforms': platform_list(), |
8ee66edd | 185 | 'include_modules': {'*': ['encodings.hex_codec']}}, |
288c0ffb | 186 | 'bdist_apps': {'installers': installers_dictionary()}}) |