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