mirror of
https://github.com/python/cpython.git
synced 2025-08-02 08:02:56 +00:00
Let all pysetup actions return a meaningful 0 or 1 exit code (#12222).
This will help scripts calling pysetup know if a command failed. Printing/logging was also made more consistent, and a few things were cleaned up. In particular, the error/Ctrl-C handling was moved from the _run function up to the main function. The run action is not fixed yet; it returns the dist.Distribution instance, which is needed by test_uninstall and not trivial to fix.
This commit is contained in:
parent
73c175f5a0
commit
943006bf68
1 changed files with 34 additions and 32 deletions
|
@ -214,7 +214,7 @@ def _create(distpatcher, args, **kw):
|
||||||
@action_help(generate_usage)
|
@action_help(generate_usage)
|
||||||
def _generate(distpatcher, args, **kw):
|
def _generate(distpatcher, args, **kw):
|
||||||
generate_setup_py()
|
generate_setup_py()
|
||||||
print('The setup.py was generated')
|
logger.info('The setup.py was generated')
|
||||||
|
|
||||||
|
|
||||||
@action_help(graph_usage)
|
@action_help(graph_usage)
|
||||||
|
@ -222,7 +222,8 @@ def _graph(dispatcher, args, **kw):
|
||||||
name = args[1]
|
name = args[1]
|
||||||
dist = get_distribution(name, use_egg_info=True)
|
dist = get_distribution(name, use_egg_info=True)
|
||||||
if dist is None:
|
if dist is None:
|
||||||
print('Distribution not found.')
|
logger.warning('Distribution not found.')
|
||||||
|
return 1
|
||||||
else:
|
else:
|
||||||
dists = get_distributions(use_egg_info=True)
|
dists = get_distributions(use_egg_info=True)
|
||||||
graph = generate_graph(dists)
|
graph = generate_graph(dists)
|
||||||
|
@ -234,8 +235,7 @@ def _install(dispatcher, args, **kw):
|
||||||
# first check if we are in a source directory
|
# first check if we are in a source directory
|
||||||
if len(args) < 2:
|
if len(args) < 2:
|
||||||
# are we inside a project dir?
|
# are we inside a project dir?
|
||||||
listing = os.listdir(os.getcwd())
|
if os.path.isfile('setup.cfg') or os.path.isfile('setup.py'):
|
||||||
if 'setup.py' in listing or 'setup.cfg' in listing:
|
|
||||||
args.insert(1, os.getcwd())
|
args.insert(1, os.getcwd())
|
||||||
else:
|
else:
|
||||||
logger.warning('No project to install.')
|
logger.warning('No project to install.')
|
||||||
|
@ -244,16 +244,10 @@ def _install(dispatcher, args, **kw):
|
||||||
target = args[1]
|
target = args[1]
|
||||||
# installing from a source dir or archive file?
|
# installing from a source dir or archive file?
|
||||||
if os.path.isdir(target) or _is_archive_file(target):
|
if os.path.isdir(target) or _is_archive_file(target):
|
||||||
if install_local_project(target):
|
return not install_local_project(target)
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
return 1
|
|
||||||
else:
|
else:
|
||||||
# download from PyPI
|
# download from PyPI
|
||||||
if install(target):
|
return not install(target)
|
||||||
return 0
|
|
||||||
else:
|
|
||||||
return 1
|
|
||||||
|
|
||||||
|
|
||||||
@action_help(metadata_usage)
|
@action_help(metadata_usage)
|
||||||
|
@ -263,12 +257,15 @@ def _metadata(dispatcher, args, **kw):
|
||||||
name = opts['args'][0]
|
name = opts['args'][0]
|
||||||
dist = get_distribution(name, use_egg_info=True)
|
dist = get_distribution(name, use_egg_info=True)
|
||||||
if dist is None:
|
if dist is None:
|
||||||
logger.warning('%s not installed', name)
|
logger.warning('%r not installed', name)
|
||||||
return
|
return 1
|
||||||
else:
|
elif os.path.isfile('setup.cfg'):
|
||||||
logger.info('searching local dir for metadata')
|
logger.info('searching local dir for metadata')
|
||||||
dist = Distribution()
|
dist = Distribution() # XXX use config module
|
||||||
dist.parse_config_files()
|
dist.parse_config_files()
|
||||||
|
else:
|
||||||
|
logger.warning('no argument given and no local setup.cfg found')
|
||||||
|
return 1
|
||||||
|
|
||||||
metadata = dist.metadata
|
metadata = dist.metadata
|
||||||
|
|
||||||
|
@ -299,11 +296,15 @@ def _remove(distpatcher, args, **kw):
|
||||||
else:
|
else:
|
||||||
auto_confirm = False
|
auto_confirm = False
|
||||||
|
|
||||||
|
retcode = 0
|
||||||
for dist in set(opts['args']):
|
for dist in set(opts['args']):
|
||||||
try:
|
try:
|
||||||
remove(dist, auto_confirm=auto_confirm)
|
remove(dist, auto_confirm=auto_confirm)
|
||||||
except PackagingError:
|
except PackagingError:
|
||||||
logger.warning('%s not installed', dist)
|
logger.warning('%r not installed', dist)
|
||||||
|
retcode = 1
|
||||||
|
|
||||||
|
return retcode
|
||||||
|
|
||||||
|
|
||||||
@action_help(run_usage)
|
@action_help(run_usage)
|
||||||
|
@ -339,14 +340,8 @@ def _run(dispatcher, args, **kw):
|
||||||
# XXX still need to be extracted from Distribution
|
# XXX still need to be extracted from Distribution
|
||||||
dist.parse_config_files()
|
dist.parse_config_files()
|
||||||
|
|
||||||
try:
|
for cmd in dispatcher.commands:
|
||||||
for cmd in dispatcher.commands:
|
dist.run_command(cmd, dispatcher.command_options[cmd])
|
||||||
dist.run_command(cmd, dispatcher.command_options[cmd])
|
|
||||||
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
raise SystemExit("interrupted")
|
|
||||||
except (IOError, os.error, PackagingError, CCompilerError) as msg:
|
|
||||||
raise SystemExit("error: " + str(msg))
|
|
||||||
|
|
||||||
# XXX this is crappy
|
# XXX this is crappy
|
||||||
return dist
|
return dist
|
||||||
|
@ -360,23 +355,22 @@ def _list(dispatcher, args, **kw):
|
||||||
results = dists
|
results = dists
|
||||||
listall = True
|
listall = True
|
||||||
else:
|
else:
|
||||||
results = [d for d in dists if d.name.lower() in opts['args']]
|
results = (d for d in dists if d.name.lower() in opts['args'])
|
||||||
listall = False
|
listall = False
|
||||||
|
|
||||||
number = 0
|
number = 0
|
||||||
for dist in results:
|
for dist in results:
|
||||||
print('%s %s at %s' % (dist.name, dist.metadata['version'], dist.path))
|
print('%r %s (from %r)' % (dist.name, dist.version, dist.path))
|
||||||
number += 1
|
number += 1
|
||||||
|
|
||||||
print()
|
|
||||||
if number == 0:
|
if number == 0:
|
||||||
if listall:
|
if listall:
|
||||||
print('Nothing seems to be installed.')
|
logger.info('Nothing seems to be installed.')
|
||||||
else:
|
else:
|
||||||
print('No matching distribution found.')
|
logger.warning('No matching distribution found.')
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
print('Found %d projects installed.' % number)
|
logger.info('Found %d projects installed.', number)
|
||||||
|
|
||||||
|
|
||||||
@action_help(search_usage)
|
@action_help(search_usage)
|
||||||
|
@ -388,7 +382,8 @@ def _search(dispatcher, args, **kw):
|
||||||
"""
|
"""
|
||||||
#opts = _parse_args(args[1:], '', ['simple', 'xmlrpc'])
|
#opts = _parse_args(args[1:], '', ['simple', 'xmlrpc'])
|
||||||
# 1. what kind of index is requested ? (xmlrpc / simple)
|
# 1. what kind of index is requested ? (xmlrpc / simple)
|
||||||
raise NotImplementedError
|
logger.error('not implemented')
|
||||||
|
return 1
|
||||||
|
|
||||||
|
|
||||||
actions = [
|
actions = [
|
||||||
|
@ -668,6 +663,7 @@ class Dispatcher:
|
||||||
def __call__(self):
|
def __call__(self):
|
||||||
if self.action is None:
|
if self.action is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
for action, desc, func in actions:
|
for action, desc, func in actions:
|
||||||
if action == self.action:
|
if action == self.action:
|
||||||
return func(self, self.args)
|
return func(self, self.args)
|
||||||
|
@ -682,6 +678,12 @@ def main(args=None):
|
||||||
if dispatcher.action is None:
|
if dispatcher.action is None:
|
||||||
return
|
return
|
||||||
return dispatcher()
|
return dispatcher()
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
logger.info('interrupted')
|
||||||
|
return 1
|
||||||
|
except (IOError, os.error, PackagingError, CCompilerError) as exc:
|
||||||
|
logger.exception(exc)
|
||||||
|
return 1
|
||||||
finally:
|
finally:
|
||||||
logger.setLevel(old_level)
|
logger.setLevel(old_level)
|
||||||
logger.handlers[:] = old_handlers
|
logger.handlers[:] = old_handlers
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue