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