ya2 · news · projects · code · about

refactoring of functional tests
[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 setuptools import setup, Command
11 from setuptools.command.develop import develop
12 from multiprocessing import cpu_count
13 from direct.dist.commands import bdist_apps
14 from lib.build.build import branch, files, ver, files, bld_dpath
15 from lib.build.docs import bld_docs
16 from lib.build.models import ModelsBuilder
17 from lib.build.images import bld_images
18 from lib.build.screenshots import bld_screenshots
19 from lib.build.lang import LanguageBuilder
20 from p3d_appimage import AppImageBuilder
21 from p3d_flatpak import FlatpakBuilder
22 import lib.engine.log # so logging's info/debug are logged
23 from game.app import PmachinesApp
24
25
26 appname = longname = 'pmachines'
27
28
29
30 msg = '''NOTE: please be sure that you've already created the assets with:
31 * python setup.py images models lang'''
32
33
34 class 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
44 class AbsCmd(Command):
45 '''Common functionalities for commands.'''
46
47 user_options = [('cores=', None, '#cores')]
48 cores = cpu_count()
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
59 class DocsCmd(AbsCmd):
60 '''Command for building the docs.'''
61
62 def run(self):
63 '''Builds the docs.'''
64 bld_docs()
65
66
67 class 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
75 class ImagesCmd(AbsCmd):
76 '''Command for building the models.'''
77
78 def run(self):
79 '''Builds the images.'''
80 bld_screenshots(PmachinesApp.scenes)
81 bld_images(
82 files(['jpg', 'png'], ['models', 'gltf', 'bam'], ['_png.png']), int(AbsCmd.cores))
83
84
85 class 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/locale/po/%s.po' % lang_code
93 LanguageBuilder.merge(lang_code, 'assets/locale/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/locale/po/')
101 list(map(self._process_lang, ['it_IT']))
102
103
104 class 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 'https://www.ya2.it/downloads/')
132 fbranch = {'master': 'alpha', 'rc': 'rc', 'stable': 'stable'}[branch]
133 bld = FlatpakBuilder(
134 self,
135 'it.ya2.Pmachines',
136 '/home/flavio/builders/pmachines_builder/flatpak',
137 'D43B6D401912B520B6805FCC8E019E6340E3BAB5',
138 '/home/flavio/builders/pmachines_builder/gpg',
139 'https://www.ya2.it/flatpak',
140 ['options*.ini'],
141 fbranch,
142 ['assets'])
143 bld.build()
144
145
146 if __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 += ['manylinux2010_x86_64']
153 installers_dct['manylinux2010_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/models/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']},
187 'icons': {
188 appname: [
189 'assets/images/icon/icon256.png',
190 'assets/images/icon/icon128.png',
191 'assets/images/icon/icon48.png',
192 'assets/images/icon/icon32.png',
193 'assets/images/icon/icon16.png']},
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}})