diff options
| author | Tarek Ziade <tarek@ziade.org> | 2010-10-25 02:00:47 +0200 |
|---|---|---|
| committer | Tarek Ziade <tarek@ziade.org> | 2010-10-25 02:00:47 +0200 |
| commit | 3a2f924196e82ff2c2bdcff9188357c509c41320 (patch) | |
| tree | 515387487062dcf19b21d0cbe9408e130dee98ed | |
| parent | 5dbdebe52132f6dbfbf63919a20fa339624a0cb6 (diff) | |
| download | disutils2-3a2f924196e82ff2c2bdcff9188357c509c41320.tar.gz | |
removed core.py
36 files changed, 209 insertions, 358 deletions
diff --git a/distutils2/command/bdist.py b/distutils2/command/bdist.py index 1b7ce16..c7ffc7f 100644 --- a/distutils2/command/bdist.py +++ b/distutils2/command/bdist.py @@ -2,12 +2,10 @@ Implements the Distutils 'bdist' command (create a built [binary] distribution).""" - - import os from distutils2.util import get_platform -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.errors import DistutilsPlatformError, DistutilsOptionError diff --git a/distutils2/command/bdist_dumb.py b/distutils2/command/bdist_dumb.py index 25d0f4f..58ebdd9 100644 --- a/distutils2/command/bdist_dumb.py +++ b/distutils2/command/bdist_dumb.py @@ -12,7 +12,7 @@ try: except ImportError: from distutils2._backport.sysconfig import get_python_version from distutils2.util import get_platform -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.errors import DistutilsPlatformError from distutils2 import log diff --git a/distutils2/command/bdist_wininst.py b/distutils2/command/bdist_wininst.py index 67a514d..a6d6893 100644 --- a/distutils2/command/bdist_wininst.py +++ b/distutils2/command/bdist_wininst.py @@ -12,7 +12,7 @@ try: from sysconfig import get_python_version except ImportError: from distutils2._backport.sysconfig import get_python_version -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.errors import DistutilsOptionError, DistutilsPlatformError from distutils2 import log from distutils2.util import get_platform diff --git a/distutils2/command/build.py b/distutils2/command/build.py index 6336ac4..ed2ccdf 100644 --- a/distutils2/command/build.py +++ b/distutils2/command/build.py @@ -6,7 +6,7 @@ Implements the Distutils 'build' command.""" import sys, os from distutils2.util import get_platform -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.errors import DistutilsOptionError def show_compilers(): diff --git a/distutils2/command/build_clib.py b/distutils2/command/build_clib.py index 0c8701e..085d899 100644 --- a/distutils2/command/build_clib.py +++ b/distutils2/command/build_clib.py @@ -16,7 +16,7 @@ module.""" # cut 'n paste. Sigh. import os -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.errors import DistutilsSetupError from distutils2.compiler.ccompiler import customize_compiler from distutils2 import log diff --git a/distutils2/command/build_ext.py b/distutils2/command/build_ext.py index cb4f691..4bfc6d7 100644 --- a/distutils2/command/build_ext.py +++ b/distutils2/command/build_ext.py @@ -9,7 +9,7 @@ import sys, os, re from warnings import warn from distutils2.util import get_platform -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.errors import (CCompilerError, CompileError, DistutilsError, DistutilsPlatformError, DistutilsSetupError) from distutils2.compiler.ccompiler import customize_compiler diff --git a/distutils2/command/build_py.py b/distutils2/command/build_py.py index 92a8d9e..c24a13b 100644 --- a/distutils2/command/build_py.py +++ b/distutils2/command/build_py.py @@ -9,7 +9,7 @@ import logging from glob import glob import distutils2 -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.errors import DistutilsOptionError, DistutilsFileError from distutils2.util import convert_path from distutils2.compat import Mixin2to3 diff --git a/distutils2/command/build_scripts.py b/distutils2/command/build_scripts.py index b76d2b5..c89502d 100644 --- a/distutils2/command/build_scripts.py +++ b/distutils2/command/build_scripts.py @@ -5,7 +5,8 @@ Implements the Distutils 'build_scripts' command.""" import os, re from stat import ST_MODE -from distutils2.core import Command + +from distutils2.command.cmd import Command from distutils2.util import convert_path, newer from distutils2 import log try: diff --git a/distutils2/command/check.py b/distutils2/command/check.py index c661e6f..8bf55f1 100644 --- a/distutils2/command/check.py +++ b/distutils2/command/check.py @@ -3,7 +3,7 @@ Implements the Distutils 'check' command. """ -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.errors import DistutilsSetupError from distutils2.util import resolve_name diff --git a/distutils2/command/clean.py b/distutils2/command/clean.py index dc2ef0b..c3a1ba5 100644 --- a/distutils2/command/clean.py +++ b/distutils2/command/clean.py @@ -7,7 +7,7 @@ Implements the Distutils 'clean' command.""" import os from shutil import rmtree -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2 import log class clean(Command): diff --git a/distutils2/command/config.py b/distutils2/command/config.py index 5bea91e..e2ab7a2 100644 --- a/distutils2/command/config.py +++ b/distutils2/command/config.py @@ -13,7 +13,7 @@ this header file lives". import os import re -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.errors import DistutilsExecError from distutils2.compiler.ccompiler import customize_compiler from distutils2 import log diff --git a/distutils2/command/install_data.py b/distutils2/command/install_data.py index 910c80f..e77b11c 100644 --- a/distutils2/command/install_data.py +++ b/distutils2/command/install_data.py @@ -7,7 +7,7 @@ platform-independent data files.""" import os -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.util import change_root, convert_path class install_data(Command): diff --git a/distutils2/command/install_dist.py b/distutils2/command/install_dist.py index 12d160f..dcbd0b3 100644 --- a/distutils2/command/install_dist.py +++ b/distutils2/command/install_dist.py @@ -11,7 +11,7 @@ from distutils2._backport.sysconfig import (get_config_vars, get_paths, get_path, get_config_var) from distutils2 import log -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.errors import DistutilsPlatformError from distutils2.util import write_file from distutils2.util import convert_path, change_root, get_platform diff --git a/distutils2/command/install_headers.py b/distutils2/command/install_headers.py index a305203..86db07f 100644 --- a/distutils2/command/install_headers.py +++ b/distutils2/command/install_headers.py @@ -4,7 +4,7 @@ Implements the Distutils 'install_headers' command, to install C/C++ header files to the Python include directory.""" -from distutils2.core import Command +from distutils2.command.cmd import Command # XXX force is never used diff --git a/distutils2/command/install_lib.py b/distutils2/command/install_lib.py index d6fa1be..f9de095 100644 --- a/distutils2/command/install_lib.py +++ b/distutils2/command/install_lib.py @@ -7,7 +7,7 @@ Implements the Distutils 'install_lib' command import os import sys -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.errors import DistutilsOptionError diff --git a/distutils2/command/install_scripts.py b/distutils2/command/install_scripts.py index b5bb897..4228652 100644 --- a/distutils2/command/install_scripts.py +++ b/distutils2/command/install_scripts.py @@ -7,7 +7,7 @@ Python scripts.""" import os -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2 import log from stat import ST_MODE diff --git a/distutils2/command/sdist.py b/distutils2/command/sdist.py index 9d22a1d..14faa4e 100644 --- a/distutils2/command/sdist.py +++ b/distutils2/command/sdist.py @@ -15,7 +15,7 @@ try: except ImportError: from distutils2._backport.shutil import get_archive_formats -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.errors import (DistutilsPlatformError, DistutilsOptionError, DistutilsTemplateError) from distutils2.manifest import Manifest diff --git a/distutils2/command/test.py b/distutils2/command/test.py index d64ebd3..57c23bf 100644 --- a/distutils2/command/test.py +++ b/distutils2/command/test.py @@ -2,7 +2,7 @@ import os import sys import unittest -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.errors import DistutilsOptionError from distutils2.util import resolve_name diff --git a/distutils2/core.py b/distutils2/core.py deleted file mode 100644 index b11110e..0000000 --- a/distutils2/core.py +++ /dev/null @@ -1,219 +0,0 @@ -"""distutils2.core - -The only module that needs to be imported to use the Distutils; provides -the 'setup' function (which is to be called from the setup script). Also -exports useful classes so that setup scripts can import them from here -although they are really defined in other modules: Distribution, Command, -PyPIRCommand, Extension, find_packages. -""" - - -import sys -import os - -from distutils2.errors import (DistutilsSetupError, DistutilsArgError, - DistutilsError, CCompilerError) -from distutils2.util import grok_environment_error - -# Mainly import these so setup scripts can "from distutils2.core import" them. -from distutils2.dist import Distribution -from distutils2.command.cmd import Command -from distutils2.extension import Extension -from distutils2.util import find_packages - -# This is a barebones help message generated displayed when the user -# runs the setup script with no arguments at all. More useful help -# is generated with various --help options: global help, list commands, -# and per-command help. -USAGE = """\ -usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] - or: %(script)s --help [cmd1 cmd2 ...] - or: %(script)s --help-commands - or: %(script)s cmd --help -""" - - -def gen_usage(script_name): - script = os.path.basename(script_name) - return USAGE % {'script': script} - - -# Some mild magic to control the behaviour of 'setup()' from 'run_setup()'. -_setup_stop_after = None -_setup_distribution = None - -# Legal keyword arguments for the setup() function -setup_keywords = ('distclass', 'script_name', 'script_args', 'options', - 'name', 'version', 'author', 'author_email', - 'maintainer', 'maintainer_email', 'url', 'license', - 'description', 'long_description', 'keywords', - 'platforms', 'classifiers', 'download_url', - 'requires', 'provides', 'obsoletes', 'use_2to3_fixers', - 'convert_2to3_doctests', 'use_2to3_fixers' - ) - -# Legal keyword arguments for the Extension constructor -extension_keywords = ('name', 'sources', 'include_dirs', - 'define_macros', 'undef_macros', - 'library_dirs', 'libraries', 'runtime_library_dirs', - 'extra_objects', 'extra_compile_args', 'extra_link_args', - 'swig_opts', 'export_symbols', 'depends', 'language') - - -def setup(**attrs): - """The gateway to the Distutils: do everything your setup script needs - to do, in a highly flexible and user-driven way. Briefly: create a - Distribution instance; find and parse config files; parse the command - line; run each Distutils command found there, customized by the options - supplied to 'setup()' (as keyword arguments), in config files, and on - the command line. - - The Distribution instance might be an instance of a class supplied via - the 'distclass' keyword argument to 'setup'; if no such class is - supplied, then the Distribution class (in dist.py) is instantiated. - All other arguments to 'setup' (except for 'cmdclass') are used to set - attributes of the Distribution instance. - - The 'cmdclass' argument, if supplied, is a dictionary mapping command - names to command classes. Each command encountered on the command line - will be turned into a command class, which is in turn instantiated; any - class found in 'cmdclass' is used in place of the default, which is - (for command 'foo_bar') class 'foo_bar' in module - 'distutils2.command.foo_bar'. The command class must provide a - 'user_options' attribute which is a list of option specifiers for - 'distutils2.fancy_getopt'. Any command-line options between the current - and the next command are used to set attributes of the current command - object. - - When the entire command line has been successfully parsed, calls the - 'run()' method on each command object in turn. This method will be - driven entirely by the Distribution object (which each command object - has a reference to, thanks to its constructor), and the - command-specific options that became attributes of each command - object. - """ - - global _setup_stop_after, _setup_distribution - - # Determine the distribution class -- either caller-supplied or - # our Distribution (see below). - distclass = attrs.pop('distclass', Distribution) - - if 'script_name' not in attrs: - attrs['script_name'] = os.path.basename(sys.argv[0]) - if 'script_args' not in attrs: - attrs['script_args'] = sys.argv[1:] - - # Create the Distribution instance, using the remaining arguments - # (ie. everything except distclass) to initialize it - try: - _setup_distribution = dist = distclass(attrs) - except DistutilsSetupError, msg: - if 'name' in attrs: - raise SystemExit, "error in %s setup command: %s" % \ - (attrs['name'], msg) - else: - raise SystemExit, "error in setup command: %s" % msg - - if _setup_stop_after == "init": - return dist - - # Find and parse the config file(s): they will override options from - # the setup script, but be overridden by the command line. - dist.parse_config_files() - - if _setup_stop_after == "config": - return dist - - # Parse the command line and override config files; any - # command line errors are the end user's fault, so turn them into - # SystemExit to suppress tracebacks. - try: - ok = dist.parse_command_line() - except DistutilsArgError, msg: - raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg - - if _setup_stop_after == "commandline": - return dist - - # And finally, run all the commands found on the command line. - if ok: - try: - dist.run_commands() - except KeyboardInterrupt: - raise SystemExit, "interrupted" - except (IOError, os.error), exc: - error = grok_environment_error(exc) - raise SystemExit, error - - except (DistutilsError, - CCompilerError), msg: - raise SystemExit, "error: " + str(msg) - - return dist - - -def run_setup(script_name, script_args=None, stop_after="run"): - """Run a setup script in a somewhat controlled environment, and - return the Distribution instance that drives things. This is useful - if you need to find out the distribution metadata (passed as - keyword args from 'script' to 'setup()', or the contents of the - config files or command line. - - 'script_name' is a file that will be run with 'execfile()'; - 'sys.argv[0]' will be replaced with 'script' for the duration of the - call. 'script_args' is a list of strings; if supplied, - 'sys.argv[1:]' will be replaced by 'script_args' for the duration of - the call. - - 'stop_after' tells 'setup()' when to stop processing; possible - values: - init - stop after the Distribution instance has been created and - populated with the keyword arguments to 'setup()' - config - stop after config files have been parsed (and their data - stored in the Distribution instance) - commandline - stop after the command line ('sys.argv[1:]' or 'script_args') - has been parsed (and the data stored in the Distribution) - run [default] - stop after all commands have been run (the same as if 'setup()' - had been called in the usual way - - Returns the Distribution instance, which provides all information - used to drive the Distutils. - """ - if stop_after not in ('init', 'config', 'commandline', 'run'): - raise ValueError, "invalid value for 'stop_after': %r" % (stop_after,) - - global _setup_stop_after, _setup_distribution - _setup_stop_after = stop_after - - save_argv = sys.argv - g = {'__file__': script_name} - l = {} - try: - try: - if script_args is not None: - sys.argv = [script_name] + script_args - else: - sys.argv = [script_name] - exec open(script_name, 'r').read() in g, l - finally: - sys.argv = save_argv - _setup_stop_after = None - except SystemExit: - # Hmm, should we do something if exiting with a non-zero code - # (ie. error)? - pass - - if _setup_distribution is None: - raise RuntimeError, \ - ("'distutils2.core.setup()' was never called -- " - "perhaps '%s' is not a Distutils setup script?") % \ - script_name - - # I wonder if the setup script's namespace -- g and l -- would be of - # any interest to callers? - return _setup_distribution diff --git a/distutils2/dist.py b/distutils2/dist.py index 8ea23cb..9f46a58 100644 --- a/distutils2/dist.py +++ b/distutils2/dist.py @@ -36,7 +36,7 @@ class Distribution(object): Distribution for some specialized purpose, and then pass the subclass to 'setup()' as the 'distclass' keyword argument. If so, it is necessary to respect the expectations that 'setup' has of Distribution. - See the code for 'setup()', in core.py, for details. + See the code for 'setup()', in run.py, for details. """ # 'global_options' describes the command-line options that may be @@ -322,7 +322,7 @@ Common commands: (see '--help-commands' for more) def parse_command_line(self): """Parse the setup script's command line, taken from the 'script_args' instance attribute (which defaults to 'sys.argv[1:]' - -- see 'setup()' in core.py). This list is first processed for + -- see 'setup()' in run.py). This list is first processed for "global options" -- options that set attributes of the Distribution instance. Then, it is alternately scanned for Distutils commands and options for that command. Each new command terminates the @@ -517,7 +517,7 @@ Common commands: (see '--help-commands' for more) in 'commands'. """ # late import because of mutual dependence between these modules - from distutils2.core import gen_usage + from distutils2.run import gen_usage from distutils2.command.cmd import Command if global_options: @@ -558,7 +558,7 @@ Common commands: (see '--help-commands' for more) line, display the requested info and return true; else return false. """ - from distutils2.core import gen_usage + from distutils2.run import gen_usage # User just wants a list of commands -- we'll print it out and stop # processing now (ie. if they ran "setup --help-commands foo bar", diff --git a/distutils2/run.py b/distutils2/run.py index af3ab60..cb51dc5 100644 --- a/distutils2/run.py +++ b/distutils2/run.py @@ -1,4 +1,109 @@ -from distutils2.core import setup +import os +import sys + +from distutils2.util import grok_environment_error +from distutils2.errors import (DistutilsSetupError, DistutilsArgError, + DistutilsError, CCompilerError) +from distutils2.dist import Distribution + +# This is a barebones help message generated displayed when the user +# runs the setup script with no arguments at all. More useful help +# is generated with various --help options: global help, list commands, +# and per-command help. +USAGE = """\ +usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] + or: %(script)s --help [cmd1 cmd2 ...] + or: %(script)s --help-commands + or: %(script)s cmd --help +""" + + +def gen_usage(script_name): + script = os.path.basename(script_name) + return USAGE % {'script': script} + + +def main(**attrs): + """The gateway to the Distutils: do everything your setup script needs + to do, in a highly flexible and user-driven way. Briefly: create a + Distribution instance; find and parse config files; parse the command + line; run each Distutils command found there, customized by the options + supplied to 'setup()' (as keyword arguments), in config files, and on + the command line. + + The Distribution instance might be an instance of a class supplied via + the 'distclass' keyword argument to 'setup'; if no such class is + supplied, then the Distribution class (in dist.py) is instantiated. + All other arguments to 'setup' (except for 'cmdclass') are used to set + attributes of the Distribution instance. + + The 'cmdclass' argument, if supplied, is a dictionary mapping command + names to command classes. Each command encountered on the command line + will be turned into a command class, which is in turn instantiated; any + class found in 'cmdclass' is used in place of the default, which is + (for command 'foo_bar') class 'foo_bar' in module + 'distutils2.command.foo_bar'. The command class must provide a + 'user_options' attribute which is a list of option specifiers for + 'distutils2.fancy_getopt'. Any command-line options between the current + and the next command are used to set attributes of the current command + object. + + When the entire command line has been successfully parsed, calls the + 'run()' method on each command object in turn. This method will be + driven entirely by the Distribution object (which each command object + has a reference to, thanks to its constructor), and the + command-specific options that became attributes of each command + object. + """ + # Determine the distribution class -- either caller-supplied or + # our Distribution (see below). + distclass = attrs.pop('distclass', Distribution) + + if 'script_name' not in attrs: + attrs['script_name'] = os.path.basename(sys.argv[0]) + + if 'script_args' not in attrs: + attrs['script_args'] = sys.argv[1:] + + # Create the Distribution instance, using the remaining arguments + # (ie. everything except distclass) to initialize it + try: + dist = distclass(attrs) + except DistutilsSetupError, msg: + if 'name' in attrs: + raise SystemExit, "error in %s setup command: %s" % \ + (attrs['name'], msg) + else: + raise SystemExit, "error in setup command: %s" % msg + + # Find and parse the config file(s): they will override options from + # the setup script, but be overridden by the command line. + dist.parse_config_files() + + # Parse the command line and override config files; any + # command line errors are the end user's fault, so turn them into + # SystemExit to suppress tracebacks. + try: + res = dist.parse_command_line() + except DistutilsArgError, msg: + raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg + + # And finally, run all the commands found on the command line. + if res: + try: + dist.run_commands() + except KeyboardInterrupt: + raise SystemExit, "interrupted" + except (IOError, os.error), exc: + error = grok_environment_error(exc) + raise SystemExit, error + + except (DistutilsError, + CCompilerError), msg: + raise SystemExit, "error: " + str(msg) + + return dist + if __name__ == '__main__': - setup() + main() diff --git a/distutils2/tests/test_command_bdist_dumb.py b/distutils2/tests/test_command_bdist_dumb.py index ffe98b9..15559fc 100644 --- a/distutils2/tests/test_command_bdist_dumb.py +++ b/distutils2/tests/test_command_bdist_dumb.py @@ -12,12 +12,12 @@ except ImportError: from distutils2.tests import run_unittest, unittest -from distutils2.core import Distribution +from distutils2.dist import Distribution from distutils2.command.bdist_dumb import bdist_dumb from distutils2.tests import support SETUP_PY = """\ -from distutils.core import setup +from distutils.run import setup import foo setup(name='foo', version='0.1', py_modules=['foo'], diff --git a/distutils2/tests/test_command_build_ext.py b/distutils2/tests/test_command_build_ext.py index 8eb4106..f7e8b40 100644 --- a/distutils2/tests/test_command_build_ext.py +++ b/distutils2/tests/test_command_build_ext.py @@ -5,7 +5,8 @@ from StringIO import StringIO import distutils2.tests from distutils2.tests import unittest -from distutils2.core import Extension, Distribution +from distutils2.extension import Extension +from distutils2.dist import Distribution from distutils2.command.build_ext import build_ext from distutils2.tests import support from distutils2.extension import Extension diff --git a/distutils2/tests/test_command_build_py.py b/distutils2/tests/test_command_build_py.py index f3e330e..eefdc69 100644 --- a/distutils2/tests/test_command_build_py.py +++ b/distutils2/tests/test_command_build_py.py @@ -5,7 +5,7 @@ import sys import StringIO from distutils2.command.build_py import build_py -from distutils2.core import Distribution +from distutils2.dist import Distribution from distutils2.errors import DistutilsFileError from distutils2.tests import unittest, support diff --git a/distutils2/tests/test_command_build_scripts.py b/distutils2/tests/test_command_build_scripts.py index e7624cd..fd5ca49 100644 --- a/distutils2/tests/test_command_build_scripts.py +++ b/distutils2/tests/test_command_build_scripts.py @@ -3,7 +3,7 @@ import os from distutils2.command.build_scripts import build_scripts -from distutils2.core import Distribution +from distutils2.dist import Distribution try: import sysconfig except ImportError: diff --git a/distutils2/tests/test_command_install_dist.py b/distutils2/tests/test_command_install_dist.py index 55046bb..001ebae 100644 --- a/distutils2/tests/test_command_install_dist.py +++ b/distutils2/tests/test_command_install_dist.py @@ -14,7 +14,7 @@ from distutils2.tests import captured_stdout from distutils2.command.install_dist import install_dist from distutils2.command import install_dist as install_module -from distutils2.core import Distribution +from distutils2.dist import Distribution from distutils2.errors import DistutilsOptionError from distutils2.tests import unittest, support diff --git a/distutils2/tests/test_command_install_distinfo.py b/distutils2/tests/test_command_install_distinfo.py index 3732f31..48f6ee5 100644 --- a/distutils2/tests/test_command_install_distinfo.py +++ b/distutils2/tests/test_command_install_distinfo.py @@ -5,7 +5,7 @@ import sys import csv from distutils2.command.install_distinfo import install_distinfo -from distutils2.core import Command +from distutils2.command.cmd import Command from distutils2.metadata import DistributionMetadata from distutils2.tests import unittest, support diff --git a/distutils2/tests/test_command_install_scripts.py b/distutils2/tests/test_command_install_scripts.py index e04b3f5..30318d5 100644 --- a/distutils2/tests/test_command_install_scripts.py +++ b/distutils2/tests/test_command_install_scripts.py @@ -3,7 +3,7 @@ import os from distutils2.command.install_scripts import install_scripts -from distutils2.core import Distribution +from distutils2.dist import Distribution from distutils2.tests import unittest, support diff --git a/distutils2/tests/test_command_register.py b/distutils2/tests/test_command_register.py index 3113e80..b1ce79e 100644 --- a/distutils2/tests/test_command_register.py +++ b/distutils2/tests/test_command_register.py @@ -13,7 +13,7 @@ except ImportError: from distutils2.command import register as register_module from distutils2.command.register import register -from distutils2.core import Distribution +from distutils2.dist import Distribution from distutils2.errors import DistutilsSetupError from distutils2.tests import unittest, support diff --git a/distutils2/tests/test_command_sdist.py b/distutils2/tests/test_command_sdist.py index 848d6c9..eedbc02 100644 --- a/distutils2/tests/test_command_sdist.py +++ b/distutils2/tests/test_command_sdist.py @@ -25,7 +25,7 @@ from distutils2.tests import captured_stdout from distutils2.command.sdist import sdist from distutils2.command.sdist import show_formats -from distutils2.core import Distribution +from distutils2.dist import Distribution from distutils2.tests import unittest from distutils2.errors import DistutilsExecError, DistutilsOptionError from distutils2.util import find_executable diff --git a/distutils2/tests/test_command_upload.py b/distutils2/tests/test_command_upload.py index df8ae91..48e7e7b 100644 --- a/distutils2/tests/test_command_upload.py +++ b/distutils2/tests/test_command_upload.py @@ -4,7 +4,7 @@ import os import sys from distutils2.command.upload import upload -from distutils2.core import Distribution +from distutils2.dist import Distribution from distutils2.tests import unittest, support from distutils2.tests.pypi_server import PyPIServer, PyPIServerTestCase @@ -128,7 +128,7 @@ class UploadTestCase(support.TempdirManager, support.EnvironGuard, handler, request_data = self.pypi.requests[-1] action, name, content =\ request_data.split("----------------GHSKFJDLGDS7543FJKLFHRE75642756743254")[1:4] - + self.assertIn('name=":action"', action) self.assertIn("doc_upload", action) diff --git a/distutils2/tests/test_command_upload_docs.py b/distutils2/tests/test_command_upload_docs.py index c9c4b91..8135e24 100644 --- a/distutils2/tests/test_command_upload_docs.py +++ b/distutils2/tests/test_command_upload_docs.py @@ -13,7 +13,7 @@ except ImportError: from distutils2.command import upload_docs as upload_docs_mod from distutils2.command.upload_docs import (upload_docs, zip_dir, encode_multipart) -from distutils2.core import Distribution +from distutils2.dist import Distribution from distutils2.errors import DistutilsFileError, DistutilsOptionError from distutils2.tests import unittest, support diff --git a/distutils2/tests/test_config.py b/distutils2/tests/test_config.py index 60b1c71..9ec6860 100644 --- a/distutils2/tests/test_config.py +++ b/distutils2/tests/test_config.py @@ -109,8 +109,8 @@ class ConfigTestCase(support.TempdirManager, sys.argv[:] = ['setup.py', '--version'] old_sys = sys.argv[:] try: - from distutils2.core import setup - dist = setup() + from distutils2.run import main + dist = main() finally: sys.argv[:] = old_sys diff --git a/distutils2/tests/test_core.py b/distutils2/tests/test_core.py deleted file mode 100644 index 11c5561..0000000 --- a/distutils2/tests/test_core.py +++ /dev/null @@ -1,97 +0,0 @@ -"""Tests for distutils2.core.""" - -import StringIO -import distutils2.core -import os -import shutil -import sys -from distutils2.tests import captured_stdout -from distutils2.tests import unittest, support - -# setup script that uses __file__ -setup_using___file__ = """\ - -__file__ - -from distutils2.core import setup -setup() -""" - -setup_prints_cwd = """\ - -import os -print os.getcwd() - -from distutils2.core import setup -setup() -""" - - -class CoreTestCase(support.EnvironGuard, unittest.TestCase): - - def setUp(self): - super(CoreTestCase, self).setUp() - self.old_stdout = sys.stdout - self.cleanup_testfn() - self.old_argv = sys.argv, sys.argv[:] - - def tearDown(self): - sys.stdout = self.old_stdout - self.cleanup_testfn() - sys.argv = self.old_argv[0] - sys.argv[:] = self.old_argv[1] - super(CoreTestCase, self).tearDown() - - def cleanup_testfn(self): - path = distutils2.tests.TESTFN - if os.path.isfile(path): - os.remove(path) - elif os.path.isdir(path): - shutil.rmtree(path) - - def write_setup(self, text, path=distutils2.tests.TESTFN): - open(path, "w").write(text) - return path - - def test_run_setup_provides_file(self): - # Make sure the script can use __file__; if that's missing, the test - # setup.py script will raise NameError. - distutils2.core.run_setup( - self.write_setup(setup_using___file__)) - - def test_run_setup_stop_after(self): - f = self.write_setup(setup_using___file__) - for s in ['init', 'config', 'commandline', 'run']: - distutils2.core.run_setup(f, stop_after=s) - self.assertRaises(ValueError, distutils2.core.run_setup, - f, stop_after='bob') - - def test_run_setup_args(self): - f = self.write_setup(setup_using___file__) - d = distutils2.core.run_setup(f, script_args=["--help"], - stop_after="init") - self.assertEqual(['--help'], d.script_args) - - def test_run_setup_uses_current_dir(self): - # This tests that the setup script is run with the current directory - # as its own current directory; this was temporarily broken by a - # previous patch when TESTFN did not use the current directory. - sys.stdout = StringIO.StringIO() - cwd = os.getcwd() - - # Create a directory and write the setup.py file there: - os.mkdir(distutils2.tests.TESTFN) - setup_py = os.path.join(distutils2.tests.TESTFN, "setup.py") - distutils2.core.run_setup( - self.write_setup(setup_prints_cwd, path=setup_py)) - - output = sys.stdout.getvalue() - if output.endswith("\n"): - output = output[:-1] - self.assertEqual(cwd, output) - -def test_suite(): - return unittest.makeSuite(CoreTestCase) - -if __name__ == "__main__": - unittest.main(defaultTest="test_suite") diff --git a/distutils2/tests/test_run.py b/distutils2/tests/test_run.py new file mode 100644 index 0000000..e66c7f4 --- /dev/null +++ b/distutils2/tests/test_run.py @@ -0,0 +1,61 @@ +"""Tests for distutils2.run.""" + +import StringIO +import os +import shutil +import sys + +import distutils2 +from distutils2.tests import captured_stdout +from distutils2.tests import unittest, support + +# setup script that uses __file__ +setup_using___file__ = """\ + +__file__ + +from distutils2.run import setup +setup() +""" + +setup_prints_cwd = """\ + +import os +print os.getcwd() + +from distutils2.run import setup +setup() +""" + + +class CoreTestCase(support.EnvironGuard, unittest.TestCase): + + def setUp(self): + super(CoreTestCase, self).setUp() + self.old_stdout = sys.stdout + self.cleanup_testfn() + self.old_argv = sys.argv, sys.argv[:] + + def tearDown(self): + sys.stdout = self.old_stdout + self.cleanup_testfn() + sys.argv = self.old_argv[0] + sys.argv[:] = self.old_argv[1] + super(CoreTestCase, self).tearDown() + + def cleanup_testfn(self): + path = distutils2.tests.TESTFN + if os.path.isfile(path): + os.remove(path) + elif os.path.isdir(path): + shutil.rmtree(path) + + def write_setup(self, text, path=distutils2.tests.TESTFN): + open(path, "w").write(text) + return path + +def test_suite(): + return unittest.makeSuite(CoreTestCase) + +if __name__ == "__main__": + unittest.main(defaultTest="test_suite") diff --git a/distutils2/tests/test_test.py b/distutils2/tests/test_test.py index 5e4c03f..9b0c950 100644 --- a/distutils2/tests/test_test.py +++ b/distutils2/tests/test_test.py @@ -8,7 +8,8 @@ from copy import copy from os.path import join from operator import getitem, setitem, delitem from StringIO import StringIO -from distutils2.core import Command + +from distutils2.command.cmd import Command from distutils2.tests import unittest from distutils2.tests.support import TempdirManager, LoggingCatcher from distutils2.command.test import test |
