ya2 · news · projects · code · about

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