From 6e1c9c6568c405bfa481dda4249abe2960173547 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Fri, 2 Jan 2015 17:58:58 +0100 Subject: [PATCH] Fixed #8280 -- Allowed management command discovery for eggs Thanks jdetaeye for the report, bhuztez and jdetaeye for the initial patches, Tim Graham and Berker Peksag for the reviews. --- django/core/management/__init__.py | 10 +++++----- docs/releases/1.8.txt | 2 ++ tests/user_commands/eggs/basic.egg | Bin 0 -> 3465 bytes tests/user_commands/tests.py | 17 +++++++++++++++-- 4 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 tests/user_commands/eggs/basic.egg diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index b88026a335..a0c86024b9 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -3,6 +3,7 @@ from __future__ import unicode_literals import collections from importlib import import_module import os +import pkgutil import sys import django @@ -24,11 +25,10 @@ def find_commands(management_dir): Returns an empty list if no commands are defined. """ command_dir = os.path.join(management_dir, 'commands') - try: - return [f[:-3] for f in os.listdir(command_dir) - if not f.startswith('_') and f.endswith('.py')] - except OSError: - return [] + # Workaround for a Python 3.2 bug with pkgutil.iter_modules + sys.path_importer_cache.pop(command_dir, None) + return [name for _, name, is_pkg in pkgutil.iter_modules([command_dir]) + if not is_pkg and not name.startswith('_')] def load_command_class(app_name, name): diff --git a/docs/releases/1.8.txt b/docs/releases/1.8.txt index b69e69db49..d6e139606d 100644 --- a/docs/releases/1.8.txt +++ b/docs/releases/1.8.txt @@ -371,6 +371,8 @@ Management Commands * Database connections are now always closed after a management command called from the command line has finished doing its job. +* Commands from alternate package formats like eggs are now also discovered. + * :djadmin:`dumpdata` now has the option :djadminopt:`--output` which allows specifying the file to which the serialized data is written. diff --git a/tests/user_commands/eggs/basic.egg b/tests/user_commands/eggs/basic.egg new file mode 100644 index 0000000000000000000000000000000000000000..cb25c6d8cf03c65d0fb274e5e26ad0db9b9b305f GIT binary patch literal 3465 zcmb7{2~3k`7{@>8K~W&M(SlQk9Ay?-ikP`z9D-1#Ek`NGhE9;0f*=Bxg zb7wC>X7Az)X`(nDJS$@=$(1MqpKJnQkilWU>($F(8Z(GVW!|u4)7&nrdmFi)H&)+$ z!Bz*K;|5;t)dZ{A%;3=B4L@3X;7V*GH&Y5GrBf5dQyJ2S!?lk|F106|3YN3kUN3&Q zGSPCfS*GwNgjK5_-Z&rclIC$z)y+`g$lF@C<(YWP$ovULGhqp;rqff)j#>hBi$Rb; z=w6~YT^O4ROW;&(E7*D|=%!rcaPyKuVhIRa5DDpNX>p*HNlEnBSiXQSj*ayYN)r;^ zsC$TwZ|ZhoL~0jgZU+U$o7#VsAA*&}!exHTX}MH41OaB$J|0k#~73q&37A zB8m5$=Q?@v(WA-kiRNaRl(K@Coz08kF|*Id_`&98oa$h~9u`03lzrE$_zFI%x?B4+ zIXLjLn?Mi^#igYu!l@#yw9}l6AswC;S%yGk%8ST zHM_T;&E$5eXofe4b)?dFE85$TXzS$l%i4A%}Rlan(|P;ZmEzg_?XHN~@4N%-)N zw=Z)Za|X?G&Z2oK()xEpR;e4Zk@$)*gsduI*}4{5!4|EVECcZ=2t>1HWQ8NU!Cl!C zM59M_1=3i34+fFvNlOC&$W;3UJlX?^pdro^2BAUg#SX8wQZvD)!|mj&*CbNRC5nkrkFL< z*(G`+6lawpNM zTOjMLF~iv(>ctp#;l0Q|;5)DjCnqoWy`Gx+GMpvij`~VS`A;Fl6i88RaQnD))Cn*# zwZY7N9|5?xk1|*LO}E$(w-XNAkbu4(yvv6mWo{#qVC=H+A(VFW&pgW9=io=3n3Q|pck+n@{1uvw^j@g z#&(e&@fWztA#~^vXc6eWp(kWu4G1%KZJ@!J#p?+KoKXT&f-zUu1ELH8hzUnBjCs7C zQEJGT!|{tO4s=iZ-@_7U5KL