-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
78 lines (61 loc) · 2.29 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import os
import subprocess
import shutil
from pathlib import Path
from setuptools import setup, find_packages, command
from setuptools.command.build_py import build_py
from distutils.command.build import build as _build
from distutils.command.clean import clean as _clean
from distutils.command.install import install as _install
# Get all of the ui files in the project.
UI_FILES = []
RC_FILES = []
for root, directories, files in os.walk('.'):
for file in files:
if os.path.splitext(file)[-1] == '.ui':
UI_FILES.append(os.path.join(root, file))
elif os.path.splitext(file)[-1] == '.qrc':
RC_FILES.append(os.path.join(root, file))
class UIBuild(_build):
def run(self):
# Convert all ui files into python files.
for file in UI_FILES:
basename = os.path.splitext(file)[0]
subprocess.run(f'pyuic5 --from-imports -o {basename}.py {file}', shell=True)
for file in RC_FILES:
basename = os.path.splitext(file)[0]
subprocess.run(f'pyrcc5 -o {basename}_rc.py {file}', shell=True)
super(UIBuild, self).run()
class UIClean(_clean):
def run(self):
# Clean up all converted UI files.
for file in UI_FILES + RC_FILES:
basename = os.path.splitext(file)[0]
if os.path.exists(f'{basename}.py'):
os.remove(f'{basename}.py')
# Remove some autogenerated things that setuptools never cleans up.
if os.path.exists('build'):
shutil.rmtree('build')
if os.path.exists('dist'):
shutil.rmtree('dist')
if os.path.exists('.DS_Store'):
os.remove('.DS_Store')
super(UIClean, self).run()
class pyinstaller(_install):
def run(self):
code_wheel = Path('.') / 'code_wheel' / '__main__.py'
resources = Path('.') / 'code_wheel' / 'resources'
icon = resources / 'icon.ico'
subprocess.run(f'pyinstaller -F -w -i {icon} {code_wheel}')
shutil.move(Path('dist') / '__main__.exe', Path('dist') / 'Bard\'s Tale IV Code Wheel.exe')
setup(
author='Christopher Pezley',
name="Bard's Tale 4 Code Wheel",
version="1.0",
packages=find_packages(),
cmdclass={
'build': UIBuild,
'clean': UIClean,
'install': pyinstaller,
},
)