580e78d9bd2fb520748cd99ee5a57065bf265404
1 '''e.g. python setup.py bdist_apps --cores=1 --nowindows=1'''
4 from ya2
.utils
.log
import LogManagerBase
5 LogManagerBase
.pre_init_logging()
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
22 app_name
= long_name
= 'pmachines'
26 assets_creation_message
= '''NOTE: please be sure that you've already created the assets with:
27 * python setup.py images models lang'''
30 class SetupDevelopmentCommand(develop
):
34 Popen([executable
, __file__
, 'lang']).communicate()
35 Popen([executable
, __file__
, 'models']).communicate()
38 class BaseCommand(Command
):
40 user_options
= [('cores=', None, '#cores')]
43 def initialize_options(self
):
44 for a
in argv
[:]: self
.__process
_argument
(a
)
46 def __process_argument(self
, argument
):
47 if argument
.startswith('--cores='):
48 BaseCommand
.cores
= int(argument
.split('=')[1])
50 def finalize_options(self
): # must override
54 class ModelsCommand(BaseCommand
):
57 ModelsBuilder().build('assets/models', int(BaseCommand
.cores
))
60 class ImagesCommand(BaseCommand
):
63 build_screenshots(Pmachines
.scenes
)
64 find_info
= FindFileNamesInfo(
66 ['models', 'gltf', 'bam'],
68 images
= find_file_names(find_info
)
69 build_images(images
, int(BaseCommand
.cores
))
72 class L10nCommand(BaseCommand
):
74 l10n_path
= 'assets/locale/'
77 LanguageBuilder
.build_pot(app_name
, 'assets/locale/po/')
78 list(map(self
.__process
_language
, ['it_IT']))
80 def __process_language(self
, lang_code
):
81 LanguageBuilder
.merge(lang_code
, 'assets/locale/po/', self
.l10n_path
, app_name
)
82 mo_template
= '%s%s/LC_MESSAGES/%s.mo'
83 mo_name
= mo_template
% (self
.l10n_path
, lang_code
, app_name
)
84 LanguageBuilder
.build_mo(mo_name
, self
.l10n_path
, app_name
)
87 class BDistAppsCommand(bdist_apps
):
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")]
94 def initialize_options(self
):
95 bdist_apps
.initialize_options(self
)
96 self
.nowindows
, self
.nolinux
= None, None
99 print(assets_creation_message
)
100 self
.__patch
_commands
_py
()
102 self
.__eventually
_build
_appimage
()
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'
110 def __eventually_build_appimage(self
):
112 hbranch
= {'master': 'alpha', 'rc': 'rc', 'stable': ''}[_branch()]
113 AppImageBuilder(self
).build(long_name
, hbranch
,
114 'https://www.ya2.it/downloads/')
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']
126 def installers_dictionary():
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'] = []
135 if __name__
== '__main__':
140 'develop': SetupDevelopmentCommand
,
141 'models': ModelsCommand
,
142 'images': ImagesCommand
,
144 'bdist_apps': BDistAppsCommand
},
145 install_requires
=['panda3d'],
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*', '', {})]},
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': [
184 'platforms': platform_list(),
185 'include_modules': {'*': ['encodings.hex_codec']}},
186 'bdist_apps': {'installers': installers_dictionary()}})