ya2 · news · projects · code · about

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