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() | |
4e980d83 | 36 | Popen([executable, __file__, 'images']).communicate() |
8ee66edd FC |
37 | |
38 | ||
d3ef798c | 39 | class BaseCommand(Command): |
8ee66edd FC |
40 | |
41 | user_options = [('cores=', None, '#cores')] | |
a747111f | 42 | cores = cpu_count() |
8ee66edd FC |
43 | |
44 | def initialize_options(self): | |
288c0ffb FC |
45 | for a in argv[:]: self.__process_argument(a) |
46 | ||
47 | def __process_argument(self, argument): | |
48 | if argument.startswith('--cores='): | |
d3ef798c | 49 | BaseCommand.cores = int(argument.split('=')[1]) |
8ee66edd FC |
50 | |
51 | def finalize_options(self): # must override | |
52 | pass | |
53 | ||
54 | ||
d3ef798c | 55 | class ModelsCommand(BaseCommand): |
8ee66edd FC |
56 | |
57 | def run(self): | |
d3ef798c | 58 | ModelsBuilder().build('assets/models', int(BaseCommand.cores)) |
8ee66edd FC |
59 | |
60 | ||
d3ef798c | 61 | class ImagesCommand(BaseCommand): |
8ee66edd FC |
62 | |
63 | def run(self): | |
288c0ffb | 64 | build_screenshots(Pmachines.scenes) |
d3ef798c FC |
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)) | |
8ee66edd FC |
71 | |
72 | ||
d3ef798c | 73 | class L10nCommand(BaseCommand): |
8ee66edd | 74 | |
288c0ffb | 75 | l10n_path = 'assets/locale/' |
8ee66edd FC |
76 | |
77 | def run(self): | |
4e980d83 FC |
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) | |
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()}}) |