ya2 · news · projects · code · about

optimization: creation of images
[pmachines.git] / setup.py
CommitLineData
8ee66edd
FC
1'''Setuptools' configuration file
2e.g. python setup.py models --cores=1
3e.g. python setup.py bdist_apps --nowin=1'''
4
5
6from os import system, getcwd, chdir
7from sys import argv, executable
8from collections import namedtuple
9from subprocess import Popen
10from distutils.cmd import Command
11from setuptools import setup
12from setuptools.command.develop import develop
a747111f 13from multiprocessing import cpu_count
8ee66edd
FC
14from direct.dist.commands import bdist_apps
15from lib.build.build import branch, files, ver, files, bld_dpath
16from lib.build.docs import bld_docs
17from lib.build.models import ModelsBuilder
18from lib.build.images import bld_images
63e7aeb2 19from lib.build.screenshots import bld_screenshots
8ee66edd
FC
20from lib.build.lang import LanguageBuilder
21from p3d_appimage import AppImageBuilder
22from p3d_flatpak import FlatpakBuilder
23import lib.engine.log # so logging's info/debug are logged
24
25
26appname = longname = 'pmachines'
27
28
29
30msg = '''NOTE: please be sure that you've already created the assets with:
31 * python setup.py images models lang'''
32
33
34class DevelopPyCmd(develop):
35 '''Command for setting up the development.'''
36
37 def run(self):
38 '''Prepare the development environment.'''
39 develop.run(self)
40 Popen([executable, __file__, 'lang']).communicate()
41 Popen([executable, __file__, 'models']).communicate()
42
43
44class AbsCmd(Command):
45 '''Common functionalities for commands.'''
46
47 user_options = [('cores=', None, '#cores')]
a747111f 48 cores = cpu_count()
8ee66edd
FC
49
50 def initialize_options(self):
51 for arg in argv[:]:
52 if arg.startswith('--cores='):
53 AbsCmd.cores = int(arg.split('=')[1])
54
55 def finalize_options(self): # must override
56 pass
57
58
59class DocsCmd(AbsCmd):
60 '''Command for building the docs.'''
61
62 def run(self):
63 '''Builds the docs.'''
64 bld_docs()
65
66
67class ModelsCmd(AbsCmd):
68 '''Command for building the models.'''
69
70 def run(self):
71 '''Builds the models.'''
72 ModelsBuilder().build('assets/models', int(AbsCmd.cores))
73
74
75class ImagesCmd(AbsCmd):
76 '''Command for building the models.'''
77
78 def run(self):
79 '''Builds the images.'''
63e7aeb2 80 bld_screenshots()
8ee66edd
FC
81 bld_images(
82 files(['jpg', 'png'], ['models', 'gltf', 'bam'], ['_png.png']), int(AbsCmd.cores))
83
84
85class LangCmd(AbsCmd):
86 '''Command for building po, pot and mo files.'''
87
88 lang_path = 'assets/locale/'
89
90 def _process_lang(self, lang_code):
91 '''Processes a single language.'''
92 poname = 'assets/po/%s.po' % lang_code
93 LanguageBuilder.merge(lang_code, 'assets/po/', self.lang_path, appname)
94 mo_tmpl = '%s%s/LC_MESSAGES/%s.mo'
95 moname = mo_tmpl % (self.lang_path, lang_code, appname)
96 LanguageBuilder.mo(moname, self.lang_path, appname)
97
98 def run(self):
99 '''Builds the language files.'''
100 LanguageBuilder.pot(appname, 'assets/po/')
101 list(map(self._process_lang, ['it_IT']))
102
103
104class BDistAppsCmd(bdist_apps):
105 '''Customization of BDistApps.'''
106
107 user_options = bdist_apps.user_options + [
108 ('cores', None, '#cores'),
109 ('nowin=', None, "don't build for windows"),
110 ('nolinux=', None, "don't build for linux")]
111
112 def initialize_options(self):
113 '''Default values.'''
114 bdist_apps.initialize_options(self)
115 self.nowin, self.nolinux = None, None
116
117 #def finalize_options(self): # must override
118 # bdist_apps.finalize_options(self)
119
120 def run(self):
121 '''Our bdist_apps' customization.'''
122 print(msg)
123 cmd = 'patch --forward ' + \
124 '../venv/lib/python3.7/site-packages/direct/dist/commands.py' + \
125 ' lib/build/commands.patch'
126 system(cmd)
127 bdist_apps.run(self)
128 if not self.nolinux:
129 hbranch = {'master': 'alpha', 'rc': 'rc', 'stable': ''}[branch]
130 AppImageBuilder(self).build(longname, hbranch,
131 'http://www.ya2tech.it/downloads/')
132 fbranch = {'master': 'alpha', 'rc': 'rc', 'stable': 'stable'}[branch]
133 bld = FlatpakBuilder(
134 self,
135 'it.ya2.Pmachines',
136 '/home/flavio/pmachines_builder/flatpak',
137 'D43B6D401912B520B6805FCC8E019E6340E3BAB5',
138 '/home/flavio/pmachines_builder/gpg',
139 'http://www.ya2tech.it/flatpak',
140 ['options*.ini'],
141 fbranch,
142 ['assets'])
143 bld.build()
144
145
146if __name__ == '__main__':
147 platform_lst, installers_dct = [], {}
148 if all('--nowin' not in arg for arg in argv):
149 platform_lst += ['win_amd64']
150 installers_dct['win_amd64'] = ['nsis']
151 if all('--nolinux' not in arg for arg in argv):
152 platform_lst += ['manylinux1_x86_64']
153 installers_dct['manylinux1_x86_64'] = []
154 log_path = '$USER_APPDATA/pmachines/logs/%Y/%B/%d/%H_%M_%S.log'
155 package_data_dirs = {'simplepbr': [('simplepbr/shaders*', '', {})]}
156 setup(
157 name=appname,
158 version=ver,
159 cmdclass={
160 'develop': DevelopPyCmd,
161 'docs': DocsCmd,
162 'models': ModelsCmd,
163 'images': ImagesCmd,
164 'lang': LangCmd,
165 'bdist_apps': BDistAppsCmd},
166 install_requires=['panda3d'],
167 options={
168 'build_apps': {
169 'exclude_patterns': [
170 'build/*', 'built/*', 'setup.py', 'requirements.txt',
171 'venv/*', '.git*', '*.pyc', 'options.ini', '__pycache__',
172 'assets/gltf/*', 'assets/models/**/*.blend',
173 'assets/models/**/models/*.png',
174 'assets/models/**/models/*.jpg'],
175 'log_filename_strftime': True,
176 'log_filename': log_path,
177 'plugins': ['pandagl', 'p3openal_audio', 'pandadx9'],
178 'gui_apps': {appname: 'main.py'},
179 'package_data_dirs': package_data_dirs,
180 'icons': {
181 appname: [
182 'assets/images/icon/icon256_png.png',
183 'assets/images/icon/icon128_png.png',
184 'assets/images/icon/icon48_png.png',
185 'assets/images/icon/icon32_png.png',
186 'assets/images/icon/icon16_png.png']},
94a18c21
FC
187 'icons': {
188 appname: [
189 'assets/icon/icon256.png',
190 'assets/icon/icon128.png',
191 'assets/icon/icon48.png',
192 'assets/icon/icon32.png',
193 'assets/icon/icon16.png']},
8ee66edd
FC
194 'include_patterns': [
195 '**/lib/licenses/*',
196 '**/licenses/*',
197 '**/*.bam',
198 '**/*.dds',
199 '**/*.bin',
200 #'**/*.png',
201 #'**/*.jpg',
202 '**/*.ico',
203 '**/*.json',
204 '**/track_tr.py',
205 '**/*.txt',
206 '**/*.ttf',
207 '**/*.vert',
208 '**/*.frag',
209 '**/*.ogg',
210 '**/*.wav',
211 '**/*.mo'],
212 'platforms': platform_lst,
213 'include_modules': {'*': ['encodings.hex_codec']}},
214 'bdist_apps': {'installers': installers_dct}})