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
.lang
import LanguageBuilder
19 from p3d_appimage
import AppImageBuilder
20 from p3d_flatpak
import FlatpakBuilder
21 import lib
.engine
.log
# so logging's info/debug are logged
24 appname
= longname
= 'pmachines'
28 msg
= '''NOTE: please be sure that you've already created the assets with:
29 * python setup.py images models lang'''
32 class DevelopPyCmd(develop
):
33 '''Command for setting up the development.'''
36 '''Prepare the development environment.'''
38 Popen([executable
, __file__
, 'lang']).communicate()
39 Popen([executable
, __file__
, 'models']).communicate()
42 class AbsCmd(Command
):
43 '''Common functionalities for commands.'''
45 user_options
= [('cores=', None, '#cores')]
48 def initialize_options(self
):
50 if arg
.startswith('--cores='):
51 AbsCmd
.cores
= int(arg
.split('=')[1])
53 def finalize_options(self
): # must override
57 class DocsCmd(AbsCmd
):
58 '''Command for building the docs.'''
61 '''Builds the docs.'''
65 class ModelsCmd(AbsCmd
):
66 '''Command for building the models.'''
69 '''Builds the models.'''
70 ModelsBuilder().build('assets/models', int(AbsCmd
.cores
))
73 class ImagesCmd(AbsCmd
):
74 '''Command for building the models.'''
77 '''Builds the images.'''
79 files(['jpg', 'png'], ['models', 'gltf', 'bam'], ['_png.png']), int(AbsCmd
.cores
))
82 class LangCmd(AbsCmd
):
83 '''Command for building po, pot and mo files.'''
85 lang_path
= 'assets/locale/'
87 def _process_lang(self
, lang_code
):
88 '''Processes a single language.'''
89 poname
= 'assets/po/%s.po' % lang_code
90 LanguageBuilder
.merge(lang_code
, 'assets/po/', self
.lang_path
, appname
)
91 mo_tmpl
= '%s%s/LC_MESSAGES/%s.mo'
92 moname
= mo_tmpl
% (self
.lang_path
, lang_code
, appname
)
93 LanguageBuilder
.mo(moname
, self
.lang_path
, appname
)
96 '''Builds the language files.'''
97 LanguageBuilder
.pot(appname
, 'assets/po/')
98 list(map(self
._process
_lang
, ['it_IT']))
101 class BDistAppsCmd(bdist_apps
):
102 '''Customization of BDistApps.'''
104 user_options
= bdist_apps
.user_options
+ [
105 ('cores', None, '#cores'),
106 ('nowin=', None, "don't build for windows"),
107 ('nolinux=', None, "don't build for linux")]
109 def initialize_options(self
):
110 '''Default values.'''
111 bdist_apps
.initialize_options(self
)
112 self
.nowin
, self
.nolinux
= None, None
114 #def finalize_options(self): # must override
115 # bdist_apps.finalize_options(self)
118 '''Our bdist_apps' customization.'''
120 cmd
= 'patch --forward ' + \
121 '../venv/lib/python3.7/site-packages/direct/dist/commands.py' + \
122 ' lib/build/commands.patch'
126 hbranch
= {'master': 'alpha', 'rc': 'rc', 'stable': ''}[branch
]
127 AppImageBuilder(self
).build(longname
, hbranch
,
128 'http://www.ya2tech.it/downloads/')
129 fbranch
= {'master': 'alpha', 'rc': 'rc', 'stable': 'stable'}[branch
]
130 bld
= FlatpakBuilder(
133 '/home/flavio/pmachines_builder/flatpak',
134 'D43B6D401912B520B6805FCC8E019E6340E3BAB5',
135 '/home/flavio/pmachines_builder/gpg',
136 'http://www.ya2tech.it/flatpak',
143 if __name__
== '__main__':
144 platform_lst
, installers_dct
= [], {}
145 if all('--nowin' not in arg
for arg
in argv
):
146 platform_lst
+= ['win_amd64']
147 installers_dct
['win_amd64'] = ['nsis']
148 if all('--nolinux' not in arg
for arg
in argv
):
149 platform_lst
+= ['manylinux1_x86_64']
150 installers_dct
['manylinux1_x86_64'] = []
151 log_path
= '$USER_APPDATA/pmachines/logs/%Y/%B/%d/%H_%M_%S.log'
152 package_data_dirs
= {'simplepbr': [('simplepbr/shaders*', '', {})]}
157 'develop': DevelopPyCmd
,
162 'bdist_apps': BDistAppsCmd
},
163 install_requires
=['panda3d'],
166 'exclude_patterns': [
167 'build/*', 'built/*', 'setup.py', 'requirements.txt',
168 'venv/*', '.git*', '*.pyc', 'options.ini', '__pycache__',
169 'assets/gltf/*', 'assets/models/**/*.blend',
170 'assets/models/**/models/*.png',
171 'assets/models/**/models/*.jpg'],
172 'log_filename_strftime': True,
173 'log_filename': log_path
,
174 'plugins': ['pandagl', 'p3openal_audio', 'pandadx9'],
175 'gui_apps': {appname
: 'main.py'},
176 'package_data_dirs': package_data_dirs
,
179 'assets/images/icon/icon256_png.png',
180 'assets/images/icon/icon128_png.png',
181 'assets/images/icon/icon48_png.png',
182 'assets/images/icon/icon32_png.png',
183 'assets/images/icon/icon16_png.png']},
184 'include_patterns': [
202 'platforms': platform_lst
,
203 'include_modules': {'*': ['encodings.hex_codec']}},
204 'bdist_apps': {'installers': installers_dct
}})