ya2 · news · projects · code · about

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