From f8e080c866fe1bf55df89a62b2dcca55e3d1256b Mon Sep 17 00:00:00 2001 From: "Ilya.Kazakevich" Date: Wed, 3 Aug 2016 19:48:39 +0300 Subject: [PATCH] Supporting API changes in Django 1.10 * Since Django 1.10 there is no optparse (and no .args field) and no "usage()" method. All django manage py test failed. --- .../_parser/parser.py | 37 +++++++++++++++---- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/python/helpers/pycharm/django_manage_commands_provider/_parser/parser.py b/python/helpers/pycharm/django_manage_commands_provider/_parser/parser.py index be82b946c1cd..cf9cd365e32a 100644 --- a/python/helpers/pycharm/django_manage_commands_provider/_parser/parser.py +++ b/python/helpers/pycharm/django_manage_commands_provider/_parser/parser.py @@ -46,7 +46,7 @@ def report_data(dumper, commands_to_skip): if command_name in commands_to_skip: sys.stderr.write("Skipping command '{0}' due to config\n".format(command_name)) continue - + fetcher = _Fetcher(utility, command_name) fetcher.daemon = True fetcher.start() @@ -62,11 +62,14 @@ def report_data(dumper, commands_to_skip): command_name)) sys.exit(1) - use_argparse = False - try: - use_argparse = command.use_argparse - except AttributeError: - pass + # There is no optparse in 1.10 + if _is_django_10(): + use_argparse = True + else: + try: + use_argparse = command.use_argparse + except AttributeError: + pass try: parser = command.create_parser("", command_name) @@ -74,9 +77,27 @@ def report_data(dumper, commands_to_skip): sys.stderr.write("Error parsing command {0}: {1}\n".format(command_name, e)) continue + try: # and there is no "usage()" since 1.10 + usage = command.usage("") + except AttributeError: + usage = command.help + dumper.start_command(command_name=command_name, - command_help_text=VersionAgnosticUtils().to_unicode(command.usage("")).replace("%prog", - command_name)) + command_help_text=VersionAgnosticUtils().to_unicode(usage).replace("%prog", + command_name)) module_to_use = _argparse if use_argparse else _optparse # Choose appropriate module: argparse, optparse module_to_use.process_command(dumper, command, parser) dumper.close_command() + + +def _is_django_10(): + """ + + :return: is Django >= 1.10 + """ + try: + from distutils.version import StrictVersion + import django + return StrictVersion(django.get_version()) >= StrictVersion("1.10") + except (ImportError, AttributeError): + return False