byteflow: overriding 'compat' modules

4 views
Skip to first unread message

Ben Jackson

unread,
Dec 31, 2009, 7:49:54 PM12/31/09
to byteflow...@googlegroups.com
I'd like to use a newer py-wikimarkup (mainly because I've extended it
to support hooks for [[local]] links*). I can see how I'd modify apps/render
to wrap it and add my byteflow-centric hooks, but I am not sure what the
Right way is to avoid using compat/wikimarkup. I'm wondering if byteflow
should use an explicit list of compat modules in a settings file. I'm
not sure how that would work with python's 'import'.

[*] http://github.com/bjj/py-wikimarkup

import settings
from pytils.translit import slugify
from blog.models import Post

def byteflowLinkHook(parser_env, namespace, body):
(article, pipe, text) = body.partition('|')
slug = slugify(article.strip())
text = (text or article).strip()
try:
post = Post.objects.get(slug=slug)
href = post.get_absolute_url()
except Post.DoesNotExist:
href = '#'
return '<a href="%s">%s</a>' % (href, text)

registerInternalLinkHook(None, byteflowLinkHook)

--
Ben Jackson AD7GD
<b...@ben.com>
http://www.ben.com/

Alexander Solovyov

unread,
Jan 5, 2010, 7:24:29 AM1/5/10
to byteflow...@googlegroups.com
On 2010-01-01, Ben Jackson wrote:

> I'd like to use a newer py-wikimarkup (mainly because I've extended it
> to support hooks for [[local]] links*). I can see how I'd modify apps/render
> to wrap it and add my byteflow-centric hooks, but I am not sure what the
> Right way is to avoid using compat/wikimarkup. I'm wondering if byteflow
> should use an explicit list of compat modules in a settings file. I'm
> not sure how that would work with python's 'import'.

Surely render application is not very extensible, I'll think about
this. But... is there any downsides in usage of new py-wikimarkup? Maybe
we just need to replace old with this one?

--
Alexander

Ben Jackson

unread,
Jan 5, 2010, 1:38:28 PM1/5/10
to byteflow...@googlegroups.com
On Tue, Jan 05, 2010 at 02:24:29PM +0200, Alexander Solovyov wrote:
> On 2010-01-01, Ben Jackson wrote:
>
> > I'd like to use a newer py-wikimarkup (mainly because I've extended it
> > to support hooks for [[local]] links*).
>
> Surely render application is not very extensible, I'll think about
> this. But... is there any downsides in usage of new py-wikimarkup? Maybe
> we just need to replace old with this one?

Maybe I should. At the moment I've just moved 'compat' to the end of
the python path so it acts as a backup for missing packages rather than
an override. If 'compat' is intended to be like the Rails 'vendor'
directory that is the wrong idea.

Alexander Solovyov

unread,
Jan 5, 2010, 4:24:51 PM1/5/10
to byteflow...@googlegroups.com
On 2010-01-05, Ben Jackson wrote:

>> Surely render application is not very extensible, I'll think about
>> this. But... is there any downsides in usage of new py-wikimarkup? Maybe
>> we just need to replace old with this one?

> Maybe I should. At the moment I've just moved 'compat' to the end of
> the python path so it acts as a backup for missing packages rather than
> an override. If 'compat' is intended to be like the Rails 'vendor'
> directory that is the wrong idea.

Hm, probably. There was an idea that 'compat' contains modules which are
known to work, but I'm not in favor of it right now.

--
Alexander

Alexander Solovyov

unread,
Jan 8, 2010, 3:36:55 AM1/8/10
to byteflow...@googlegroups.com
On 2010-01-05, Ben Jackson wrote:

> Maybe I should. At the moment I've just moved 'compat' to the end of
> the python path so it acts as a backup for missing packages rather than
> an override. If 'compat' is intended to be like the Rails 'vendor'
> directory that is the wrong idea.

Hmm... probably. Then it should be .append'ed to a sys.path instead of
.insert'ion. I'll change that.

--
Alexander

Ben Jackson

unread,
Jan 8, 2010, 12:17:16 PM1/8/10
to byteflow...@googlegroups.com

Since settings.py gets executed multiple times (the DEBUG print in
settings_local makes that obvious) I actually did this:

def addpath(where, path):
if not os.path.isabs(path):
path = os.path.join(PROJECT_ROOT, path)
if path not in sys.path:
sys.path.insert(where, path)

addpath(0, 'apps')
addpath(-1, 'compat')

and after local is loaded, a new hook:

try:
for path in ADDITIONAL_PATHS:
addpath(0, path)
except NameError:
pass

Alexander Solovyov

unread,
Jan 10, 2010, 3:59:19 PM1/10/10
to byteflow...@googlegroups.com
On 2010-01-08, Ben Jackson wrote:

>>> Maybe I should. At the moment I've just moved 'compat' to the end of
>>> the python path so it acts as a backup for missing packages rather than
>>> an override. If 'compat' is intended to be like the Rails 'vendor'
>>> directory that is the wrong idea.

>> Hmm... probably. Then it should be .append'ed to a sys.path instead of
>> .insert'ion. I'll change that.

> Since settings.py gets executed multiple times (the DEBUG print in
> settings_local makes that obvious) I actually did this:

Huh, really? That's news for me. :-( Anyway, I'll wait with this change
to thought about and play with yml's developments.

--
Alexander

Ben Jackson

unread,
Jan 10, 2010, 4:45:17 PM1/10/10
to byteflow...@googlegroups.com
On Sun, Jan 10, 2010 at 10:59:19PM +0200, Alexander Solovyov wrote:
>
> > Since settings.py gets executed multiple times (the DEBUG print in
> > settings_local makes that obvious) I actually did this:
>
> Huh, really? That's news for me. :-( Anyway, I'll wait with this change
> to thought about and play with yml's developments.

I think it has to do with the way django.conf works. Something like
manage.py imports settings directly (via implicit . in path) and then
the DJANGO_SETTINGS_MODULE env is used in django.conf. It doesn't
matter if you only set constants but it becomes and issue if your
setttings.py has side effects. I don't know where the 4x issue comes
from, but I've seen the DEBUG print come out 4 times.

Alexander Solovyov

unread,
Jan 10, 2010, 4:52:39 PM1/10/10
to byteflow...@googlegroups.com
On 2010-01-10, Ben Jackson wrote:

>>> Since settings.py gets executed multiple times (the DEBUG print in
>>> settings_local makes that obvious) I actually did this:

>> Huh, really? That's news for me. :-(

> I think it has to do with the way django.conf works. Something like


> manage.py imports settings directly (via implicit . in path) and then
> the DJANGO_SETTINGS_MODULE env is used in django.conf. It doesn't
> matter if you only set constants but it becomes and issue if your
> setttings.py has side effects. I don't know where the 4x issue comes
> from, but I've seen the DEBUG print come out 4 times.

Hah, magic, welcome to our lives. :\ Ok, thanks, I'll remember that.

--
Alexander

Yuri Baburov

unread,
Jan 10, 2010, 8:04:48 PM1/10/10
to byteflow...@googlegroups.com
Hey guys.

All's simple:

if python manage.py runserver is called, settings.py is executed 4 times,
in production or any other command, settings.py is executed 2 times.
First double is because of "auto-reload" feature.
Second is because of "import settings" once & "import myblog.settings"
once if your django project is called "myblog".
I raised this issue few times at django-dev, it seems no one cares.

--
Best regards, Yuri V. Baburov, ICQ# 99934676, Skype: yuri.baburov,
MSN: bu...@live.com

Reply all
Reply to author
Forward
0 new messages