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 setuptools
import setup
, Command
11 from setuptools
.command
.develop
import develop
12 from multiprocessing
import cpu_count
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
23 from game
.app
import PmachinesApp
26 appname
= longname
= 'pmachines'
30 msg
= '''NOTE: please be sure that you've already created the assets with:
31 * python setup.py images models lang'''
34 class DevelopPyCmd(develop
):
35 '''Command for setting up the development.'''
38 '''Prepare the development environment.'''
40 Popen([executable
, __file__
, 'lang']).communicate()
41 Popen([executable
, __file__
, 'models']).communicate()
44 class AbsCmd(Command
):
45 '''Common functionalities for commands.'''
47 user_options
= [('cores=', None, '#cores')]
50 def initialize_options(self
):
52 if arg
.startswith('--cores='):
53 AbsCmd
.cores
= int(arg
.split('=')[1])
55 def finalize_options(self
): # must override
59 class DocsCmd(AbsCmd
):
60 '''Command for building the docs.'''
63 '''Builds the docs.'''
67 class ModelsCmd(AbsCmd
):
68 '''Command for building the models.'''
71 '''Builds the models.'''
72 ModelsBuilder().build('assets/models', int(AbsCmd
.cores
))
75 class ImagesCmd(AbsCmd
):
76 '''Command for building the models.'''
79 '''Builds the images.'''
80 bld_screenshots(PmachinesApp
.scenes
)
82 files(['jpg', 'png'], ['models', 'gltf', 'bam'], ['_png.png']), int(AbsCmd
.cores
))
85 class LangCmd(AbsCmd
):
86 '''Command for building po, pot and mo files.'''
88 lang_path
= 'assets/locale/'
90 def _process_lang(self
, lang_code
):
91 '''Processes a single language.'''
92 poname
= 'assets/locale/po/%s.po' % lang_code
93 LanguageBuilder
.merge(lang_code
, 'assets/locale/po/', self
.lang_path
, appname
)
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
)
99 '''Builds the language files.'''
100 LanguageBuilder
.pot(appname
, 'assets/locale/po/')
101 list(map(self
._process
_lang
, ['it_IT']))
104 class BDistAppsCmd(bdist_apps
):
105 '''Customization of BDistApps.'''
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")]
112 def initialize_options(self
):
113 '''Default values.'''
114 bdist_apps
.initialize_options(self
)
115 self
.nowin
, self
.nolinux
= None, None
117 #def finalize_options(self): # must override
118 # bdist_apps.finalize_options(self)
121 '''Our bdist_apps' customization.'''
123 cmd
= 'patch --forward ' + \
124 '../venv/lib/python3.7/site-packages/direct/dist/commands.py' + \
125 ' lib/build/commands.patch'
129 hbranch
= {'master': 'alpha', 'rc': 'rc', 'stable': ''}[branch
]
130 AppImageBuilder(self
).build(longname
, hbranch
,
131 'https://www.ya2.it/downloads/')
132 fbranch
= {'master': 'alpha', 'rc': 'rc', 'stable': 'stable'}[branch
]
133 bld
= FlatpakBuilder(
136 '/home/flavio/builders/pmachines_builder/flatpak',
137 'D43B6D401912B520B6805FCC8E019E6340E3BAB5',
138 '/home/flavio/builders/pmachines_builder/gpg',
139 'https://www.ya2.it/flatpak',
146 if __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
):
152 platform_lst
+= ['manylinux2010_x86_64']
153 installers_dct
['manylinux2010_x86_64'] = []
154 log_path
= '$USER_APPDATA/pmachines/logs/%Y/%B/%d/%H_%M_%S.log'
155 package_data_dirs
= {'simplepbr': [('simplepbr/shaders*', '', {})]}
160 'develop': DevelopPyCmd
,
165 'bdist_apps': BDistAppsCmd
},
166 install_requires
=['panda3d'],
169 'exclude_patterns': [
170 'build/*', 'built/*', 'setup.py', 'requirements.txt',
171 'venv/*', '.git*', '*.pyc', 'options.ini', '__pycache__',
172 'assets/models/gltf/*', 'assets/models/**/*.blend',
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
,
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']},
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']},
194 'include_patterns': [
212 'platforms': platform_lst
,
213 'include_modules': {'*': ['encodings.hex_codec']}},
214 'bdist_apps': {'installers': installers_dct
}})