Commits

Lenard Lindstrom  committed 2b93930

make python -m pygame.docs bring up the docs in a browser. also fix Python 3 issues with executable packages

  • Participants
  • Parent commits e3a61fb

Comments (0)

Files changed (8)

File docs/__init__.py

+# Make docs a package that brings up the main page in a web brower when
+# executed.
+#
+# python -m pygame.docs
+
+if __name__ == '__main__':
+    import os
+    pkg_dir = os.path.dirname(os.path.abspath(__file__))
+    main = os.path.join(pkg_dir, '__main__.py')
+    execfile(main)
+
+

File docs/__main__.py

+# python -m pygame.docs
+
+import os
+import webbrowser
+try:
+    from urllib.parse import urlunparse, quote
+except ImportError:
+    from urlparse import urlunparse
+    from urllib import quote
+
+def iterpath(path):
+    path, last = os.path.split(path)
+    if last:
+        for p in iterpath(path):
+            yield p
+        yield last
+
+pkg_dir = os.path.dirname(os.path.abspath(__file__))
+main_page = os.path.join(pkg_dir, 'index.html')
+url_path = quote('/'.join(iterpath(main_page)))
+url = urlunparse(('file', '', url_path, '', '', ''))
+webbrowser.open(url)

File examples/data/house_lo.mp3

Binary file modified.

File run_tests.py

 
 """
 
-import test.go
+import test.__main__
 
                        'pygame.tests.run_tests__tests.exclude',
                        'pygame.tests.run_tests__tests.timeout',
                        'pygame.tests.run_tests__tests.everything',
+                       'pygame.docs',
                        'pygame.examples'],
        "package_dir": {'pygame': 'lib',
                        'pygame.threads': 'lib/threads',
                        'pygame.gp2x': 'lib/gp2x',
                        'pygame.tests': 'test',
+                       'pygame.docs': 'docs',
                        'pygame.examples': 'examples'},
        "headers":     headers,
        "ext_modules": extensions,

File test/__init__.py

 A quick way to run the test suite package from the command line
 is by importing the go submodule:
 
-python -c "import pygame.tests.go" [<test options>]
+python -m "import pygame.tests" [<test options>]
 
 Command line option --help displays a usage message. Available options
 correspond to the pygame.tests.run arguments.
 individual parts of Pygame. Each can also be run as a main program. This is
 useful if the test, such as cdrom_test, is interactive.
 
-For Pygame development the test suite can be run from a Pygame 
-distribution root directory. Program run_tests.py is provided for convenience,
-though test/go.py can be run directly.
+For Pygame development the test suite can be run from a Pygame distribution
+root directory using run_tests.py. Alternately, test/__main__.py can be run
+directly.
 
 """
 
 if __name__ == 'pygame.tests':
     from pygame.tests.test_utils.run_tests import run
 elif __name__ == '__main__':
-    import pygame.tests.go
+    import os
+    pkg_dir = os.path.dirname(os.path.abspath(__file__))
+    main = os.path.join(pkg_dir, '__main__.py')
+    execfile(main)
 else:
     from test.test_utils.run_tests import run
-

File test/__main__.py

+"""Load and run the Pygame test suite
+
+python -c "import pygame.tests.go" [<test options>]
+
+or
+
+python test/go.py [<test options>]
+
+Command line option --help displays a command line usage message.
+
+run_tests.py in the main distribution directory is an alternative to test.go
+
+"""
+
+import sys
+
+if __name__ == '__main__':
+    import os
+    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
+    parent_dir, pkg_name = os.path.split(pkg_dir)
+    is_pygame_pkg = (pkg_name == 'tests' and
+                     os.path.split(parent_dir)[1] == 'pygame')
+    if not is_pygame_pkg:
+        sys.path.insert(0, parent_dir)
+else:
+    is_pygame_pkg = __name__.startswith('pygame.tests.')
+
+if is_pygame_pkg:
+    from pygame.tests.test_utils.run_tests import run
+    from pygame.tests.test_utils.test_runner import opt_parser
+else:
+    from test.test_utils.run_tests import run
+    from test.test_utils.test_runner import opt_parser
+
+if is_pygame_pkg:
+    test_pkg_name = "pygame.tests"
+else:
+    test_pkg_name = "test"
+program_name = sys.argv[0]
+if program_name == '-c':
+    program_name = 'python -c "import %s.go"' % test_pkg_name
+
+###########################################################################
+# Set additional command line options
+#
+# Defined in test_runner.py as it shares options, added to here
+
+opt_parser.set_usage("""
+
+Runs all or some of the %(pkg)s.xxxx_test tests.
+
+$ %(exec)s sprite threads -sd
+
+Runs the sprite and threads module tests isolated in subprocesses, dumping
+all failing tests info in the form of a dict.
+
+""" % {'pkg': test_pkg_name, 'exec': program_name})
+
+opt_parser.add_option (
+     "-d",  "--dump", action = 'store_true',
+     help   = "dump failures/errors as dict ready to eval" )
+
+opt_parser.add_option (
+     "-F",  "--file",
+     help   = "dump failures/errors to a file" )
+
+opt_parser.add_option (
+     "-a",  "--all", action = 'store_true',
+     help   = "dump all results not just errors eg. -da" )
+
+opt_parser.add_option (
+     "-m",  "--multi_thread", metavar = 'THREADS', type = 'int',
+     help   = "run subprocessed tests in x THREADS" )
+
+opt_parser.add_option (
+     "-t",  "--time_out", metavar = 'SECONDS', type = 'int',
+     help   = "kill stalled subprocessed tests after SECONDS" )
+
+opt_parser.add_option (
+     "-f",  "--fake", metavar = "DIR",
+     help   = "run fake tests in run_tests__tests/$DIR" )
+
+opt_parser.add_option (
+     "-p",  "--python", metavar = "PYTHON",
+     help   = "path to python excutable to run subproccesed tests\n"
+              "default (sys.executable): %s" % sys.executable)
+
+TIME_OUT = 30
+
+# DEFAULTS
+
+opt_parser.set_defaults (
+    python = sys.executable,
+    time_out = TIME_OUT,
+)
+
+###########################################################################
+# Set run() keyword arguements according to command line arguemnts.
+# args will be the test module list, passed as positional argumemts.
+
+options, args = opt_parser.parse_args()
+
+kwds = {}
+if options.incomplete:
+    kwds['incomplete'] = True
+if options.nosubprocess:
+    kwds['nosubprocess'] = True
+if options.dump:
+    kwds['dump'] = True
+if options.file:
+    kwds['file'] = options.file
+kwds['timings'] = options.timings
+if options.exclude:
+    kwds['exclude'] = options.exclude
+if options.show_output:
+    kwds['show_output'] = True
+if options.all:
+    kwds['all'] = True
+if options.randomize:
+    kwds['randomize'] = True
+if options.seed is not None:
+    kwds['seed'] = options.seed
+if options.multi_thread is not None:
+    kwds['multi_thread'] = options.multi_thread
+if options.time_out is not None:
+    kwds['time_out'] = options.time_out
+if options.fake:
+    kwds['fake'] = options.fake
+if options.python:
+    kwds['python'] = options.python
+
+###########################################################################
+# Run the test suite.
+run(*args, **kwds)
+
+

File test/go.py

-"""Load and run the Pygame test suite
-
-python -c "import pygame.tests.go" [<test options>]
-
-or
-
-python test/go.py [<test options>]
-
-Command line option --help displays a command line usage message.
-
-run_tests.py in the main distribution directory is an alternative to test.go
-
-"""
-
-import sys
-
-if __name__ == '__main__':
-    import os
-    pkg_dir = os.path.split(os.path.abspath(__file__))[0]
-    parent_dir, pkg_name = os.path.split(pkg_dir)
-    is_pygame_pkg = (pkg_name == 'tests' and
-                     os.path.split(parent_dir)[1] == 'pygame')
-    if not is_pygame_pkg:
-        sys.path.insert(0, parent_dir)
-else:
-    is_pygame_pkg = __name__.startswith('pygame.tests.')
-
-if is_pygame_pkg:
-    from pygame.tests.test_utils.run_tests import run
-    from pygame.tests.test_utils.test_runner import opt_parser
-else:
-    from test.test_utils.run_tests import run
-    from test.test_utils.test_runner import opt_parser
-
-if is_pygame_pkg:
-    test_pkg_name = "pygame.tests"
-else:
-    test_pkg_name = "test"
-program_name = sys.argv[0]
-if program_name == '-c':
-    program_name = 'python -c "import %s.go"' % test_pkg_name
-
-###########################################################################
-# Set additional command line options
-#
-# Defined in test_runner.py as it shares options, added to here
-
-opt_parser.set_usage("""
-
-Runs all or some of the %(pkg)s.xxxx_test tests.
-
-$ %(exec)s sprite threads -sd
-
-Runs the sprite and threads module tests isolated in subprocesses, dumping
-all failing tests info in the form of a dict.
-
-""" % {'pkg': test_pkg_name, 'exec': program_name})
-
-opt_parser.add_option (
-     "-d",  "--dump", action = 'store_true',
-     help   = "dump failures/errors as dict ready to eval" )
-
-opt_parser.add_option (
-     "-F",  "--file",
-     help   = "dump failures/errors to a file" )
-
-opt_parser.add_option (
-     "-a",  "--all", action = 'store_true',
-     help   = "dump all results not just errors eg. -da" )
-
-opt_parser.add_option (
-     "-m",  "--multi_thread", metavar = 'THREADS', type = 'int',
-     help   = "run subprocessed tests in x THREADS" )
-
-opt_parser.add_option (
-     "-t",  "--time_out", metavar = 'SECONDS', type = 'int',
-     help   = "kill stalled subprocessed tests after SECONDS" )
-
-opt_parser.add_option (
-     "-f",  "--fake", metavar = "DIR",
-     help   = "run fake tests in run_tests__tests/$DIR" )
-
-opt_parser.add_option (
-     "-p",  "--python", metavar = "PYTHON",
-     help   = "path to python excutable to run subproccesed tests\n"
-              "default (sys.executable): %s" % sys.executable)
-
-TIME_OUT = 30
-
-# DEFAULTS
-
-opt_parser.set_defaults (
-    python = sys.executable,
-    time_out = TIME_OUT,
-)
-
-###########################################################################
-# Set run() keyword arguements according to command line arguemnts.
-# args will be the test module list, passed as positional argumemts.
-
-options, args = opt_parser.parse_args()
-
-kwds = {}
-if options.incomplete:
-    kwds['incomplete'] = True
-if options.nosubprocess:
-    kwds['nosubprocess'] = True
-if options.dump:
-    kwds['dump'] = True
-if options.file:
-    kwds['file'] = options.file
-kwds['timings'] = options.timings
-if options.exclude:
-    kwds['exclude'] = options.exclude
-if options.show_output:
-    kwds['show_output'] = True
-if options.all:
-    kwds['all'] = True
-if options.randomize:
-    kwds['randomize'] = True
-if options.seed is not None:
-    kwds['seed'] = options.seed
-if options.multi_thread is not None:
-    kwds['multi_thread'] = options.multi_thread
-if options.time_out is not None:
-    kwds['time_out'] = options.time_out
-if options.fake:
-    kwds['fake'] = options.fake
-if options.python:
-    kwds['python'] = options.python
-
-###########################################################################
-# Run the test suite.
-run(*args, **kwds)
-
-