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()
36 Popen([executable
, __file__
, 'images']).communicate()
39 class BaseCommand(Command
):
41 user_options
= [('cores=', None, '#cores')]
44 def initialize_options(self
):
45 for a
in argv
[:]: self
.__process
_argument
(a
)
47 def __process_argument(self
, argument
):
48 if argument
.startswith('--cores='):
49 BaseCommand
.cores
= int(argument
.split('=')[1])
51 def finalize_options(self
): # must override
55 class ModelsCommand(BaseCommand
):
58 ModelsBuilder().build('assets/models', int(BaseCommand
.cores
))
61 class ImagesCommand(BaseCommand
):
64 build_screenshots(Pmachines
.scenes
)
65 find_info
= FindFileNamesInfo(
67 ['models', 'gltf', 'bam'],
69 images
= find_file_names(find_info
)
70 build_images(images
, int(BaseCommand
.cores
))
73 class L10nCommand(BaseCommand
):
75 l10n_path
= 'assets/locale/'
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
)
82 def __process_language(self
, language_code
):
83 self
.__language
_builder
.merge(language_code
)
84 self
.__language
_builder
.build_mo(language_code
)
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()}})