ya2 · news · projects · code · about

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