ya2 · news · projects · code · about

refinements (building)
[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
5d67a04d 10from setuptools import setup, Command
8ee66edd 11from setuptools.command.develop import develop
a747111f 12from multiprocessing import cpu_count
8ee66edd 13from direct.dist.commands import bdist_apps
ea71df6e 14from ya2.build.build import _branch, files, _version
cb700bcc 15#from ya2.build.docs import bld_docs
53ddf3c3
FC
16from ya2.build.models import ModelsBuilder
17from ya2.build.images import bld_images
18from ya2.build.screenshots import bld_screenshots
19from ya2.build.lang import LanguageBuilder
8ee66edd 20from p3d_appimage import AppImageBuilder
e9be18cf 21#from p3d_flatpak import FlatpakBuilder
b35b1f62 22import ya2.utils.log # so logging's info/debug are logged
4586cbf6 23from pmachines.app import PmachinesApp
8ee66edd
FC
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
cb700bcc
FC
59#class DocsCmd(AbsCmd):
60# '''Command for building the docs.'''
8ee66edd 61
cb700bcc
FC
62# def run(self):
63# '''Builds the docs.'''
64# bld_docs()
8ee66edd
FC
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.'''
6168d0c2 80 bld_screenshots(PmachinesApp.scenes)
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.'''
58c1093d
FC
92 poname = 'assets/locale/po/%s.po' % lang_code
93 LanguageBuilder.merge(lang_code, 'assets/locale/po/', self.lang_path, appname)
8ee66edd
FC
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.'''
58c1093d 100 LanguageBuilder.pot(appname, 'assets/locale/po/')
8ee66edd
FC
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' + \
53ddf3c3 125 ' ya2/build/commands.patch'
8ee66edd
FC
126 system(cmd)
127 bdist_apps.run(self)
128 if not self.nolinux:
a7f2fc93 129 hbranch = {'master': 'alpha', 'rc': 'rc', 'stable': ''}[_branch()]
8ee66edd 130 AppImageBuilder(self).build(longname, hbranch,
1ba5e7f0 131 'https://www.ya2.it/downloads/')
a7f2fc93 132 fbranch = {'master': 'alpha', 'rc': 'rc', 'stable': 'stable'}[_branch()]
e9be18cf
FC
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()
8ee66edd
FC
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):
addec9c9
FC
152 platform_lst += ['manylinux2010_x86_64']
153 installers_dct['manylinux2010_x86_64'] = []
8ee66edd
FC
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,
ea71df6e 158 version=_version(),
8ee66edd
FC
159 cmdclass={
160 'develop': DevelopPyCmd,
cb700bcc 161 # 'docs': DocsCmd,
8ee66edd
FC
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__',
420ce99a 172 'assets/models/gltf/*', 'assets/models/**/*.blend',
8ee66edd
FC
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: [
7e487769
FC
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']},
8ee66edd 194 'include_patterns': [
53ddf3c3 195 '**/ya2/licenses/*',
8ee66edd
FC
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}})