Stricter PEP-8 conformance.
[python-bulletml.git] / setup.py
1 #!/usr/bin/env python
2
3 import glob
4 import os
5 import shutil
6 import sys
7
8 from distutils.core import setup, Command, Extension
9 from distutils.command.clean import clean as distutils_clean
10 from distutils.command.sdist import sdist as distutils_sdist
11
12
13 class clean(distutils_clean):
14 def run(self):
15 # In addition to what the normal clean run does, remove pyc
16 # and pyo and backup files from the source tree.
17 distutils_clean.run(self)
18
19 def should_remove(filename):
20 if (filename.lower()[-4:] in [".pyc", ".pyo"]
21 or filename.endswith("~")
22 or (filename.startswith("#")
23 and filename.endswith("#"))):
24 return True
25 else:
26 return False
27 for pathname, dirs, files in os.walk(os.path.dirname(__file__)):
28 for filename in filter(should_remove, files):
29 try:
30 os.unlink(os.path.join(pathname, filename))
31 except EnvironmentError as err:
32 print(str(err))
33
34 try:
35 os.unlink("MANIFEST")
36 except OSError:
37 pass
38
39 for base in ["coverage", "build", "dist"]:
40 path = os.path.join(os.path.dirname(__file__), base)
41 if os.path.isdir(path):
42 shutil.rmtree(path)
43
44
45 class coverage_cmd(Command):
46 description = "generate test coverage data"
47 user_options = []
48
49 def initialize_options(self):
50 pass
51
52 def finalize_options(self):
53 pass
54
55 def run(self):
56 import trace
57 tracer = trace.Trace(
58 count=True, trace=False,
59 ignoredirs=[sys.prefix, sys.exec_prefix])
60
61 def run_tests():
62 import bulletml
63 try:
64 reload(bulletml)
65 except NameError:
66 pass
67 self.run_command("test")
68
69 tracer.runfunc(run_tests)
70 results = tracer.results()
71 coverage = os.path.join(os.path.dirname(__file__), "coverage")
72 results.write_results(show_missing=True, coverdir=coverage)
73 map(os.unlink, glob.glob(os.path.join(coverage, "[!b]*.cover")))
74 try:
75 os.unlink(os.path.join(coverage, "..setup.cover"))
76 except OSError:
77 pass
78
79 total_lines = 0
80 bad_lines = 0
81 for filename in glob.glob(os.path.join(coverage, "*.cover")):
82 lines = open(filename, "rU").readlines()
83 total_lines += len(lines)
84 bad_lines += len(
85 [line for line in lines if
86 (line.startswith(">>>>>>") and
87 "finally:" not in line and '"""' not in line)])
88 pct = 100.0 * (total_lines - bad_lines) / float(total_lines)
89 print("Coverage data written to %s (%d/%d, %0.2f%%)" % (
90 coverage, total_lines - bad_lines, total_lines, pct))
91
92
93 class sdist(distutils_sdist):
94 def run(self):
95 self.run_command("test")
96 distutils_sdist.run(self)
97
98
99 class test_cmd(Command):
100 description = "run automated tests"
101 user_options = [
102 ("to-run=", None, "list of tests to run (default all)"),
103 ]
104
105 def initialize_options(self):
106 self.to_run = []
107 self.quick = False
108
109 def finalize_options(self):
110 if self.to_run:
111 self.to_run = self.to_run.split(",")
112
113 def run(self):
114 import tests
115 if tests.unit(self.to_run):
116 raise SystemExit("Test failures are listed above.")
117
118 if __name__ == "__main__":
119 setup(cmdclass=dict(clean=clean, test=test_cmd, coverage=coverage_cmd,
120 sdist=sdist),
121 name="python-bulletml", version="3",
122 url="https://yukkurigames.com/python-bulletml/",
123 description="parse and run BulletML scripts",
124 author="Joe Wreschnig",
125 author_email="joe.wreschnig@gmail.com",
126 license="MIT-style",
127 packages=["bulletml"],
128 data_files=glob.glob("examples/*/*.xml") + ["examples/template.xml"],
129 scripts=["bulletml-runner", "bulletml-to-bulletyaml"],
130 ext_modules=[Extension(
131 'bulletml._collision',
132 [os.path.join('bulletml', '_collision.c')])],
133 long_description="""\
134 BulletML is the Bullet Markup Language. BulletML can describe the
135 barrage of bullets in shooting games. (For example Progear, Psyvariar,
136 Gigawing2, G DARIUS, XEVIOUS, ...) This module parses and executes
137 BulletML scripts in Python. All data structures in it are
138 renderer-agnostic. A sample renderer for Pygame is included. The full
139 API documentation is contained in its Python docstrings.
140
141 In addition to the standard BulletML XML format, this module supports
142 an equivalent YAML format. For convenience, two simple collision
143 routines are provided, bulletml.overlaps for stationary circles and
144 bulletml.collides for moving circles.
145
146 More information is available at the BulletML homepage,
147 http://www.asahi-net.or.jp/~cs8k-cyu/bulletml/index_e.html, or the
148 python-bulletml homepage, https://yukkurigames.com/python-bulletml/.
149 """)