aa5273fc78b123cd39f0220111d752d614a34cd0
1 '''e.g. python setup.py bdist_apps --cores=1 --no-windows=1'''
4 from ya2
.utils
.log
import LogManager
5 LogManager
.before_init_setup('pmachines')
8 from setuptools
import setup
9 from subprocess
import Popen
10 from setuptools
import Command
11 from setuptools
.command
.develop
import develop
12 from multiprocessing
import cpu_count
13 from textwrap
import dedent
14 from direct
.dist
.commands
import bdist_apps
15 from p3d_appimage
import AppImageBuilder
16 from ya2
.build
.build
import _branch
, find_file_names
, _version
, FindFileNamesArgs
17 from ya2
.build
.lang
import LanguageBuilder
18 from ya2
.build
.screenshots
import ScreenshotsBuilder
19 from ya2
.build
.images
import ImagesBuilder
20 from ya2
.build
.models
import ModelsBuilder
21 from pmachines
.application
.application
import Pmachines
24 app_name
= long_name
= 'pmachines'
27 class SetupDevelopmentCommand(develop
):
31 for argument
in ['lang', 'models', 'images']:
32 p
= Popen([sys
.executable
, __file__
, argument
])
36 class BaseCommand(Command
):
38 user_options
= [('cores=', None, '#cores')]
41 def initialize_options(self
):
42 BaseCommand
.cores
= cpu_count()
43 for a
in argv
[:]: self
.__process
_argument
(a
)
45 def __process_argument(self
, argument
):
46 if argument
.startswith('--cores='):
47 BaseCommand
.cores
= int(argument
.split('=')[1])
49 def finalize_options(self
): pass # must override
52 class ModelsCommand(BaseCommand
):
55 m
= ModelsBuilder('assets/models', int(BaseCommand
.cores
))
59 class ImagesCommand(BaseCommand
):
62 s
= ScreenshotsBuilder(Pmachines
.scenes())
64 find_info
= FindFileNamesArgs(
66 ['models', 'gltf', 'bam', 'build'],
68 images
= find_file_names(find_info
)
69 i
= ImagesBuilder(images
, int(BaseCommand
.cores
))
73 class L10nCommand(BaseCommand
):
77 app_name
, 'assets/locale/po/', 'assets/scenes/', 'assets/locale/')
80 'test', 'tests/assets/locale/po/', 'tests/assets/scenes/', 'tests/assets/locale/')
84 class BDistAppsCommand(bdist_apps
):
86 user_options
= bdist_apps
.user_options
+ [
87 ('cores', None, '#cores'),
88 ('nowindows=', None, "don't build for windows"), # letters, numbers and hypens only
89 ('nolinux=', None, "don't build for linux")]
91 def initialize_options(self
):
92 super().initialize_options()
93 self
.nowindows
, self
.nolinux
= None, None
94 for a
in argv
[:]: self
.__process
_argument
(a
)
96 def __process_argument(self
, argument
):
97 if argument
.startswith('--no-windows='):
98 self
.nowindows
= int(argument
.split('=')[1])
99 if argument
.startswith('--no-linux='):
100 self
.nolinux
= int(argument
.split('=')[1])
103 assets_creation_message
= dedent('''NOTE: please be sure that you've already created the assets with:
104 * python setup.py images models lang''')
105 print(assets_creation_message
)
106 self
.__patch
_commands
_py
()
108 self
.__eventually
_build
_appimage
()
110 def __patch_commands_py(self
):
111 command
= 'patch --forward ' + \
112 '../venv/lib/python3.7/site-packages/direct/dist/commands.py' + \
113 ' ya2/build/commands.patch'
116 def __eventually_build_appimage(self
):
118 a
= AppImageBuilder(self
)
119 filename_branch
= {'master': 'alpha', 'rc': 'rc', 'stable': ''}
120 branch
= filename_branch
[_branch()]
121 a
.build(long_name
, branch
, 'https://www.ya2.it/downloads/')
124 def _build_setup_arguments():
127 'version': _version(),
128 'packages': ['pmachines', 'ya2', 'assets', 'licenses'],
130 'develop': SetupDevelopmentCommand
,
131 'models': ModelsCommand
,
132 'images': ImagesCommand
,
134 'bdist_apps': BDistAppsCommand
},
135 'install_requires': ['panda3d'],
138 'exclude_patterns': [
139 'build/*', 'built/*', 'setup.py', 'requirements.txt',
140 'venv/*', '.git*', '*.pyc', 'options.ini', '__pycache__',
141 'assets/models/gltf/*', 'assets/models/**/*.blend',
142 'assets/models/**/models/*.png',
143 'assets/models/**/models/*.jpg'],
144 'log_filename_strftime': True,
145 'log_filename': '$USER_APPDATA/pmachines/logs/%Y/%B/%d/%H_%M_%S.log',
146 'plugins': ['pandagl', 'p3openal_audio', 'pandadx9'],
147 'gui_apps': {app_name
: 'main.py'},
148 'package_data_dirs': {'simplepbr': [('simplepbr/shaders*', '', {})]},
151 'assets/images/icon/icon256.png',
152 'assets/images/icon/icon128.png',
153 'assets/images/icon/icon48.png',
154 'assets/images/icon/icon32.png',
155 'assets/images/icon/icon16.png']},
156 'include_patterns': [
174 'platforms': __platform_list(),
175 'include_modules': {'*': ['encodings.hex_codec']},
176 'prefer_discrete_gpu': True},
177 'bdist_apps': {'installers': __installers_dictionary()}}}
180 def __platform_list():
182 if all('--no-windows' not in a
for a
in argv
):
183 platforms
+= ['win_amd64']
184 if all('--no-linux' not in a
for a
in argv
):
185 platforms
+= ['manylinux2010_x86_64']
188 def __installers_dictionary():
190 if all('--no-windows' not in a
for a
in argv
):
191 installers
['win_amd64'] = ['nsis']
192 if all('--no-linux' not in a
for a
in argv
):
193 installers
['manylinux2010_x86_64'] = []
196 if __name__
== '__main__':
197 setup(**_build_setup_arguments())