ya2 · news · projects · code · about

removed next/prev/rewind
[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
FC
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
63e7aeb2 18from lib.build.screenshots import bld_screenshots
8ee66edd
FC
19from lib.build.lang import LanguageBuilder
20from p3d_appimage import AppImageBuilder
21from p3d_flatpak import FlatpakBuilder
22import lib.engine.log # so logging's info/debug are logged
6168d0c2 23from game.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
59class DocsCmd(AbsCmd):
60 '''Command for building the docs.'''
61
62 def run(self):
63 '''Builds the docs.'''
64 bld_docs()
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' + \
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,
1ba5e7f0 131 'https://www.ya2.it/downloads/')
8ee66edd
FC
132 fbranch = {'master': 'alpha', 'rc': 'rc', 'stable': 'stable'}[branch]
133 bld = FlatpakBuilder(
134 self,
135 'it.ya2.Pmachines',
c83fc94b 136 '/home/flavio/builders/pmachines_builder/flatpak',
8ee66edd 137 'D43B6D401912B520B6805FCC8E019E6340E3BAB5',
c83fc94b
FC
138 '/home/flavio/builders/pmachines_builder/gpg',
139 'https://www.ya2.it/flatpak',
8ee66edd
FC
140 ['options*.ini'],
141 fbranch,
8eb89921 142 ['assets'])
8ee66edd
FC
143 bld.build()
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,
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__',
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
FC
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}})