forked from fogleman/Minecraft
-
Notifications
You must be signed in to change notification settings - Fork 33
/
setup.py
126 lines (107 loc) · 3.51 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
122
123
124
125
126
import glob
import os
import sys
from Cython.Distutils import build_ext
from distutils.util import get_platform
from distutils.extension import Extension
import globals as G
excluded_modules = (
'globals',
'gui',
'views',
'controllers',
'mods',
'build',
'setup',
'setup-py2exe',
'setup-cx_Freeze',
'pyglet.gl.glext_arb',
'pyglet.gl.glext_nv',
'pyglet.image.codecs',
'pyglet.image.codecs.pypng',
'pyglet.media',
'pyglet.media.drivers.alsa.asound',
'pyglet.window',
'pyglet.window.xlib.xlib',
'venv',
)
excluded_includes = (
'main',
'manager',
)
def find_files(source, target, patterns):
"""Locates the specified data-files and returns the matches
in a data_files compatible format.
source is the root of the source data tree.
Use '' or '.' for current directory.
target is the root of the target data tree.
Use '' or '.' for the distribution directory.
patterns is a sequence of glob-patterns for the
files you want to copy.
"""
if glob.has_magic(source) or glob.has_magic(target):
raise ValueError("Magic not allowed in src, target")
ret = {}
for pattern in patterns:
pattern = os.path.join(source, pattern)
for filename in glob.glob(pattern):
if os.path.isfile(filename):
targetpath = os.path.join(target, os.path.relpath(filename, source))
path = os.path.dirname(targetpath)
ret.setdefault(path, []).append(filename)
return sorted(ret.items())
def get_modules(path=None):
first = False
if path is None:
path = os.path.abspath(os.path.dirname(__file__))
first = True
for f_or_d in os.listdir(path):
if not first:
f_or_d = os.path.join(path, f_or_d)
if os.path.isdir(f_or_d) and f_or_d not in excluded_modules:
d = f_or_d
for name, f in get_modules(d):
yield name, f
else:
f = f_or_d
if f.endswith(('.py', 'pyx')):
name = '.'.join(s for s in f.split('.')[0].replace("\\","/").split('/')
if s != '__init__')
if name and name not in excluded_modules:
yield name, f
ext_modules = [Extension(name, [f]) for name, f in get_modules()]
includes = [name for name, f in get_modules() if name not in excluded_includes]
packages = ["pyglet", "sqlite3"] # force cx_Freeze to bundle these
cython_output_dir = "build/lib.%s-%d.%d" % (get_platform(), *sys.version_info[:2])
options = {
'build_ext': {
# 'inplace': True,
'cython_c_in_temp': True,
'cython_directives': {
'language_level': '3',
}
},
}
if len(sys.argv) > 1 and sys.argv[1] in ("build", "build_exe"):
from cx_Freeze import setup, Executable
options['build_exe'] = {
'packages': packages,
'excludes': ['test', 'unittest'],
'includes': includes,
'include_files': ['resources/'],
"path": [cython_output_dir] + sys.path,
}
executables = [Executable("main.py", targetName=G.APP_NAME + (".exe" if sys.platform == 'win32' else '')), Executable("server.py")]
else:
from distutils.core import setup
executables = []
setup(
name=G.APP_NAME,
cmdclass={'build_ext': build_ext},
options=options,
requires=['pyglet', 'Cython'],
version="0.1",
description="A Minecraft demo clone in Python 3.6.x",
ext_modules=ext_modules,
executables=executables,
)