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 multiprocessing
import cpu_count
14 from direct
.dist
.commands
import bdist_apps
15 from lib
.build
.build
import branch
, files
, ver
, files
, bld_dpath
16 from lib
.build
.docs
import bld_docs
17 from lib
.build
.models
import ModelsBuilder
18 from lib
.build
.images
import bld_images
19 from lib
.build
.screenshots
import bld_screenshots
20 from lib
.build
.lang
import LanguageBuilder
21 from p3d_appimage
import AppImageBuilder
22 from p3d_flatpak
import FlatpakBuilder
23 import lib
.engine
.log
# so logging's info/debug are logged
24 from game
.app
import PmachinesApp
27 appname
= longname
= 'pmachines'
31 msg
= '''NOTE: please be sure that you've already created the assets with:
32 * python setup.py images models lang'''
35 class DevelopPyCmd(develop
):
36 '''Command for setting up the development.'''
39 '''Prepare the development environment.'''
41 Popen([executable
, __file__
, 'lang']).communicate()
42 Popen([executable
, __file__
, 'models']).communicate()
45 class AbsCmd(Command
):
46 '''Common functionalities for commands.'''
48 user_options
= [('cores=', None, '#cores')]
51 def initialize_options(self
):
53 if arg
.startswith('--cores='):
54 AbsCmd
.cores
= int(arg
.split('=')[1])
56 def finalize_options(self
): # must override
60 class DocsCmd(AbsCmd
):
61 '''Command for building the docs.'''
64 '''Builds the docs.'''
68 class ModelsCmd(AbsCmd
):
69 '''Command for building the models.'''
72 '''Builds the models.'''
73 ModelsBuilder().build('assets/models', int(AbsCmd
.cores
))
76 class ImagesCmd(AbsCmd
):
77 '''Command for building the models.'''
80 '''Builds the images.'''
81 bld_screenshots(PmachinesApp
.scenes
)
83 files(['jpg', 'png'], ['models', 'gltf', 'bam'], ['_png.png']), int(AbsCmd
.cores
))
86 class LangCmd(AbsCmd
):
87 '''Command for building po, pot and mo files.'''
89 lang_path
= 'assets/locale/'
91 def _process_lang(self
, lang_code
):
92 '''Processes a single language.'''
93 poname
= 'assets/locale/po/%s.po' % lang_code
94 LanguageBuilder
.merge(lang_code
, 'assets/locale/po/', self
.lang_path
, appname
)
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
)
100 '''Builds the language files.'''
101 LanguageBuilder
.pot(appname
, 'assets/locale/po/')
102 list(map(self
._process
_lang
, ['it_IT']))
105 class BDistAppsCmd(bdist_apps
):
106 '''Customization of BDistApps.'''
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")]
113 def initialize_options(self
):
114 '''Default values.'''
115 bdist_apps
.initialize_options(self
)
116 self
.nowin
, self
.nolinux
= None, None
118 #def finalize_options(self): # must override
119 # bdist_apps.finalize_options(self)
122 '''Our bdist_apps' customization.'''
124 cmd
= 'patch --forward ' + \
125 '../venv/lib/python3.7/site-packages/direct/dist/commands.py' + \
126 ' lib/build/commands.patch'
130 hbranch
= {'master': 'alpha', 'rc': 'rc', 'stable': ''}[branch
]
131 AppImageBuilder(self
).build(longname
, hbranch
,
132 'https://www.ya2.it/downloads/')
133 fbranch
= {'master': 'alpha', 'rc': 'rc', 'stable': 'stable'}[branch
]
134 bld
= FlatpakBuilder(
137 '/home/flavio/builders/pmachines_builder/flatpak',
138 'D43B6D401912B520B6805FCC8E019E6340E3BAB5',
139 '/home/flavio/builders/pmachines_builder/gpg',
140 'https://www.ya2.it/flatpak',
147 if __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
+= ['manylinux2010_x86_64']
154 installers_dct
['manylinux2010_x86_64'] = []
155 log_path
= '$USER_APPDATA/pmachines/logs/%Y/%B/%d/%H_%M_%S.log'
156 package_data_dirs
= {'simplepbr': [('simplepbr/shaders*', '', {})]}
161 'develop': DevelopPyCmd
,
166 'bdist_apps': BDistAppsCmd
},
167 install_requires
=['panda3d'],
170 'exclude_patterns': [
171 'build/*', 'built/*', 'setup.py', 'requirements.txt',
172 'venv/*', '.git*', '*.pyc', 'options.ini', '__pycache__',
173 'assets/models/gltf/*', 'assets/models/**/*.blend',
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
,
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']},
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']},
195 'include_patterns': [
213 'platforms': platform_lst
,
214 'include_modules': {'*': ['encodings.hex_codec']}},
215 'bdist_apps': {'installers': installers_dct
}})