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