-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
121 lines (104 loc) · 3.05 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
APP_NAME = 'Dodopult'
cfg = {
'name': APP_NAME,
'version': '1.0dev',
'description': 'A simple game',
'author': 'Ignas Mikalajunas and Marius Gedminas',
'author_email': '',
'url': '',
'py2exe.target': '',
'py2exe.icon': 'assets\\Dodo.ico', #64x64
'py2exe.binary': APP_NAME, #leave off the .exe, it will be added
}
# usage: python setup.py command
#
# sdist - build a source dist
# py2exe - build an exe
#
# the goods are placed in the dist dir for you to .zip up or whatever...
from distutils.core import setup, Extension
try:
import py2exe
except:
pass
import sys
import glob
import os
import shutil
try:
cmd = sys.argv[1]
except IndexError:
raise SystemExit('Usage: setup.py py2exe')
# utility for adding subdirectories
def add_files(dest, generator):
for dirpath, dirnames, filenames in generator:
for name in 'CVS', '.svn', '.git':
if name in dirnames:
dirnames.remove(name)
for name in filenames:
if '~' in name: continue
suffix = os.path.splitext(name)[1]
if suffix in ('.pyc', '.pyo'): continue
if name[0] == '.': continue
filename = os.path.join(dirpath, name)
dest.append(filename)
# define what is our data
data = []
add_files(data, os.walk('assets'))
print data
data.extend(glob.glob('*.txt'))
data.extend(glob.glob('*.png'))
# define what is our source
src = []
add_files(src, os.walk('lib'))
src.extend(glob.glob('*.py'))
# build the sdist target
if cmd == 'sdist':
f = open("MANIFEST.in", "w")
for l in data: f.write("include "+l+"\n")
for l in src: f.write("include "+l+"\n")
f.close()
setup(
name=cfg['name'],
version=cfg['version'],
description=cfg['description'],
author=cfg['author'],
author_email=cfg['author_email'],
url=cfg['url'],
)
# build the py2exe target
if cmd in ('py2exe',):
dist_dir = os.path.join('dist', cfg['py2exe.target'])
data_dir = dist_dir
src = 'dodo.py'
dest = cfg['py2exe.binary']+'.py'
shutil.copy(src, dest)
setup(
options={'py2exe': {
'dist_dir': dist_dir,
'dll_excludes': ['_dotblas.pyd', '_numpy.pyd']
}},
windows=[{
'script': dest,
'icon_resources': [(0, 'assets\\Dodo.ico')],
}],
)
# recursively make a bunch of folders
def make_dirs(dname_):
parts = list(os.path.split(dname_))
dname = None
while len(parts):
if dname == None:
dname = parts.pop(0)
else:
dname = os.path.join(dname, parts.pop(0))
if not os.path.isdir(dname):
os.mkdir(dname)
# copy data into the binaries
if cmd in ('py2exe',):
dest = data_dir
for fname in data:
dname = os.path.join(dest, os.path.dirname(fname))
make_dirs(dname)
if not os.path.isdir(fname):
shutil.copy(fname, dname)