summaryrefslogtreecommitdiff
path: root/django/core/management
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2016-03-28 18:33:29 -0400
committerTim Graham <timograham@gmail.com>2016-04-08 09:51:06 -0400
commitdf8d8d4292684d6ffa7474f1e201aed486f02b53 (patch)
treec661bf9b33de5288afe4f63347a2a9c768ef98eb /django/core/management
parent2956e2f5e3f63d279f5dae2a995265364d3e6db1 (diff)
Fixed E128 flake8 warnings in django/.
Diffstat (limited to 'django/core/management')
-rw-r--r--django/core/management/__init__.py6
-rw-r--r--django/core/management/base.py33
-rw-r--r--django/core/management/commands/check.py18
-rw-r--r--django/core/management/commands/compilemessages.py23
-rw-r--r--django/core/management/commands/createcachetable.py30
-rw-r--r--django/core/management/commands/dbshell.py19
-rw-r--r--django/core/management/commands/diffsettings.py7
-rw-r--r--django/core/management/commands/dumpdata.py89
-rw-r--r--django/core/management/commands/flush.py19
-rw-r--r--django/core/management/commands/inspectdb.py13
-rw-r--r--django/core/management/commands/loaddata.py58
-rw-r--r--django/core/management/commands/makemessages.py103
-rw-r--r--django/core/management/commands/makemigrations.py48
-rw-r--r--django/core/management/commands/migrate.py53
-rw-r--r--django/core/management/commands/runserver.py24
-rw-r--r--django/core/management/commands/sendtestemail.py18
-rw-r--r--django/core/management/commands/shell.py24
-rw-r--r--django/core/management/commands/showmigrations.py24
-rw-r--r--django/core/management/commands/sqlflush.py7
-rw-r--r--django/core/management/commands/sqlmigrate.py20
-rw-r--r--django/core/management/commands/sqlsequencereset.py7
-rw-r--r--django/core/management/commands/squashmigrations.py31
-rw-r--r--django/core/management/commands/startapp.py14
-rw-r--r--django/core/management/commands/startproject.py15
-rw-r--r--django/core/management/commands/test.py35
-rw-r--r--django/core/management/commands/testserver.py25
-rw-r--r--django/core/management/templates.py18
27 files changed, 489 insertions, 292 deletions
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
index eef52e74ba..aa649176d2 100644
--- a/django/core/management/__init__.py
+++ b/django/core/management/__init__.py
@@ -196,8 +196,10 @@ class ManagementUtility(object):
settings.INSTALLED_APPS
else:
sys.stderr.write("No Django settings specified.\n")
- sys.stderr.write("Unknown command: %r\nType '%s help' for usage.\n" %
- (subcommand, self.prog_name))
+ sys.stderr.write(
+ "Unknown command: %r\nType '%s help' for usage.\n"
+ % (subcommand, self.prog_name)
+ )
sys.exit(1)
if isinstance(app_name, BaseCommand):
# If the command is already loaded, use it directly.
diff --git a/django/core/management/base.py b/django/core/management/base.py
index f747e57ab4..1601d6d055 100644
--- a/django/core/management/base.py
+++ b/django/core/management/base.py
@@ -241,25 +241,33 @@ class BaseCommand(object):
Create and return the ``ArgumentParser`` which will be used to
parse the arguments to this command.
"""
- parser = CommandParser(self, prog="%s %s" % (os.path.basename(prog_name), subcommand),
- description=self.help or None)
+ parser = CommandParser(
+ self, prog="%s %s" % (os.path.basename(prog_name), subcommand),
+ description=self.help or None,
+ )
parser.add_argument('--version', action='version', version=self.get_version())
- parser.add_argument('-v', '--verbosity', action='store', dest='verbosity', default=1,
+ parser.add_argument(
+ '-v', '--verbosity', action='store', dest='verbosity', default=1,
type=int, choices=[0, 1, 2, 3],
- help='Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output')
- parser.add_argument('--settings',
+ help='Verbosity level; 0=minimal output, 1=normal output, 2=verbose output, 3=very verbose output',
+ )
+ parser.add_argument(
+ '--settings',
help=(
'The Python path to a settings module, e.g. '
'"myproject.settings.main". If this isn\'t provided, the '
'DJANGO_SETTINGS_MODULE environment variable will be used.'
),
)
- parser.add_argument('--pythonpath',
- help='A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".')
- parser.add_argument('--traceback', action='store_true',
- help='Raise on CommandError exceptions')
- parser.add_argument('--no-color', action='store_true', dest='no_color', default=False,
- help="Don't colorize the command output.")
+ parser.add_argument(
+ '--pythonpath',
+ help='A directory to add to the Python path, e.g. "/home/djangoprojects/myproject".',
+ )
+ parser.add_argument('--traceback', action='store_true', help='Raise on CommandError exceptions')
+ parser.add_argument(
+ '--no-color', action='store_true', dest='no_color', default=False,
+ help="Don't colorize the command output.",
+ )
self.add_arguments(parser)
return parser
@@ -478,8 +486,7 @@ class AppCommand(BaseCommand):
missing_args_message = "Enter at least one application label."
def add_arguments(self, parser):
- parser.add_argument('args', metavar='app_label', nargs='+',
- help='One or more application label.')
+ parser.add_argument('args', metavar='app_label', nargs='+', help='One or more application label.')
def handle(self, *app_labels, **options):
from django.apps import apps
diff --git a/django/core/management/commands/check.py b/django/core/management/commands/check.py
index 4f5cc71f43..aa9685caa9 100644
--- a/django/core/management/commands/check.py
+++ b/django/core/management/commands/check.py
@@ -14,12 +14,18 @@ class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('args', metavar='app_label', nargs='*')
- parser.add_argument('--tag', '-t', action='append', dest='tags',
- help='Run only checks labeled with given tag.')
- parser.add_argument('--list-tags', action='store_true', dest='list_tags',
- help='List available tags.')
- parser.add_argument('--deploy', action='store_true', dest='deploy',
- help='Check deployment settings.')
+ parser.add_argument(
+ '--tag', '-t', action='append', dest='tags',
+ help='Run only checks labeled with given tag.',
+ )
+ parser.add_argument(
+ '--list-tags', action='store_true', dest='list_tags',
+ help='List available tags.',
+ )
+ parser.add_argument(
+ '--deploy', action='store_true', dest='deploy',
+ help='Check deployment settings.',
+ )
parser.add_argument(
'--fail-level',
default='ERROR',
diff --git a/django/core/management/commands/compilemessages.py b/django/core/management/commands/compilemessages.py
index 07e108fa1b..874fea4b5a 100644
--- a/django/core/management/commands/compilemessages.py
+++ b/django/core/management/commands/compilemessages.py
@@ -36,13 +36,19 @@ class Command(BaseCommand):
program_options = ['--check-format']
def add_arguments(self, parser):
- parser.add_argument('--locale', '-l', dest='locale', action='append', default=[],
+ parser.add_argument(
+ '--locale', '-l', dest='locale', action='append', default=[],
help='Locale(s) to process (e.g. de_AT). Default is to process all. '
- 'Can be used multiple times.')
- parser.add_argument('--exclude', '-x', dest='exclude', action='append', default=[],
- help='Locales to exclude. Default is none. Can be used multiple times.')
- parser.add_argument('--use-fuzzy', '-f', dest='fuzzy', action='store_true', default=False,
- help='Use fuzzy translations.')
+ 'Can be used multiple times.',
+ )
+ parser.add_argument(
+ '--exclude', '-x', dest='exclude', action='append', default=[],
+ help='Locales to exclude. Default is none. Can be used multiple times.',
+ )
+ parser.add_argument(
+ '--use-fuzzy', '-f', dest='fuzzy', action='store_true', default=False,
+ help='Use fuzzy translations.',
+ )
def handle(self, **options):
locale = options['locale']
@@ -116,8 +122,9 @@ class Command(BaseCommand):
"mo files will not be updated/created." % dirpath)
return
- args = [self.program] + self.program_options + ['-o',
- npath(base_path + '.mo'), npath(base_path + '.po')]
+ args = [self.program] + self.program_options + [
+ '-o', npath(base_path + '.mo'), npath(base_path + '.po')
+ ]
output, errors, status = popen_wrapper(args)
if status:
if errors:
diff --git a/django/core/management/commands/createcachetable.py b/django/core/management/commands/createcachetable.py
index 4a6456b536..f80fa8834e 100644
--- a/django/core/management/commands/createcachetable.py
+++ b/django/core/management/commands/createcachetable.py
@@ -15,16 +15,20 @@ class Command(BaseCommand):
requires_system_checks = False
def add_arguments(self, parser):
- parser.add_argument('args', metavar='table_name', nargs='*',
- help='Optional table names. Otherwise, settings.CACHES is used to '
- 'find cache tables.')
- parser.add_argument('--database', action='store', dest='database',
+ parser.add_argument(
+ 'args', metavar='table_name', nargs='*',
+ help='Optional table names. Otherwise, settings.CACHES is used to find cache tables.',
+ )
+ parser.add_argument(
+ '--database', action='store', dest='database',
default=DEFAULT_DB_ALIAS,
help='Nominates a database onto which the cache tables will be '
- 'installed. Defaults to the "default" database.')
- parser.add_argument('--dry-run', action='store_true', dest='dry_run',
- help='Does not create the table, just prints the SQL that would '
- 'be run.')
+ 'installed. Defaults to the "default" database.',
+ )
+ parser.add_argument(
+ '--dry-run', action='store_true', dest='dry_run',
+ help='Does not create the table, just prints the SQL that would be run.',
+ )
def handle(self, *tablenames, **options):
db = options['database']
@@ -72,9 +76,10 @@ class Command(BaseCommand):
field_output.append("UNIQUE")
if f.db_index:
unique = "UNIQUE " if f.unique else ""
- index_output.append("CREATE %sINDEX %s ON %s (%s);" %
- (unique, qn('%s_%s' % (tablename, f.name)), qn(tablename),
- qn(f.name)))
+ index_output.append(
+ "CREATE %sINDEX %s ON %s (%s);" %
+ (unique, qn('%s_%s' % (tablename, f.name)), qn(tablename), qn(f.name))
+ )
table_output.append(" ".join(field_output))
full_statement = ["CREATE TABLE %s (" % qn(tablename)]
for i, line in enumerate(table_output):
@@ -89,8 +94,7 @@ class Command(BaseCommand):
self.stdout.write(statement)
return
- with transaction.atomic(using=database,
- savepoint=connection.features.can_rollback_ddl):
+ with transaction.atomic(using=database, savepoint=connection.features.can_rollback_ddl):
with connection.cursor() as curs:
try:
curs.execute(full_statement)
diff --git a/django/core/management/commands/dbshell.py b/django/core/management/commands/dbshell.py
index d2ff81f7ca..eda1ff68c9 100644
--- a/django/core/management/commands/dbshell.py
+++ b/django/core/management/commands/dbshell.py
@@ -3,15 +3,18 @@ from django.db import DEFAULT_DB_ALIAS, connections
class Command(BaseCommand):
- help = ("Runs the command-line client for specified database, or the "
- "default database if none is provided.")
+ help = (
+ "Runs the command-line client for specified database, or the "
+ "default database if none is provided."
+ )
requires_system_checks = False
def add_arguments(self, parser):
- parser.add_argument('--database', action='store', dest='database',
- default=DEFAULT_DB_ALIAS, help='Nominates a database onto which to '
- 'open a shell. Defaults to the "default" database.')
+ parser.add_argument(
+ '--database', action='store', dest='database', default=DEFAULT_DB_ALIAS,
+ help='Nominates a database onto which to open a shell. Defaults to the "default" database.',
+ )
def handle(self, **options):
connection = connections[options['database']]
@@ -22,5 +25,7 @@ class Command(BaseCommand):
# isn't installed. There's a possibility OSError would be raised
# for some other reason, in which case this error message would be
# inaccurate. Still, this message catches the common case.
- raise CommandError('You appear not to have the %r program installed or on your path.' %
- connection.client.executable_name)
+ raise CommandError(
+ 'You appear not to have the %r program installed or on your path.' %
+ connection.client.executable_name
+ )
diff --git a/django/core/management/commands/diffsettings.py b/django/core/management/commands/diffsettings.py
index 9729131b3f..7bae48c218 100644
--- a/django/core/management/commands/diffsettings.py
+++ b/django/core/management/commands/diffsettings.py
@@ -14,9 +14,10 @@ class Command(BaseCommand):
requires_system_checks = False
def add_arguments(self, parser):
- parser.add_argument('--all', action='store_true', dest='all', default=False,
- help='Display all settings, regardless of their value. '
- 'Default values are prefixed by "###".')
+ parser.add_argument(
+ '--all', action='store_true', dest='all', default=False,
+ help='Display all settings, regardless of their value. Default values are prefixed by "###".',
+ )
def handle(self, **options):
# Inspired by Postfix's "postconf -n".
diff --git a/django/core/management/commands/dumpdata.py b/django/core/management/commands/dumpdata.py
index f8edcafabb..b8547d684f 100644
--- a/django/core/management/commands/dumpdata.py
+++ b/django/core/management/commands/dumpdata.py
@@ -12,37 +12,57 @@ class ProxyModelWarning(Warning):
class Command(BaseCommand):
- help = ("Output the contents of the database as a fixture of the given "
- "format (using each model's default manager unless --all is "
- "specified).")
+ help = (
+ "Output the contents of the database as a fixture of the given format "
+ "(using each model's default manager unless --all is specified)."
+ )
def add_arguments(self, parser):
- parser.add_argument('args', metavar='app_label[.ModelName]', nargs='*',
- help='Restricts dumped data to the specified app_label or app_label.ModelName.')
- parser.add_argument('--format', default='json', dest='format',
- help='Specifies the output serialization format for fixtures.')
- parser.add_argument('--indent', default=None, dest='indent', type=int,
- help='Specifies the indent level to use when pretty-printing output.')
- parser.add_argument('--database', action='store', dest='database',
+ parser.add_argument(
+ 'args', metavar='app_label[.ModelName]', nargs='*',
+ help='Restricts dumped data to the specified app_label or app_label.ModelName.',
+ )
+ parser.add_argument(
+ '--format', default='json', dest='format',
+ help='Specifies the output serialization format for fixtures.',
+ )
+ parser.add_argument(
+ '--indent', default=None, dest='indent', type=int,
+ help='Specifies the indent level to use when pretty-printing output.',
+ )
+ parser.add_argument(
+ '--database', action='store', dest='database',
default=DEFAULT_DB_ALIAS,
help='Nominates a specific database to dump fixtures from. '
- 'Defaults to the "default" database.')
- parser.add_argument('-e', '--exclude', dest='exclude', action='append', default=[],
+ 'Defaults to the "default" database.',
+ )
+ parser.add_argument(
+ '-e', '--exclude', dest='exclude', action='append', default=[],
help='An app_label or app_label.ModelName to exclude '
- '(use multiple --exclude to exclude multiple apps/models).')
- parser.add_argument('--natural-foreign', action='store_true', dest='use_natural_foreign_keys', default=False,
- help='Use natural foreign keys if they are available.')
- parser.add_argument('--natural-primary', action='store_true', dest='use_natural_primary_keys', default=False,
- help='Use natural primary keys if they are available.')
- parser.add_argument('-a', '--all', action='store_true', dest='use_base_manager', default=False,
+ '(use multiple --exclude to exclude multiple apps/models).',
+ )
+ parser.add_argument(
+ '--natural-foreign', action='store_true', dest='use_natural_foreign_keys', default=False,
+ help='Use natural foreign keys if they are available.',
+ )
+ parser.add_argument(
+ '--natural-primary', action='store_true', dest='use_natural_primary_keys', default=False,
+ help='Use natural primary keys if they are available.',
+ )
+ parser.add_argument(
+ '-a', '--all', action='store_true', dest='use_base_manager', default=False,
help="Use Django's base manager to dump all models stored in the database, "
- "including those that would otherwise be filtered or modified by a custom manager.")
- parser.add_argument('--pks', dest='primary_keys',
- help="Only dump objects with given primary keys. "
- "Accepts a comma separated list of keys. "
- "This option will only work when you specify one model.")
- parser.add_argument('-o', '--output', default=None, dest='output',
- help='Specifies file to which the output is written.')
+ "including those that would otherwise be filtered or modified by a custom manager.",
+ )
+ parser.add_argument(
+ '--pks', dest='primary_keys',
+ help="Only dump objects with given primary keys. Accepts a comma-separated "
+ "list of keys. This option only works when you specify one model.",
+ )
+ parser.add_argument(
+ '-o', '--output', default=None, dest='output',
+ help='Specifies file to which the output is written.'
+ )
def handle(self, *app_labels, **options):
format = options['format']
@@ -80,9 +100,10 @@ class Command(BaseCommand):
if len(app_labels) == 0:
if primary_keys:
raise CommandError("You can only use --pks option with one model")
- app_list = OrderedDict((app_config, None)
- for app_config in apps.get_app_configs()
- if app_config.models_module is not None and app_config not in excluded_apps)
+ app_list = OrderedDict(
+ (app_config, None) for app_config in apps.get_app_configs()
+ if app_config.models_module is not None and app_config not in excluded_apps
+ )
else:
if len(app_labels) > 1 and primary_keys:
raise CommandError("You can only use --pks option with one model")
@@ -171,11 +192,13 @@ class Command(BaseCommand):
object_count = sum(get_objects(count_only=True))
stream = open(output, 'w') if output else None
try:
- serializers.serialize(format, get_objects(), indent=indent,
- use_natural_foreign_keys=use_natural_foreign_keys,
- use_natural_primary_keys=use_natural_primary_keys,
- stream=stream or self.stdout, progress_output=progress_output,
- object_count=object_count)
+ serializers.serialize(
+ format, get_objects(), indent=indent,
+ use_natural_foreign_keys=use_natural_foreign_keys,
+ use_natural_primary_keys=use_natural_primary_keys,
+ stream=stream or self.stdout, progress_output=progress_output,
+ object_count=object_count,
+ )
finally:
if stream:
stream.close()
diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py
index 3820f2cce8..68226355b8 100644
--- a/django/core/management/commands/flush.py
+++ b/django/core/management/commands/flush.py
@@ -13,16 +13,21 @@ from django.utils.six.moves import input
class Command(BaseCommand):
- help = ('Removes ALL DATA from the database, including data added during '
- 'migrations. Does not achieve a "fresh install" state.')
+ help = (
+ 'Removes ALL DATA from the database, including data added during '
+ 'migrations. Does not achieve a "fresh install" state.'
+ )
def add_arguments(self, parser):
- parser.add_argument('--noinput', '--no-input',
+ parser.add_argument(
+ '--noinput', '--no-input',
action='store_false', dest='interactive', default=True,
- help='Tells Django to NOT prompt the user for input of any kind.')
- parser.add_argument('--database', action='store', dest='database',
- default=DEFAULT_DB_ALIAS,
- help='Nominates a database to flush. Defaults to the "default" database.')
+ help='Tells Django to NOT prompt the user for input of any kind.',
+ )
+ parser.add_argument(
+ '--database', action='store', dest='database', default=DEFAULT_DB_ALIAS,
+ help='Nominates a database to flush. Defaults to the "default" database.',
+ )
def handle(self, **options):
database = options['database']
diff --git a/django/core/management/commands/inspectdb.py b/django/core/management/commands/inspectdb.py
index 24310ee390..02a8ac225e 100644
--- a/django/core/management/commands/inspectdb.py
+++ b/django/core/management/commands/inspectdb.py
@@ -17,11 +17,14 @@ class Command(BaseCommand):
db_module = 'django.db'
def add_arguments(self, parser):
- parser.add_argument('table', action='store', nargs='*', type=str,
- help='Selects what tables or views should be introspected.')
- parser.add_argument('--database', action='store', dest='database',
- default=DEFAULT_DB_ALIAS, help='Nominates a database to '
- 'introspect. Defaults to using the "default" database.')
+ parser.add_argument(
+ 'table', action='store', nargs='*', type=str,
+ help='Selects what tables or views should be introspected.',
+ )
+ parser.add_argument(
+ '--database', action='store', dest='database', default=DEFAULT_DB_ALIAS,
+ help='Nominates a database to introspect. Defaults to using the "default" database.',
+ )
def handle(self, **options):
try:
diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
index a53270a38b..1b0cee0d2b 100644
--- a/django/core/management/commands/loaddata.py
+++ b/django/core/management/commands/loaddata.py
@@ -32,21 +32,26 @@ except ImportError:
class Command(BaseCommand):
help = 'Installs the named fixture(s) in the database.'
- missing_args_message = ("No database fixture specified. Please provide the "
- "path of at least one fixture in the command line.")
+ missing_args_message = (
+ "No database fixture specified. Please provide the path of at least "
+ "one fixture in the command line."
+ )
def add_arguments(self, parser):
- parser.add_argument('args', metavar='fixture', nargs='+',
- help='Fixture labels.')
- parser.add_argument('--database', action='store', dest='database',
- default=DEFAULT_DB_ALIAS, help='Nominates a specific database to load '
- 'fixtures into. Defaults to the "default" database.')
- parser.add_argument('--app', action='store', dest='app_label',
- default=None, help='Only look for fixtures in the specified app.')
- parser.add_argument('--ignorenonexistent', '-i', action='store_true',
- dest='ignore', default=False,
+ parser.add_argument('args', metavar='fixture', nargs='+', help='Fixture labels.')
+ parser.add_argument(
+ '--database', action='store', dest='database', default=DEFAULT_DB_ALIAS,
+ help='Nominates a specific database to load fixtures into. Defaults to the "default" database.',
+ )
+ parser.add_argument(
+ '--app', action='store', dest='app_label', default=None,
+ help='Only look for fixtures in the specified app.',
+ )
+ parser.add_argument(
+ '--ignorenonexistent', '-i', action='store_true', dest='ignore', default=False,
help='Ignores entries in the serialized data for fields that do not '
- 'currently exist on the model.')
+ 'currently exist on the model.',
+ )
def handle(self, *fixture_labels, **options):
@@ -120,11 +125,15 @@ class Command(BaseCommand):
if self.verbosity >= 1:
if self.fixture_object_count == self.loaded_object_count:
- self.stdout.write("Installed %d object(s) from %d fixture(s)" %
- (self.loaded_object_count, self.fixture_count))
+ self.stdout.write(
+ "Installed %d object(s) from %d fixture(s)"
+ % (self.loaded_object_count, self.fixture_count)
+ )
else:
- self.stdout.write("Installed %d object(s) (of %d) from %d fixture(s)" %
- (self.loaded_object_count, self.fixture_object_count, self.fixture_count))
+ self.stdout.write(
+ "Installed %d object(s) (of %d) from %d fixture(s)"
+ % (self.loaded_object_count, self.fixture_object_count, self.fixture_count)
+ )
def load_label(self, fixture_label):
"""
@@ -140,11 +149,14 @@ class Command(BaseCommand):
objects_in_fixture = 0
loaded_objects_in_fixture = 0
if self.verbosity >= 2:
- self.stdout.write("Installing %s fixture '%s' from %s." %
- (ser_fmt, fixture_name, humanize(fixture_dir)))
+ self.stdout.write(
+ "Installing %s fixture '%s' from %s."
+ % (ser_fmt, fixture_name, humanize(fixture_dir))
+ )
- objects = serializers.deserialize(ser_fmt, fixture,
- using=self.using, ignorenonexistent=self.ignore)
+ objects = serializers.deserialize(
+ ser_fmt, fixture, using=self.using, ignorenonexistent=self.ignore,
+ )
for obj in objects:
objects_in_fixture += 1
@@ -208,8 +220,10 @@ class Command(BaseCommand):
for dir_ in fixture_dirs]
fixture_name = os.path.basename(fixture_name)
- suffixes = ('.'.join(ext for ext in combo if ext)
- for combo in product(databases, ser_fmts, cmp_fmts))
+ suffixes = (
+ '.'.join(ext for ext in combo if ext)
+ for combo in product(databases, ser_fmts, cmp_fmts)
+ )
targets = set('.'.join((fixture_name, suffix)) for suffix in suffixes)
fixture_files = []
diff --git a/django/core/management/commands/makemessages.py b/django/core/management/commands/makemessages.py
index cfe6d3d087..45113b68ab 100644
--- a/django/core/management/commands/makemessages.py
+++ b/django/core/management/commands/makemessages.py
@@ -30,8 +30,10 @@ NO_LOCALE_DIR = object()
def check_programs(*programs):
for program in programs:
if find_command(program) is None:
- raise CommandError("Can't find %s. Make sure you have GNU "
- "gettext tools 0.15 or newer installed." % program)
+ raise CommandError(
+ "Can't find %s. Make sure you have GNU gettext tools 0.15 or "
+ "newer installed." % program
+ )
@total_ordering
@@ -161,11 +163,13 @@ def write_pot_file(potfile, msgs):
class Command(BaseCommand):
- help = ("Runs over the entire source tree of the current directory and "
-"pulls out all strings marked for translation. It creates (or updates) a message "
-"file in the conf/locale (in the django tree) or locale (for projects and "
-"applications) directory.\n\nYou must run this command with one of either the "
-"--locale, --exclude or --all options.")
+ help = (
+ "Runs over the entire source tree of the current directory and "
+ "pulls out all strings marked for translation. It creates (or updates) a message "
+ "file in the conf/locale (in the django tree) or locale (for projects and "
+ "applications) directory.\n\nYou must run this command with one of either the "
+ "--locale, --exclude, or --all options."
+ )
translatable_file_class = TranslatableFile
build_file_class = BuildFile
@@ -179,37 +183,60 @@ class Command(BaseCommand):
xgettext_options = ['--from-code=UTF-8', '--add-comments=Translators']
def add_arguments(self, parser):
- parser.add_argument('--locale', '-l', default=[], dest='locale', action='append',
+ parser.add_argument(
+ '--locale', '-l', default=[], dest='locale', action='append',
help='Creates or updates the message files for the given locale(s) (e.g. pt_BR). '
- 'Can be used multiple times.')
- parser.add_argument('--exclude', '-x', default=[], dest='exclude', action='append',
- help='Locales to exclude. Default is none. Can be used multiple times.')
- parser.add_argument('--domain', '-d', default='django', dest='domain',
- help='The domain of the message files (default: "django").')
- parser.add_argument('--all', '-a', action='store_true', dest='all',
- default=False, help='Updates the message files for all existing locales.')
- parser.add_argument('--extension', '-e', dest='extensions',
+ 'Can be used multiple times.',
+ )
+ parser.add_argument(
+ '--exclude', '-x', default=[], dest='exclude', action='append',
+ help='Locales to exclude. Default is none. Can be used multiple times.',
+ )
+ parser.add_argument(
+ '--domain', '-d', default='django', dest='domain',
+ help='The domain of the message files (default: "django").',
+ )
+ parser.add_argument(
+ '--all', '-a', action='store_true', dest='all', default=False,
+ help='Updates the message files for all existing locales.',
+ )
+ parser.add_argument(
+ '--extension', '-e', dest='extensions', action='append',
help='The file extension(s) to examine (default: "html,txt,py", or "js" '
'if the domain is "djangojs"). Separate multiple extensions with '
'commas, or use -e multiple times.',
- action='append')
- parser.add_argument('--symlinks', '-s', action='store_true', dest='symlinks',
- default=False, help='Follows symlinks to directories when examining '
- 'source code and templates for translation strings.')
- parser.add_argument('--ignore', '-i', action='append', dest='ignore_patterns',
+ )
+ parser.add_argument(
+ '--symlinks', '-s', action='store_true', dest='symlinks', default=False,
+ help='Follows symlinks to directories when examining source code '
+ 'and templates for translation strings.',
+ )
+ parser.add_argument(
+ '--ignore', '-i', action='append', dest='ignore_patterns',
default=[], metavar='PATTERN',
help='Ignore files or directories matching this glob-style pattern. '
- 'Use multiple times to ignore more.')
- parser.add_argument('--no-default-ignore', action='store_false', dest='use_default_ignore_patterns',
- default=True, help="Don't ignore the common glob-style patterns 'CVS', '.*', '*~' and '*.pyc'.")
- parser.add_argument('--no-wrap', action='store_true', dest='no_wrap',
- default=False, help="Don't break long message lines into several lines.")
- parser.add_argument('--no-location', action='store_true', dest='no_location',
- default=False, help="Don't write '#: filename:line' lines.")
- parser.add_argument('--no-obsolete', action='store_true', dest='no_obsolete',
- default=False, help="Remove obsolete message strings.")
- parser.add_argument('--keep-pot', action='store_true', dest='keep_pot',
- default=False, help="Keep .pot file after making messages. Useful when debugging.")
+ 'Use multiple times to ignore more.',
+ )
+ parser.add_argument(
+ '--no-default-ignore', action='store_false', dest='use_default_ignore_patterns',
+ default=True, help="Don't ignore the common glob-style patterns 'CVS', '.*', '*~' and '*.pyc'.",
+ )
+ parser.add_argument(
+ '--no-wrap', action='store_true', dest='no_wrap',
+ default=False, help="Don't break long message lines into several lines.",
+ )
+ parser.add_argument(
+ '--no-location', action='store_true', dest='no_location',
+ default=False, help="Don't write '#: filename:line' lines.",
+ )
+ parser.add_argument(
+ '--no-obsolete', action='store_true', dest='no_obsolete',
+ default=False, help="Remove obsolete message strings.",
+ )
+ parser.add_argument(
+ '--keep-pot', action='store_true', dest='keep_pot',
+ default=False, help="Keep .pot file after making messages. Useful when debugging.",
+ )
def handle(self, *args, **options):
locale = options['locale']
@@ -256,12 +283,16 @@ class Command(BaseCommand):
self.extensions = handle_extensions(exts)
if (locale is None and not exclude and not process_all) or self.domain is None:
- raise CommandError("Type '%s help %s' for usage information." % (
- os.path.basename(sys.argv[0]), sys.argv[1]))
+ raise CommandError(
+ "Type '%s help %s' for usage information."
+ % (os.path.basename(sys.argv[0]), sys.argv[1])
+ )
if self.verbosity > 1:
- self.stdout.write('examining files with the extensions: %s\n'
- % get_text_list(list(self.extensions), 'and'))
+ self.stdout.write(
+ 'examining files with the extensions: %s\n'
+ % get_text_list(list(self.extensions), 'and')
+ )
self.invoked_for_django = False
self.locale_paths = []
diff --git a/django/core/management/commands/makemigrations.py b/django/core/management/commands/makemigrations.py
index fc691391f5..6766434193 100644
--- a/django/core/management/commands/makemigrations.py
+++ b/django/core/management/commands/makemigrations.py
@@ -24,24 +24,40 @@ class Command(BaseCommand):
help = "Creates new migration(s) for apps."
def add_arguments(self, parser):
- parser.add_argument('args', metavar='app_label', nargs='*',
- help='Specify the app label(s) to create migrations for.')
- parser.add_argument('--dry-run', action='store_true', dest='dry_run', default=False,
- help="Just show what migrations would be made; don't actually write them.")
- parser.add_argument('--merge', action='store_true', dest='merge', default=False,
- help="Enable fixing of migration conflicts.")
- parser.add_argument('--empty', action='store_true', dest='empty', default=False,
- help="Create an empty migration.")
- parser.add_argument('--noinput', '--no-input',
+ parser.add_argument(
+ 'args', metavar='app_label', nargs='*',
+ help='Specify the app label(s) to create migrations for.',
+ )
+ parser.add_argument(
+ '--dry-run', action='store_true', dest='dry_run', default=False,
+ help="Just show what migrations would be made; don't actually write them.",
+ )
+ parser.add_argument(
+ '--merge', action='store_true', dest='merge', default=False,
+ help="Enable fixing of migration conflicts.",
+ )
+ parser.add_argument(
+ '--empty', action='store_true', dest='empty', default=False,
+ help="Create an empty migration.",
+ )
+ parser.add_argument(
+ '--noinput', '--no-input',
action='store_false', dest='interactive', default=True,
- help='Tells Django to NOT prompt the user for input of any kind.')
- parser.add_argument('-n', '--name', action='store', dest='name', default=None,
- help="Use this name for migration file(s).")
- parser.add_argument('-e', '--exit', action='store_true', dest='exit_code', default=False,
+ help='Tells Django to NOT prompt the user for input of any kind.',
+ )
+ parser.add_argument(
+ '-n', '--name', action='store', dest='name', default=None,
+ help="Use this name for migration file(s).",
+ )
+ parser.add_argument(
+ '-e', '--exit', action='store_true', dest='exit_code', default=False,
help='Exit with error code 1 if no changes needing migrations are found. '
- 'Deprecated, use the --check option instead.')
- parser.add_argument('--check', action='store_true', dest='check_changes',
- help='Exit with a non-zero status if model changes are missing migrations.')
+ 'Deprecated, use the --check option instead.',
+ )
+ parser.add_argument(
+ '--check', action='store_true', dest='check_changes',
+ help='Exit with a non-zero status if model changes are missing migrations.',
+ )
def handle(self, *app_labels, **options):
self.verbosity = options['verbosity']
diff --git a/django/core/management/commands/migrate.py b/django/core/management/commands/migrate.py
index 9c73500d21..84dbc59c65 100644
--- a/django/core/management/commands/migrate.py
+++ b/django/core/management/commands/migrate.py
@@ -22,28 +22,39 @@ class Command(BaseCommand):
help = "Updates database schema. Manages both apps with migrations and those without."
def add_arguments(self, parser):
- parser.add_argument('app_label', nargs='?',
- help='App label of an application to synchronize the state.')
- parser.add_argument('migration_name', nargs='?',
- help=(
- 'Database state will be brought to the state after that '
- 'migration. Use the name "zero" to unapply all migrations.'
- ),
+ parser.add_argument(
+ 'app_label', nargs='?',
+ help='App label of an application to synchronize the state.',
)
- parser.add_argument('--noinput', '--no-input',
+ parser.add_argument(
+ 'migration_name', nargs='?',
+ help='Database state will be brought to the state after that '
+ 'migration. Use the name "zero" to unapply all migrations.',
+ )
+ parser.add_argument(
+ '--noinput', '--no-input',
action='store_false', dest='interactive', default=True,
- help='Tells Django to NOT prompt the user for input of any kind.')
- parser.add_argument('--database', action='store', dest='database',
- default=DEFAULT_DB_ALIAS, help='Nominates a database to synchronize. '
- 'Defaults to the "default" database.')
- parser.add_argument('--fake', action='store_true', dest='fake', default=False,
- help='Mark migrations as run without actually running them.')
- parser.add_argument('--fake-initial', action='store_true', dest='fake_initial', default=False,
+ help='Tells Django to NOT prompt the user for input of any kind.',
+ )
+ parser.add_argument(
+ '--database', action='store', dest='database',
+ default=DEFAULT_DB_ALIAS,
+ help='Nominates a database to synchronize. Defaults to the "default" database.',
+ )
+ parser.add_argument(
+ '--fake', action='store_true', dest='fake', default=False,
+ help='Mark migrations as run without actually running them.',
+ )
+ parser.add_argument(
+ '--fake-initial', action='store_true', dest='fake_initial', default=False,
help='Detect if tables already exist and fake-apply initial migrations if so. Make sure '
'that the current database schema matches your initial migration before using this '
- 'flag. Django will only check for an existing table name.')
- parser.add_argument('--run-syncdb', action='store_true', dest='run_syncdb',
- help='Creates tables for apps without migrations.')
+ 'flag. Django will only check for an existing table name.',
+ )
+ parser.add_argument(
+ '--run-syncdb', action='store_true', dest='run_syncdb',
+ help='Creates tables for apps without migrations.',
+ )
def handle(self, *args, **options):
@@ -238,8 +249,10 @@ class Command(BaseCommand):
opts = model._meta
converter = connection.introspection.table_name_converter
# Note that if a model is unmanaged we short-circuit and never try to install it
- return not ((converter(opts.db_table) in tables) or
- (opts.auto_created and converter(opts.auto_created._meta.db_table) in tables))
+ return not (
+ (converter(opts.db_table) in tables) or
+ (opts.auto_created and converter(opts.auto_created._meta.db_table) in tables)
+ )
manifest = OrderedDict(
(app_name, list(filter(model_installed, model_list)))
diff --git a/django/core/management/commands/runserver.py b/django/core/management/commands/runserver.py
index d5c8189d6b..18c2d61a88 100644
--- a/django/core/management/commands/runserver.py
+++ b/django/core/management/commands/runserver.py
@@ -32,14 +32,22 @@ class Command(BaseCommand):
default_port = '8000'
def add_arguments(self, parser):
- parser.add_argument('addrport', nargs='?',
- help='Optional port number, or ipaddr:port')
- parser.add_argument('--ipv6', '-6', action='store_true', dest='use_ipv6', default=False,
- help='Tells Django to use an IPv6 address.')
- parser.add_argument('--nothreading', action='store_false', dest='use_threading', default=True,
- help='Tells Django to NOT use threading.')
- parser.add_argument('--noreload', action='store_false', dest='use_reloader', default=True,
- help='Tells Django to NOT use the auto-reloader.')
+ parser.add_argument(
+ 'addrport', nargs='?',
+ help='Optional port number, or ipaddr:port'
+ )
+ parser.add_argument(
+ '--ipv6', '-6', action='store_true', dest='use_ipv6', default=False,
+ help='Tells Django to use an IPv6 address.',
+ )
+ parser.add_argument(
+ '--nothreading', action='store_false', dest='use_threading', default=True,
+ help='Tells Django to NOT use threading.',
+ )
+ parser.add_argument(
+ '--noreload', action='store_false', dest='use_reloader', default=True,
+ help='Tells Django to NOT use the auto-reloader.',
+ )
def execute(self, *args, **options):
if options['no_color']:
diff --git a/django/core/management/commands/sendtestemail.py b/django/core/management/commands/sendtestemail.py
index 3e3b40a959..6ca011b544 100644
--- a/django/core/management/commands/sendtestemail.py
+++ b/django/core/management/commands/sendtestemail.py
@@ -10,12 +10,18 @@ class Command(BaseCommand):
missing_args_message = "You must specify some email recipients, or pass the --managers or --admin options."
def add_arguments(self, parser):
- parser.add_argument('email', nargs='*',
- help='One or more email addresses to send a test email to.')
- parser.add_argument('--managers', action='store_true', dest='managers', default=False,
- help='Send a test email to the addresses specified in settings.MANAGERS.')
- parser.add_argument('--admins', action='store_true', dest='admins', default=False,
- help='Send a test email to the addresses specified in settings.ADMINS.')
+ parser.add_argument(
+ 'email', nargs='*',
+ help='One or more email addresses to send a test email to.',
+ )
+ parser.add_argument(
+ '--managers', action='store_true', dest='managers', default=False,
+ help='Send a test email to the addresses specified in settings.MANAGERS.',
+ )
+ parser.add_argument(
+ '--admins', action='store_true', dest='admins', default=False,
+ help='Send a test email to the addresses specified in settings.ADMINS.',
+ )
def handle(self, *args, **kwargs):
subject = 'Test email from %s on %s' % (socket.gethostname(), timezone.now())
diff --git a/django/core/management/commands/shell.py b/django/core/management/commands/shell.py
index bd61940aba..d6d6f6a087 100644
--- a/django/core/management/commands/shell.py
+++ b/django/core/management/commands/shell.py
@@ -11,15 +11,23 @@ class Command(BaseCommand):
shells = ['ipython', 'bpython', 'python']
def add_arguments(self, parser):
- parser.add_argument('--plain', action='store_true', dest='plain',
+ parser.add_argument(
+ '--plain', action='store_true', dest='plain',
help='Tells Django to use plain Python, not IPython or bpython. '
- 'Deprecated, use the `-i python` or `--interface python` option instead.')
- parser.add_argument('--no-startup', action='store_true', dest='no_startup',
- help='When using plain Python, ignore the PYTHONSTARTUP environment variable and ~/.pythonrc.py script.')
- parser.add_argument('-i', '--interface', choices=self.shells, dest='interface',
- help='Specify an interactive interpreter interface. Available options: "ipython", "bpython", and "python"')
- parser.add_argument('-c', '--command', dest='command',
- help='Instead of opening an interactive shell, run a command as Django and exit.')
+ 'Deprecated, use the `-i python` or `--interface python` option instead.',
+ )
+ parser.add_argument(
+ '--no-startup', action='store_true', dest='no_startup',
+ help='When using plain Python, ignore the PYTHONSTARTUP environment variable and ~/.pythonrc.py script.',
+ )
+ parser.add_argument(
+ '-i', '--interface', choices=self.shells, dest='interface',
+ help='Specify an interactive interpreter interface. Available options: "ipython", "bpython", and "python"',
+ )
+ parser.add_argument(
+ '-c', '--command', dest='command',
+ help='Instead of opening an interactive shell, run a command as Django and exit.',
+ )
def _ipython_pre_011(self):
"""Start IPython pre-0.11"""
diff --git a/django/core/management/commands/showmigrations.py b/django/core/management/commands/showmigrations.py
index 0e53e11259..0d239b1eef 100644
--- a/django/core/management/commands/showmigrations.py
+++ b/django/core/management/commands/showmigrations.py
@@ -10,16 +10,24 @@ class Command(BaseCommand):
help = "Shows all available migrations for the current project"
def add_arguments(self, parser):
- parser.add_argument('app_label', nargs='*',
- help='App labels of applications to limit the output to.')
- parser.add_argument('--database', action='store', dest='database', default=DEFAULT_DB_ALIAS,
- help='Nominates a database to synchronize. Defaults to the "default" database.')
+ parser.add_argument(
+ 'app_label', nargs='*',
+ help='App labels of applications to limit the output to.',
+ )
+ parser.add_argument(
+ '--database', action='store', dest='database', default=DEFAULT_DB_ALIAS,
+ help='Nominates a database to synchronize. Defaults to the "default" database.',
+ )
formats = parser.add_mutually_exclusive_group()
- formats.add_argument('--list', '-l', action='store_const', dest='format', const='list',
- help='Shows a list of all migrations and which are applied.')
- formats.add_argument('--plan', '-p', action='store_const', dest='format', const='plan',
- help='Shows all migrations in the order they will be applied.')
+ formats.add_argument(
+ '--list', '-l', action='store_const', dest='format', const='list',
+ help='Shows a list of all migrations and which are applied.',
+ )
+ formats.add_argument(
+ '--plan', '-p', action='store_const', dest='format', const='plan',
+ help='Shows all migrations in the order they will be applied.',
+ )
parser.set_defaults(format='list')
diff --git a/django/core/management/commands/sqlflush.py b/django/core/management/commands/sqlflush.py
index eba9197be7..f0c7e30270 100644
--- a/django/core/management/commands/sqlflush.py
+++ b/django/core/management/commands/sqlflush.py
@@ -15,9 +15,10 @@ class Command(BaseCommand):
def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
- parser.add_argument('--database', default=DEFAULT_DB_ALIAS,
- help='Nominates a database to print the SQL for. Defaults to the '
- '"default" database.')
+ parser.add_argument(
+ '--database', default=DEFAULT_DB_ALIAS,
+ help='Nominates a database to print the SQL for. Defaults to the "default" database.',
+ )
def handle(self, **options):
return '\n'.join(sql_flush(self.style, connections[options['database']], only_django=True))
diff --git a/django/core/management/commands/sqlmigrate.py b/django/core/management/commands/sqlmigrate.py
index b858b2b805..5047d900c1 100644
--- a/django/core/management/commands/sqlmigrate.py
+++ b/django/core/management/commands/sqlmigrate.py
@@ -13,15 +13,17 @@ class Command(BaseCommand):
output_transaction = True
def add_arguments(self, parser):
- parser.add_argument('app_label',
- help='App label of the application containing the migration.')
- parser.add_argument('migration_name',
- help='Migration name to print the SQL for.')
- parser.add_argument('--database', default=DEFAULT_DB_ALIAS,
- help='Nominates a database to create SQL for. Defaults to the '
- '"default" database.')
- parser.add_argument('--backwards', action='store_true', dest='backwards',
- default=False, help='Creates SQL to unapply the migration, rather than to apply it')
+ parser.add_argument('app_label', help='App label of the application containing the migration.')
+ parser.add_argument('migration_name', help='Migration name to print the SQL for.')
+ parser.add_argument(
+ '--database', default=DEFAULT_DB_ALIAS,
+ help='Nominates a database to create SQL for. Defaults to the "default" database.',
+ )
+ parser.add_argument(
+ '--backwards', action='store_true', dest='backwards',
+ default=False,
+ help='Creates SQL to unapply the migration, rather than to apply it',
+ )
def execute(self, *args, **options):
# sqlmigrate doesn't support coloring its output but we need to force
diff --git a/django/core/management/commands/sqlsequencereset.py b/django/core/management/commands/sqlsequencereset.py
index ebb6f9da2e..6ac6e10d60 100644
--- a/django/core/management/commands/sqlsequencereset.py
+++ b/django/core/management/commands/sqlsequencereset.py
@@ -11,9 +11,10 @@ class Command(AppCommand):
def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
- parser.add_argument('--database', default=DEFAULT_DB_ALIAS,
- help='Nominates a database to print the SQL for. Defaults to the '
- '"default" database.')
+ parser.add_argument(
+ '--database', default=DEFAULT_DB_ALIAS,
+ help='Nominates a database to print the SQL for. Defaults to the "default" database.',
+ )
def handle_app_config(self, app_config, **options):
if app_config.models_module is None:
diff --git a/django/core/management/commands/squashmigrations.py b/django/core/management/commands/squashmigrations.py
index 61c99baafd..d9babf85f8 100644
--- a/django/core/management/commands/squashmigrations.py
+++ b/django/core/management/commands/squashmigrations.py
@@ -13,17 +13,26 @@ class Command(BaseCommand):
help = "Squashes an existing set of migrations (from first until specified) into a single new one."
def add_arguments(self, parser):
- parser.add_argument('app_label',
- help='App label of the application to squash migrations for.')
- parser.add_argument('start_migration_name', default=None, nargs='?',
- help='Migrations will be squashed starting from and including this migration.')
- parser.add_argument('migration_name',
- help='Migrations will be squashed until and including this migration.')
- parser.add_argument('--no-optimize', action='store_true', dest='no_optimize', default=False,
- help='Do not try to optimize the squashed operations.')
- parser.add_argument('--noinput', '--no-input',
- action='store_false', dest='interactive', default=True,
- help='Tells Django to NOT prompt the user for input of any kind.')
+ parser.add_argument(
+ 'app_label',
+ help='App label of the application to squash migrations for.',
+ )
+ parser.add_argument(
+ 'start_migration_name', default=None, nargs='?',
+ help='Migrations will be squashed starting from and including this migration.',
+ )
+ parser.add_argument(
+ 'migration_name',
+ help='Migrations will be squashed until and including this migration.',
+ )
+ parser.add_argument(
+ '--no-optimize', action='store_true', dest='no_optimize', default=False,
+ help='Do not try to optimize the squashed operations.',
+ )
+ parser.add_argument(
+ '--noinput', '--no-input', action='store_false', dest='interactive', default=True,
+ help='Tells Django to NOT prompt the user for input of any kind.',
+ )
def handle(self, **options):
diff --git a/django/core/management/commands/startapp.py b/django/core/management/commands/startapp.py
index 23ae25446b..32e9454a3c 100644
--- a/django/core/management/commands/startapp.py
+++ b/django/core/management/commands/startapp.py
@@ -5,9 +5,10 @@ from django.core.management.templates import TemplateCommand
class Command(TemplateCommand):
- help = ("Creates a Django app directory structure for the given app "
- "name in the current directory or optionally in the given "
- "directory.")
+ help = (
+ "Creates a Django app directory structure for the given app name in "
+ "the current directory or optionally in the given directory."
+ )
missing_args_message = "You must provide an application name."
def handle(self, **options):
@@ -20,8 +21,9 @@ class Command(TemplateCommand):
except ImportError:
pass
else:
- raise CommandError("%r conflicts with the name of an existing "
- "Python module and cannot be used as an app "
- "name. Please try another name." % app_name)
+ raise CommandError(
+ "%r conflicts with the name of an existing Python module and "
+ "cannot be used as an app name. Please try another name." % app_name
+ )
super(Command, self).handle('app', app_name, target, **options)
diff --git a/django/core/management/commands/startproject.py b/django/core/management/commands/startproject.py
index f50f27cf1f..d7307e141b 100644
--- a/django/core/management/commands/startproject.py
+++ b/django/core/management/commands/startproject.py
@@ -7,9 +7,10 @@ from ..utils import get_random_secret_key
class Command(TemplateCommand):
- help = ("Creates a Django project directory structure for the given "
- "project name in the current directory or optionally in the "
- "given directory.")
+ help = (
+ "Creates a Django project directory structure for the given project "
+ "name in the current directory or optionally in the given directory."
+ )
missing_args_message = "You must provide a project name."
def handle(self, **options):
@@ -22,10 +23,10 @@ class Command(TemplateCommand):
except ImportError:
pass
else:
- raise CommandError("%r conflicts with the name of an existing "
- "Python module and cannot be used as a "
- "project name. Please try another name." %
- project_name)
+ raise CommandError(
+ "%r conflicts with the name of an existing Python module and "
+ "cannot be used as a project name. Please try another name." % project_name
+ )
# Create a random SECRET_KEY to put it in the main settings.
options['secret_key'] = get_random_secret_key()
diff --git a/django/core/management/commands/test.py b/django/core/management/commands/test.py
index 2d98abebd0..73796fe417 100644
--- a/django/core/management/commands/test.py
+++ b/django/core/management/commands/test.py
@@ -29,24 +29,29 @@ class Command(BaseCommand):
super(Command, self).run_from_argv(argv)
def add_arguments(self, parser):
- parser.add_argument('args', metavar='test_label', nargs='*',
- help='Module paths to test; can be modulename, modulename.TestCase or modulename.TestCase.test_method')
- parser.add_argument('--noinput', '--no-input',
- action='store_false', dest='interactive', default=True,
- help='Tells Django to NOT prompt the user for input of any kind.')
- parser.add_argument('--failfast',
- action='store_true', dest='failfast', default=False,
- help='Tells Django to stop running the test suite after first '
- 'failed test.')
- parser.add_argument('--testrunner',
- action='store', dest='testrunner',
+ parser.add_argument(
+ 'args', metavar='test_label', nargs='*',
+ help='Module paths to test; can be modulename, modulename.TestCase or modulename.TestCase.test_method'
+ )
+ parser.add_argument(
+ '--noinput', '--no-input', action='store_false', dest='interactive', default=True,
+ help='Tells Django to NOT prompt the user for input of any kind.',
+ )
+ parser.add_argument(
+ '--failfast', action='store_true', dest='failfast', default=False,
+ help='Tells Django to stop running the test suite after first failed test.',
+ )
+ parser.add_argument(
+ '--testrunner', action='store', dest='testrunner',
help='Tells Django to use specified test runner class instead of '
- 'the one specified by the TEST_RUNNER setting.')
- parser.add_argument('--liveserver',
- action='store', dest='liveserver', default=None,
+ 'the one specified by the TEST_RUNNER setting.',
+ )
+ parser.add_argument(
+ '--liveserver', action='store', dest='liveserver', default=None,
help='Overrides the default address where the live server (used '
'with LiveServerTestCase) is expected to run from. The '
- 'default value is localhost:8081-8179.')
+ 'default value is localhost:8081-8179.',
+ )
test_runner_class = get_runner(settings, self.test_runner)
diff --git a/django/core/management/commands/testserver.py b/django/core/management/commands/testserver.py
index a241283ce2..223a045f7c 100644
--- a/django/core/management/commands/testserver.py
+++ b/django/core/management/commands/testserver.py
@@ -9,15 +9,22 @@ class Command(BaseCommand):
requires_system_checks = False
def add_arguments(self, parser):
- parser.add_argument('args', metavar='fixture', nargs='*',
- help='Path(s) to fixtures to load before running the server.')
- parser.add_argument('--noinput', '--no-input',
- action='store_false', dest='interactive', default=True,
- help='Tells Django to NOT prompt the user for input of any kind.')
- parser.add_argument('--addrport', default='',
- help='Port number or ipaddr:port to run the server on.')
- parser.add_argument('--ipv6', '-6', action='store_true', dest='use_ipv6', default=False,
- help='Tells Django to use an IPv6 address.')
+ parser.add_argument(
+ 'args', metavar='fixture', nargs='*',
+ help='Path(s) to fixtures to load before running the server.',
+ )
+ parser.add_argument(
+ '--noinput', '--no-input', action='store_false', dest='interactive', default=True,
+ help='Tells Django to NOT prompt the user for input of any kind.',
+ )
+ parser.add_argument(
+ '--addrport', default='',
+ help='Port number or ipaddr:port to run the server on.',
+ )
+ parser.add_argument(
+ '--ipv6', '-6', action='store_true', dest='use_ipv6', default=False,
+ help='Tells Django to use an IPv6 address.',
+ )
def handle(self, *fixture_labels, **options):
verbosity = options['verbosity']
diff --git a/django/core/management/templates.py b/django/core/management/templates.py
index 1cd06d101a..df522e809c 100644
--- a/django/core/management/templates.py
+++ b/django/core/management/templates.py
@@ -51,18 +51,20 @@ class TemplateCommand(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('name', help='Name of the application or project.')
parser.add_argument('directory', nargs='?', help='Optional destination directory')
- parser.add_argument('--template',
- help='The path or URL to load the template from.')
- parser.add_argument('--extension', '-e', dest='extensions',
+ parser.add_argument('--template', help='The path or URL to load the template from.')
+ parser.add_argument(
+ '--extension', '-e', dest='extensions',
action='append', default=['py'],
help='The file extension(s) to render (default: "py"). '
'Separate multiple extensions with commas, or use '
- '-e multiple times.')
- parser.add_argument('--name', '-n', dest='files',
+ '-e multiple times.'
+ )
+ parser.add_argument(
+ '--name', '-n', dest='files',
action='append', default=[],
- help='The file name(s) to render. '
- 'Separate multiple extensions with commas, or use '
- '-n multiple times.')
+ help='The file name(s) to render. Separate multiple extensions '
+ 'with commas, or use -n multiple times.'
+ )
def handle(self, app_or_project, name, target=None, **options):
self.app_or_project = app_or_project