1 '''Setuptools' configuration file
2 e.g. python setup.py models --cores=1
3 e.g. python setup.py bdist_apps --nowin=1'''
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
25 appname
= longname
= 'pmachines'
29 msg
= '''NOTE: please be sure that you've already created the assets with:
30 * python setup.py images models lang'''
33 class DevelopPyCmd(develop
):
34 '''Command for setting up the development.'''
37 '''Prepare the development environment.'''
39 Popen([executable
, __file__
, 'lang']).communicate()
40 Popen([executable
, __file__
, 'models']).communicate()
43 class AbsCmd(Command
):
44 '''Common functionalities for commands.'''
46 user_options
= [('cores=', None, '#cores')]
49 def initialize_options(self
):
51 if arg
.startswith('--cores='):
52 AbsCmd
.cores
= int(arg
.split('=')[1])
54 def finalize_options(self
): # must override
58 class DocsCmd(AbsCmd
):
59 '''Command for building the docs.'''
62 '''Builds the docs.'''
66 class ModelsCmd(AbsCmd
):
67 '''Command for building the models.'''
70 '''Builds the models.'''
71 ModelsBuilder().build('assets/models', int(AbsCmd
.cores
))
74 class ImagesCmd(AbsCmd
):
75 '''Command for building the models.'''
78 '''Builds the images.'''
81 files(['jpg', 'png'], ['models', 'gltf', 'bam'], ['_png.png']), int(AbsCmd
.cores
))
84 class LangCmd(AbsCmd
):
85 '''Command for building po, pot and mo files.'''
87 lang_path
= 'assets/locale/'
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
)
98 '''Builds the language files.'''
99 LanguageBuilder
.pot(appname
, 'assets/po/')
100 list(map(self
._process
_lang
, ['it_IT']))
103 class BDistAppsCmd(bdist_apps
):
104 '''Customization of BDistApps.'''
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")]
111 def initialize_options(self
):
112 '''Default values.'''
113 bdist_apps
.initialize_options(self
)
114 self
.nowin
, self
.nolinux
= None, None
116 #def finalize_options(self): # must override
117 # bdist_apps.finalize_options(self)
120 '''Our bdist_apps' customization.'''
122 cmd
= 'patch --forward ' + \
123 '../venv/lib/python3.7/site-packages/direct/dist/commands.py' + \
124 ' lib/build/commands.patch'
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(
135 '/home/flavio/pmachines_builder/flatpak',
136 'D43B6D401912B520B6805FCC8E019E6340E3BAB5',
137 '/home/flavio/pmachines_builder/gpg',
138 'http://www.ya2tech.it/flatpak',
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*', '', {})]}
159 'develop': DevelopPyCmd
,
164 'bdist_apps': BDistAppsCmd
},
165 install_requires
=['panda3d'],
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
,
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']},
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': [
211 'platforms': platform_lst
,
212 'include_modules': {'*': ['encodings.hex_codec']}},
213 'bdist_apps': {'installers': installers_dct
}})