mirror of
https://github.com/python/cpython.git
synced 2025-12-04 08:34:25 +00:00
Group commands by topic in “pysetup run --list-commands” output.
This fixes a regression from distutils, where “setup.py --help-commands” prints out commands grouped by topic (i.e. building vs. installing), which is more useful than using sorted.
This commit is contained in:
parent
1aa54a417d
commit
5c69b66086
3 changed files with 39 additions and 35 deletions
|
|
@ -6,38 +6,28 @@ from packaging.util import resolve_name
|
||||||
__all__ = ['get_command_names', 'set_command', 'get_command_class',
|
__all__ = ['get_command_names', 'set_command', 'get_command_class',
|
||||||
'STANDARD_COMMANDS']
|
'STANDARD_COMMANDS']
|
||||||
|
|
||||||
_COMMANDS = {
|
|
||||||
'check': 'packaging.command.check.check',
|
|
||||||
'test': 'packaging.command.test.test',
|
|
||||||
'build': 'packaging.command.build.build',
|
|
||||||
'build_py': 'packaging.command.build_py.build_py',
|
|
||||||
'build_ext': 'packaging.command.build_ext.build_ext',
|
|
||||||
'build_clib': 'packaging.command.build_clib.build_clib',
|
|
||||||
'build_scripts': 'packaging.command.build_scripts.build_scripts',
|
|
||||||
'clean': 'packaging.command.clean.clean',
|
|
||||||
'install_dist': 'packaging.command.install_dist.install_dist',
|
|
||||||
'install_lib': 'packaging.command.install_lib.install_lib',
|
|
||||||
'install_headers': 'packaging.command.install_headers.install_headers',
|
|
||||||
'install_scripts': 'packaging.command.install_scripts.install_scripts',
|
|
||||||
'install_data': 'packaging.command.install_data.install_data',
|
|
||||||
'install_distinfo':
|
|
||||||
'packaging.command.install_distinfo.install_distinfo',
|
|
||||||
'sdist': 'packaging.command.sdist.sdist',
|
|
||||||
'bdist': 'packaging.command.bdist.bdist',
|
|
||||||
'bdist_dumb': 'packaging.command.bdist_dumb.bdist_dumb',
|
|
||||||
'bdist_wininst': 'packaging.command.bdist_wininst.bdist_wininst',
|
|
||||||
'register': 'packaging.command.register.register',
|
|
||||||
'upload': 'packaging.command.upload.upload',
|
|
||||||
'upload_docs': 'packaging.command.upload_docs.upload_docs',
|
|
||||||
}
|
|
||||||
|
|
||||||
# XXX this is crappy
|
STANDARD_COMMANDS = [
|
||||||
|
# packaging
|
||||||
|
'check', 'test',
|
||||||
|
# building
|
||||||
|
'build', 'build_py', 'build_ext', 'build_clib', 'build_scripts', 'clean',
|
||||||
|
# installing
|
||||||
|
'install_dist', 'install_lib', 'install_headers', 'install_scripts',
|
||||||
|
'install_data', 'install_distinfo',
|
||||||
|
# distributing
|
||||||
|
'sdist', 'bdist', 'bdist_dumb', 'bdist_wininst',
|
||||||
|
'register', 'upload', 'upload_docs',
|
||||||
|
]
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
_COMMANDS['bdist_msi'] = 'packaging.command.bdist_msi.bdist_msi'
|
STANDARD_COMMANDS.insert(STANDARD_COMMANDS.index('bdist_wininst'),
|
||||||
|
'bdist_msi')
|
||||||
|
|
||||||
# XXX use OrderedDict to preserve the grouping (build-related, install-related,
|
# XXX maybe we need more than one registry, so that --list-comands can display
|
||||||
# distribution-related)
|
# standard, custom and overriden standard commands differently
|
||||||
STANDARD_COMMANDS = set(_COMMANDS)
|
_COMMANDS = dict((name, 'packaging.command.%s.%s' % (name, name))
|
||||||
|
for name in STANDARD_COMMANDS)
|
||||||
|
|
||||||
|
|
||||||
def get_command_names():
|
def get_command_names():
|
||||||
|
|
|
||||||
|
|
@ -254,16 +254,13 @@ def _run(dispatcher, args, **kw):
|
||||||
parser = dispatcher.parser
|
parser = dispatcher.parser
|
||||||
args = args[1:]
|
args = args[1:]
|
||||||
|
|
||||||
commands = STANDARD_COMMANDS # + extra commands
|
commands = STANDARD_COMMANDS # FIXME display extra commands
|
||||||
|
|
||||||
if args == ['--list-commands']:
|
if args == ['--list-commands']:
|
||||||
print('List of available commands:')
|
print('List of available commands:')
|
||||||
cmds = sorted(commands)
|
for cmd in commands:
|
||||||
|
|
||||||
for cmd in cmds:
|
|
||||||
cls = dispatcher.cmdclass.get(cmd) or get_command_class(cmd)
|
cls = dispatcher.cmdclass.get(cmd) or get_command_class(cmd)
|
||||||
desc = getattr(cls, 'description',
|
desc = getattr(cls, 'description', '(no description available)')
|
||||||
'(no description available)')
|
|
||||||
print(' %s: %s' % (cmd, desc))
|
print(' %s: %s' % (cmd, desc))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,23 @@ class RunTestCase(support.TempdirManager,
|
||||||
self.assertGreater(out, b'')
|
self.assertGreater(out, b'')
|
||||||
self.assertEqual(err, b'')
|
self.assertEqual(err, b'')
|
||||||
|
|
||||||
|
def test_list_commands(self):
|
||||||
|
status, out, err = assert_python_ok('-m', 'packaging.run', 'run',
|
||||||
|
'--list-commands')
|
||||||
|
# check that something is displayed
|
||||||
|
self.assertEqual(status, 0)
|
||||||
|
self.assertGreater(out, b'')
|
||||||
|
self.assertEqual(err, b'')
|
||||||
|
|
||||||
|
# make sure the manual grouping of commands is respected
|
||||||
|
check_position = out.find(b' check: ')
|
||||||
|
build_position = out.find(b' build: ')
|
||||||
|
self.assertTrue(check_position, out) # "out" printed as debugging aid
|
||||||
|
self.assertTrue(build_position, out)
|
||||||
|
self.assertLess(check_position, build_position, out)
|
||||||
|
|
||||||
|
# TODO test that custom commands don't break --list-commands
|
||||||
|
|
||||||
|
|
||||||
def test_suite():
|
def test_suite():
|
||||||
return unittest.makeSuite(RunTestCase)
|
return unittest.makeSuite(RunTestCase)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue