summaryrefslogtreecommitdiff
path: root/setuptools/_distutils/core.py
diff options
context:
space:
mode:
Diffstat (limited to 'setuptools/_distutils/core.py')
-rw-r--r--setuptools/_distutils/core.py114
1 files changed, 78 insertions, 36 deletions
diff --git a/setuptools/_distutils/core.py b/setuptools/_distutils/core.py
index f43888ea..34cafbce 100644
--- a/setuptools/_distutils/core.py
+++ b/setuptools/_distutils/core.py
@@ -10,14 +10,22 @@ import os
import sys
import tokenize
-from distutils.debug import DEBUG
-from distutils.errors import *
+from .debug import DEBUG
+from .errors import (
+ DistutilsSetupError,
+ DistutilsError,
+ CCompilerError,
+ DistutilsArgError,
+)
# Mainly import these so setup scripts can "from distutils.core import" them.
-from distutils.dist import Distribution
-from distutils.cmd import Command
-from distutils.config import PyPIRCCommand
-from distutils.extension import Extension
+from .dist import Distribution
+from .cmd import Command
+from .config import PyPIRCCommand
+from .extension import Extension
+
+
+__all__ = ['Distribution', 'Command', 'PyPIRCCommand', 'Extension', 'setup']
# This is a barebones help message generated displayed when the user
# runs the setup script with no arguments at all. More useful help
@@ -30,9 +38,10 @@ usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: %(script)s cmd --help
"""
-def gen_usage (script_name):
+
+def gen_usage(script_name):
script = os.path.basename(script_name)
- return USAGE % vars()
+ return USAGE % locals()
# Some mild magic to control the behaviour of 'setup()' from 'run_setup()'.
@@ -40,22 +49,51 @@ _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',
- )
+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',
+)
# 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):
+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): # noqa: C901
"""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
@@ -100,7 +138,7 @@ def setup (**attrs):
if 'script_name' not in attrs:
attrs['script_name'] = os.path.basename(sys.argv[0])
- if 'script_args' not in attrs:
+ if 'script_args' not in attrs:
attrs['script_args'] = sys.argv[1:]
# Create the Distribution instance, using the remaining arguments
@@ -111,8 +149,7 @@ def setup (**attrs):
if 'name' not in attrs:
raise SystemExit("error in setup command: %s" % msg)
else:
- raise SystemExit("error in %s setup command: %s" % \
- (attrs['name'], msg))
+ raise SystemExit("error in {} setup command: {}".format(attrs['name'], msg))
if _setup_stop_after == "init":
return dist
@@ -149,10 +186,11 @@ def setup (**attrs):
return dist
+
# setup ()
-def run_commands (dist):
+def run_commands(dist):
"""Given a Distribution object run all the commands,
raising ``SystemExit`` errors in the case of failure.
@@ -165,13 +203,12 @@ def run_commands (dist):
raise SystemExit("interrupted")
except OSError as exc:
if DEBUG:
- sys.stderr.write("error: %s\n" % (exc,))
+ sys.stderr.write("error: {}\n".format(exc))
raise
else:
- raise SystemExit("error: %s" % (exc,))
+ raise SystemExit("error: {}".format(exc))
- except (DistutilsError,
- CCompilerError) as msg:
+ except (DistutilsError, CCompilerError) as msg:
if DEBUG:
raise
else:
@@ -180,7 +217,7 @@ def run_commands (dist):
return dist
-def run_setup (script_name, script_args=None, stop_after="run"):
+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 meta-data (passed as
@@ -212,7 +249,7 @@ def run_setup (script_name, script_args=None, stop_after="run"):
used to drive the Distutils.
"""
if stop_after not in ('init', 'config', 'commandline', 'run'):
- raise ValueError("invalid value for 'stop_after': %r" % (stop_after,))
+ raise ValueError("invalid value for 'stop_after': {!r}".format(stop_after))
global _setup_stop_after, _setup_distribution
_setup_stop_after = stop_after
@@ -237,13 +274,18 @@ def run_setup (script_name, script_args=None, stop_after="run"):
pass
if _setup_distribution is None:
- raise RuntimeError(("'distutils.core.setup()' was never called -- "
- "perhaps '%s' is not a Distutils setup script?") % \
- script_name)
+ raise RuntimeError(
+ (
+ "'distutils.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?
- #print "_setup_distribution:", _setup_distribution
+ # print "_setup_distribution:", _setup_distribution
return _setup_distribution
+
# run_setup ()