Django

Code

Ticket #6587 (new)

Opened 8 months ago

Last modified 3 weeks ago

remove django.templates __path__ hacking

Reported by: oyvind Assigned to:
Milestone: post-1.0 Component: Template system
Version: SVN Keywords: path hacking remove
Cc: cgrady@the-magi.us Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 1

Description

As mentioned in VersionOneFeatures

I made a attempt at fixing it, posting git patch

Attachments

new_template_lib_loader.diff (2.8 kB) - added by oyvind on 02/12/08 10:15:25.
new template library loader
new_template_lib_loader_2.diff (3.3 kB) - added by oyvind on 02/12/08 12:45:30.
better error messages, no conflicting library names, better naming of variables
new_template_lib_loader_3.diff (3.4 kB) - added by oyvind on 02/13/08 07:19:47.
Do not walk subdirs in os.walk
new_template_lib_loader_4.diff (4.5 kB) - added by oyvind on 02/13/08 09:03:08.
get_library no longer uses django.templatetags.module
new_template_lib_loader_5.diff (5.1 kB) - added by oyvind on 02/28/08 10:41:39.
More use of import, tests pass
new_template_lib_loader_6.diff (4.5 kB) - added by oyvind on 02/29/08 04:23:14.
populate app_label in templatetags/init..py, import_library is own function
new_template_lib_loader_7.diff (5.0 kB) - added by oyvind on 03/19/08 12:10:49.
better naming of variables, some code fixes, added some docstrings
new_template_lib_loader_8.diff (4.6 kB) - added by oyvind on 06/16/08 12:24:13.
All tests pass
new_template_lib_loader_9.diff (4.5 kB) - added by oyvind on 06/16/08 17:46:59.
removed os import
new_template_lib_loader_10.diff (70.0 kB) - added by oyvind on 07/01/08 15:03:08.
fixed import to get the correct module, moved defaulttags and defaultfilters to avoid circular imports, fixes #6579
new_template_lib_loader_11.diff (134.6 kB) - added by oyvind on 07/01/08 15:15:27.
forgot to remove some files in the commit, again
new_template_lib_loader_12.diff (135.7 kB) - added by oyvind on 08/05/08 09:32:07.
new loader using imp, may need some cleaup, and decide if add_to_builtins should change, and if a import should use a list instead of the getattr solution
new_template_lib_loader_13.diff (135.6 kB) - added by oyvind on 08/05/08 10:49:51.
removed import using getattr
new_template_lib_loader_14.diff (135.0 kB) - added by oyvind on 08/06/08 09:24:57.
Final patch, i hope :)

Change History

02/12/08 10:15:25 changed by oyvind

  • attachment new_template_lib_loader.diff added.

new template library loader

02/12/08 12:45:30 changed by oyvind

  • attachment new_template_lib_loader_2.diff added.

better error messages, no conflicting library names, better naming of variables

02/13/08 07:19:47 changed by oyvind

  • attachment new_template_lib_loader_3.diff added.

Do not walk subdirs in os.walk

02/13/08 09:03:08 changed by oyvind

  • attachment new_template_lib_loader_4.diff added.

get_library no longer uses django.templatetags.module

02/13/08 09:37:06 changed by oyvind

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

all tests in runtests.py templates now pass

02/16/08 00:50:47 changed by Simon Greenhill <dev@simon.net.nz>

  • stage changed from Unreviewed to Ready for checkin.

02/18/08 12:44:10 changed by mtredinnick

  • needs_better_patch set to 1.
  • stage changed from Ready for checkin to Accepted.

A good start. Needs a little more tweaking, though.

Line 19 in the new version of templatetags/__init__.py can't be right. It looks like you're trying to replicate Python's import behaviour, but that's not the way to do it. I would be cautious of anything trying to do with this work without using at least some functions from Python's imp module. See below (the "Finally,..." paragraph) for more here: I feel a bit suspicious about the whole approach in this part of the code.

Lines 8 and 9 in the same file cry out for a better solution. One possible, probably for another ticket, is to add a "tags to load always" list in settings. This would help people who are poking into the builtin tags as well. We could add django.templatetags.* to that list.

Even simpler, and probably sufficient for the purposes of this ticket is to iterate over ['django'] + list(settings.INSTALLED_APPS). That avoids having some special list we have to remember to update if we add more tags in there.

Finally, the approach in get_library_names() looks complex. You're doing a lot of computation there in the hope of getting one hit on the returned dictionary when you try to load a tag. Is it possible to let Python do more of the work here. Loop over the list of directories (<app_name>+'.templatetags') and try appending what is being loaded to the end of that and importing. As soon as you don't get an import error, stop with success. That will also mean if you try to load the same template tags in multiple templates in the the same process, Python will just reuse the one already in memory, instead of walking all those directories again. Push less of the work down into get_library_names() and try to use Python's builtin import facilities (esp. __import__() a bit more.

02/22/08 16:30:28 changed by Collin Grady <cgrady@the-magi.us>

  • cc set to cgrady@the-magi.us.

02/28/08 10:41:39 changed by oyvind

  • attachment new_template_lib_loader_5.diff added.

More use of import, tests pass

02/29/08 04:23:14 changed by oyvind

  • attachment new_template_lib_loader_6.diff added.

populate app_label in templatetags/init..py, import_library is own function

03/19/08 12:10:49 changed by oyvind

  • attachment new_template_lib_loader_7.diff added.

better naming of variables, some code fixes, added some docstrings

06/16/08 12:24:13 changed by oyvind

  • attachment new_template_lib_loader_8.diff added.

All tests pass

06/16/08 12:27:55 changed by telenieko

#3349 talks about ImportError? in template loading.

06/16/08 12:36:52 changed by oyvind

This patch shows the tried modules, should the message be less specific, and ask about apps in INSTALLED_APPS as in #3349?

06/16/08 17:46:59 changed by oyvind

  • attachment new_template_lib_loader_9.diff added.

removed os import

06/17/08 05:45:27 changed by telenieko

I prefer to know the tried modules, just pointed out #3349 in case it gets invalidated whe this one gets in. But I doubt it now as I changed #3349 summary (as the patch fixed other places with obscure errors).

06/18/08 05:33:44 changed by oyvind

  • owner changed from nobody to oyvind.

06/18/08 05:36:08 changed by oyvind

  • status changed from new to assigned.
  • needs_better_patch deleted.

06/23/08 13:27:57 changed by ramiro

See also #6579 regarding the use of [''] as the 4th. parameter to ___init__() (with some notes from the Python developers advising against its use.)

07/01/08 15:03:08 changed by oyvind

  • attachment new_template_lib_loader_10.diff added.

fixed import to get the correct module, moved defaulttags and defaultfilters to avoid circular imports, fixes #6579

07/01/08 15:15:27 changed by oyvind

  • attachment new_template_lib_loader_11.diff added.

forgot to remove some files in the commit, again

08/05/08 09:32:07 changed by oyvind

  • attachment new_template_lib_loader_12.diff added.

new loader using imp, may need some cleaup, and decide if add_to_builtins should change, and if a import should use a list instead of the getattr solution

08/05/08 10:49:51 changed by oyvind

  • attachment new_template_lib_loader_13.diff added.

removed import using getattr

08/06/08 09:24:57 changed by oyvind

  • attachment new_template_lib_loader_14.diff added.

Final patch, i hope :)

08/14/08 01:32:26 changed by mtredinnick

  • owner changed from oyvind to mtredinnick.
  • status changed from assigned to new.

08/15/08 02:17:08 changed by Alex

  • milestone changed from 1.0 beta to post-1.0.

1.0 beta has shipped and this was not fixed, will be handled post-1.0.

08/15/08 09:14:58 changed by mtredinnick

  • milestone changed from post-1.0 to 1.0.

I realise people are only trying to help, but can we have a little restraint with triaging tickets off the feature list? Particularly when a maintainer is currently the assigned person. This is still on the 1.0 track. I can do it in a more-or-less backwards-compatible way, with luck.

09/02/08 07:16:40 changed by mtredinnick

  • owner deleted.
  • needs_better_patch set to 1.
  • milestone deleted.

09/26/08 18:48:52 changed by anonymous

  • milestone set to post-1.0.

Add/Change #6587 (remove django.templates __path__ hacking)




Change Properties
Action