[Python-checkins] r45514 - in sandbox/trunk/setuptools: _pkgutil.py doctest.py pkg_resources.py pydoc.py setup.py setuptools/tests/doctest.py (original) (raw)

phillip.eby python-checkins at python.org
Tue Apr 18 05:03:19 CEST 2006


Author: phillip.eby Date: Tue Apr 18 05:03:16 2006 New Revision: 45514

Added: sandbox/trunk/setuptools/_pkgutil.py - copied unchanged from r45512, python/trunk/Lib/pkgutil.py sandbox/trunk/setuptools/doctest.py - copied, changed from r45512, python/trunk/Lib/doctest.py sandbox/trunk/setuptools/pydoc.py - copied, changed from r45512, python/trunk/Lib/pydoc.py Removed: sandbox/trunk/setuptools/setuptools/tests/doctest.py Modified: sandbox/trunk/setuptools/pkg_resources.py sandbox/trunk/setuptools/setup.py Log: Backport pkgutil, pydoc, and doctest from the 2.5 trunk to setuptools 0.7 trunk. (Sideport?) Setuptools 0.7 will install these in place of the 2.3/2.4 versions (at least of pydoc and doctest) to let them work properly with eggs. pkg_resources now depends on the 2.5 pkgutil, which is included here as _pkgutil, to work around the fact that some system packagers will install setuptools without overriding the stdlib modules.
But users who install their own setuptools will get them, and the system packaged people probably don't need them.

Copied: sandbox/trunk/setuptools/doctest.py (from r45512, python/trunk/Lib/doctest.py)

--- python/trunk/Lib/doctest.py (original) +++ sandbox/trunk/setuptools/doctest.py Tue Apr 18 05:03:16 2006 @@ -1328,13 +1328,13 @@ __LINECACHE_FILENAME_RE = re.compile(r'<doctest ' r'(?P[\w.]+)' r'[(?P\d+)]>$')

Modified: sandbox/trunk/setuptools/pkg_resources.py

--- sandbox/trunk/setuptools/pkg_resources.py (original) +++ sandbox/trunk/setuptools/pkg_resources.py Tue Apr 18 05:03:16 2006 @@ -13,7 +13,7 @@ method. """ -import sys, os, zipimport, time, re, imp, new +import sys, os, zipimport, time, re, imp, new, pkgutil # XXX from sets import ImmutableSet from os import utime, rename, unlink # capture these to bypass sandboxing from os import open as os_open @@ -244,6 +244,15 @@ return get_distribution(dist).get_entry_info(group, name) +try: + from pkgutil import get_importer +except ImportError: + import _pkgutil as pkgutil + get_importer = pkgutil.get_importer +else: + import pkgutil + + class IMetadataProvider: def has_metadata(name): @@ -276,15 +285,6 @@

@@ -1411,7 +1411,6 @@ metadata = PathMetadata(egg_path, os.path.join(egg_path,'EGG-INFO')) dist = Distribution.from_filename(egg_path, metadata=metadata) """

 def __init__(self, path, egg_info):
     self.module_path = path
     self.egg_info = egg_info

@@ -1433,87 +1432,6 @@ self._setup_prefix() -class ImpWrapper: - """PEP 302 Importer that wraps Python's "normal" import algorithm"""

_distribution_finders = {}

@@ -1595,7 +1513,7 @@ for item in find_distributions(line.rstrip()): yield item

-register_finder(ImpWrapper,find_on_path) +register_finder(pkgutil.ImpImporter, find_on_path)

_namespace_handlers = {} _namespace_packages = {} @@ -1691,8 +1609,8 @@ # Only return the path if it's not already there return subpath

-register_namespace_handler(ImpWrapper,file_ns_handler) -register_namespace_handler(zipimport.zipimporter,file_ns_handler) +register_namespace_handler(pkgutil.ImpImporter, file_ns_handler) +register_namespace_handler(zipimport.zipimporter, file_ns_handler)

def null_ns_handler(importer, path_item, packageName, module):

Copied: sandbox/trunk/setuptools/pydoc.py (from r45512, python/trunk/Lib/pydoc.py)

--- python/trunk/Lib/pydoc.py (original) +++ sandbox/trunk/setuptools/pydoc.py Tue Apr 18 05:03:16 2006 @@ -53,6 +53,9 @@

path will be displayed.

import sys, imp, os, re, types, inspect, builtin, pkgutil +if not hasattr(pkgutil,'walk_packages'):

Modified: sandbox/trunk/setuptools/setup.py

--- sandbox/trunk/setuptools/setup.py (original) +++ sandbox/trunk/setuptools/setup.py Tue Apr 18 05:03:16 2006 @@ -18,12 +18,12 @@ from distutils.util import convert_path d = {}; execfile(convert_path('setuptools/command/init.py'), d) SETUP_COMMANDS = d['all']

VERSION = "0.7a1" from setuptools import setup, find_packages import sys -scripts = []

+modules = ['pkg_resources','easy_install'] +if sys.version<"2.5":

setup( name="setuptools", version=VERSION, @@ -39,7 +39,7 @@ packages = find_packages(), package_data = {'setuptools':['*.exe','site-patch.py']},

@@ -91,7 +91,7 @@ Topic :: System :: Archiving :: Packaging Topic :: System :: Systems Administration Topic :: Utilities""".splitlines() if f.strip()],

Deleted: /sandbox/trunk/setuptools/setuptools/tests/doctest.py

--- /sandbox/trunk/setuptools/setuptools/tests/doctest.py Tue Apr 18 05:03:16 2006 +++ (empty file) @@ -1,2677 +0,0 @@ -# Module doctest. -# Released to the public domain 16-Jan-2001, by Tim Peters (tim at python.org). -# Major enhancements and refactoring by: -# Jim Fulton -# Edward Loper

-# Provided as-is; use at your own risk; no warranty; no promises; enjoy!

-try: - basestring -except NameError: - basestring = str,unicode

-try: - enumerate -except NameError: - def enumerate(seq): - return zip(range(len(seq)),seq)

-r"""Module doctest -- a framework for running examples in docstrings.

-In simplest use, end each module M to be tested with:

-def _test(): - import doctest - doctest.testmod()

-if name == "main": - _test()

-Then running the module as a script will cause the examples in the -docstrings to get executed and verified:

-python M.py

-This won't display anything unless an example fails, in which case the -failing example(s) and the cause(s) of the failure(s) are printed to stdout -(why not stderr? because stderr is a lame hack <0.2 wink>), and the final -line of output is "Test failed.".

-Run it with the -v switch instead:

-python M.py -v

-and a detailed report of all examples tried is printed to stdout, along -with assorted summaries at the end.

-You can force verbose mode by passing "verbose=True" to testmod, or prohibit -it by passing "verbose=False". In either of those cases, sys.argv is not -examined by testmod.

-There are a variety of other ways to run doctests, including integration -with the unittest framework, and support for running non-Python text -files containing doctests. There are also many ways to override parts -of doctest's default behaviors. See the Library Reference Manual for -details. -"""

-docformat = 'reStructuredText en'

-all = [ - # 0, Option Flags - 'register_optionflag', - 'DONT_ACCEPT_TRUE_FOR_1', - 'DONT_ACCEPT_BLANKLINE', - 'NORMALIZE_WHITESPACE', - 'ELLIPSIS', - 'IGNORE_EXCEPTION_DETAIL', - 'COMPARISON_FLAGS', - 'REPORT_UDIFF', - 'REPORT_CDIFF', - 'REPORT_NDIFF', - 'REPORT_ONLY_FIRST_FAILURE', - 'REPORTING_FLAGS', - # 1. Utility Functions - 'is_private', - # 2. Example & DocTest - 'Example', - 'DocTest', - # 3. Doctest Parser - 'DocTestParser', - # 4. Doctest Finder - 'DocTestFinder', - # 5. Doctest Runner - 'DocTestRunner', - 'OutputChecker', - 'DocTestFailure', - 'UnexpectedException', - 'DebugRunner', - # 6. Test Functions - 'testmod', - 'testfile', - 'run_docstring_examples', - # 7. Tester - 'Tester', - # 8. Unittest Support - 'DocTestSuite', - 'DocFileSuite', - 'set_unittest_reportflags', - # 9. Debugging Support - 'script_from_examples', - 'testsource', - 'debug_src', - 'debug', -]

-import future

-import sys, traceback, inspect, linecache, os, re, types -import unittest, difflib, pdb, tempfile -import warnings -from StringIO import StringIO

-# Don't whine about the deprecated is_private function in this -# module's tests. -warnings.filterwarnings("ignore", "is_private", DeprecationWarning, - name, 0)

-# There are 4 basic classes: -# - Example: a <source, want> pair, plus an intra-docstring line number. -# - DocTest: a collection of examples, parsed from a docstring, plus -# info about where the docstring came from (name, filename, lineno). -# - DocTestFinder: extracts DocTests from a given object's docstring and -# its contained objects' docstrings. -# - DocTestRunner: runs DocTest cases, and accumulates statistics. -# -# So the basic picture is: -# -# list of: -# +------+ +---------+ +-------+ -# |object| --DocTestFinder-> | DocTest | --DocTestRunner-> |results| -# +------+ +---------+ +-------+ -# | Example | -# | ... | -# | Example | -# +---------+

-# Option constants.

-OPTIONFLAGS_BY_NAME = {} -def register_optionflag(name): - flag = 1 << len(OPTIONFLAGS_BY_NAME) - OPTIONFLAGS_BY_NAME[name] = flag - return flag

-DONT_ACCEPT_TRUE_FOR_1 = register_optionflag('DONT_ACCEPT_TRUE_FOR_1') -DONT_ACCEPT_BLANKLINE = register_optionflag('DONT_ACCEPT_BLANKLINE') -NORMALIZE_WHITESPACE = register_optionflag('NORMALIZE_WHITESPACE') -ELLIPSIS = register_optionflag('ELLIPSIS') -IGNORE_EXCEPTION_DETAIL = register_optionflag('IGNORE_EXCEPTION_DETAIL')

-COMPARISON_FLAGS = (DONT_ACCEPT_TRUE_FOR_1 | - DONT_ACCEPT_BLANKLINE | - NORMALIZE_WHITESPACE | - ELLIPSIS | - IGNORE_EXCEPTION_DETAIL)

-REPORT_UDIFF = register_optionflag('REPORT_UDIFF') -REPORT_CDIFF = register_optionflag('REPORT_CDIFF') -REPORT_NDIFF = register_optionflag('REPORT_NDIFF') -REPORT_ONLY_FIRST_FAILURE = register_optionflag('REPORT_ONLY_FIRST_FAILURE')

-REPORTING_FLAGS = (REPORT_UDIFF | - REPORT_CDIFF | - REPORT_NDIFF | - REPORT_ONLY_FIRST_FAILURE)

-# Special string markers for use in want strings: -BLANKLINE_MARKER = '' -ELLIPSIS_MARKER = '...'

-###################################################################### -## Table of Contents -###################################################################### -# 1. Utility Functions -# 2. Example & DocTest -- store test cases -# 3. DocTest Parser -- extracts examples from strings -# 4. DocTest Finder -- extracts test cases from objects -# 5. DocTest Runner -- runs test cases -# 6. Test Functions -- convenient wrappers for testing -# 7. Tester Class -- for backwards compatibility -# 8. Unittest Support -# 9. Debugging Support -# 10. Example Usage

-###################################################################### -## 1. Utility Functions -######################################################################

-def is_private(prefix, base): - """prefix, base -> true iff name prefix + "." + base is "private".

-class _SpoofOut(StringIO): - def getvalue(self): - result = StringIO.getvalue(self) - # If anything at all was written, make sure there's a trailing - # newline. There's no way for the expected output to indicate - # that a trailing newline is missing. - if result and not result.endswith("\n"): - result += "\n" - # Prevent softspace from screwing up the next test case, in - # case they used print with a trailing comma in an example. - if hasattr(self, "softspace"): - del self.softspace - return result

-def _ellipsis_match(want, got): - """ - Essentially the only subtle case: - >>> _ellipsis_match('aa...aa', 'aaa') - False - """ - if want.find(ELLIPSIS_MARKER)==-1: - return want == got

-def _module_relative_path(module, path): - if not inspect.ismodule(module): - raise TypeError, 'Expected a module: %r' % module - if path.startswith('/'): - raise ValueError, 'Module-relative files may not have absolute paths'

-## 2. Example & DocTest -###################################################################### -## - An "example" is a <source, want> pair, where "source" is a -## fragment of source code, and "want" is the expected output for -## "source." The Example class also includes information about -## where the example was extracted from. -## -## - A "doctest" is a collection of examples, typically extracted from -## a string (such as an object's docstring). The DocTest class also -## includes information about where the string was extracted from.

-class Example: - """ - A single doctest example, consisting of source code and expected - output. Example defines the following attributes:

-## 3. DocTestParser -######################################################################

-class DocTestParser: - """ - A class used to parse strings containing doctest examples. - """ - # This regular expression is used to find doctest examples in a - # string. It defines three groups: source is the source code - # (including leading indentation and prompts); indent is the - # indentation of the first (PS1) line of the source code; and - # want is the expected output (including leading indentation). - _EXAMPLE_RE = re.compile(r''' - # Source consists of a PS1 line followed by zero or more PS2 lines. - (?P - (?:^(?P [ ]) >>> .) # PS1 line - (?:\n [ ]* ... .)) # PS2 lines - \n? - # Want consists of any non-blank lines that do not start with PS1. - (?P (?:(?![ ]$) # Not a blank line - (?![ ]>>>) # Not a line starting with PS1 - .$\n? # But any other line - )) - ''', re.MULTILINE | re.VERBOSE)

-## 4. DocTest Finder -######################################################################

-class DocTestFinder: - """ - A class used to extract the DocTests that are relevant to a given - object, from its docstring and the docstrings of its contained - objects. Doctests can currently be extracted from the following - object types: modules, functions, classes, methods, staticmethods, - classmethods, and properties. - """

-## 5. DocTest Runner -######################################################################

-class DocTestRunner: - """ - A class used to run DocTest test cases, and accumulate statistics. - The run method is used to process a single DocTest case. It - returns a tuple (f, t), where t is the number of test cases - tried, and f is the number of test cases that failed.

-## 6. Test Functions -###################################################################### -# These should be backwards compatible.

-# For backward compatibility, a global instance of a DocTestRunner -# class, updated by testmod. -master = None

-def testmod(m=None, name=None, globs=None, verbose=None, isprivate=None, - report=True, optionflags=0, extraglobs=None, - raise_on_error=False, exclude_empty=False): - """m=None, name=None, globs=None, verbose=None, isprivate=None, - report=True, optionflags=0, extraglobs=None, raise_on_error=False, - exclude_empty=False

-## 7. Tester -###################################################################### -# This is provided only for backwards compatibility. It's not -# actually used in any way.

-class Tester: - def init(self, mod=None, globs=None, verbose=None, - isprivate=None, optionflags=0):

-## 8. Unittest Support -######################################################################

-_unittest_reportflags = 0

-def set_unittest_reportflags(flags): - """Sets the unittest option flags.

-## 9. Debugging Support -######################################################################

-def script_from_examples(s): - r"""Extract script from text with examples.

-## 10. Example Usage -###################################################################### -class _TestClass: - """ - A pointless class, for sanity-checking of docstring testing.



More information about the Python-checkins mailing list