Directory Service Providers need to be instantiated

Martin Pool mbp at canonical.com
Mon Sep 27 07:58:34 BST 2010


On 25 September 2010 01:20, Glen Mailer <glenjamin at gmail.com> wrote:
> Hi guys,
>
> This is a fairly obscure thing, but here goes:
>
> bzrlib.directory_service.DirectoryServiceRegistry.dereference does the
> following:
>
> return service().look_up(name, url)
>
> This means that any directory service has to be a callable which when
> called provides an object with a look_up method.
>
> This is rather odd IMO, and also means that every call to dereference
> will instantiate an object which gets thrown away.
> As the constructor is never passed any arguments, I can't see any
> advantages to this approach.
>
> The reason I cane across this and found the behaviour prohibiting is
> for the following (draft) plugin: lp:~glenjamin/+junk/bzr-shortcuts
>
> I had to resort to a dodgy __call__ hack since I didn't really want to
> create a whole bunch of classes to do exactly the same thing.
>
> Anyway, any thoughts?

I agree, that is a little strange: why not just put in objects which
will themselves provide a lookup() call, or for that matter why not
just register callables that can be passed (name, url) directly.

It's probably done that way because whoever first added it wanted to
register classes, have them constructed without arguments, then to
return lookup.

fwiw it seems to me you could just register the BazaarDirectoryFactory
class for every name, then have it examine the arguments in lookup()?

http://bazaar.launchpad.net/~glenjamin/%2Bjunk/bzr-shortcuts/annotate/head:/__init__.py


-- 
Martin



More information about the bazaar mailing list