← Back to team overview

launchpad-dev team mailing list archive

HOWTO Avoid circular dependencies (at least some of them)

 

I was just talking with Robert about this, and I realised that I probably 
haven't brought this to the attention of everyone yet.

You may have noticed that recently, particularly in lp.code, that enums and 
errors have their own module.

The primary reason for this is to reduce circular dependencies.

In a number of places in the code we need an enum, or error.  Often these have 
been in a related interfaces file.  However the interfaces file also brings in 
all sorts of other unrelated bits and pieces that have nothing to do with the 
enum or error we need, and can cause circular dependencies.

Since enums and errors have no other dependencies other than lazr.enum and 
Exception (most of the time) we can be pretty safe importing them without 
worrying what else is going to be imported by the interpreter.

This is one reason why in a number of scripts we have to have a line like:
  import canonical.launchpad.interfaces

The only reason for this is to control the order of imports of a pile of 
things.  Without it, we get stuck in some circular import problems (as I found 
with my recent branch).

So...

ACTION:
	Create modules in your application that follow the "lp.code" example.  
I've already done one or two.
  lp.<app>.enums.py
  lp.<app>.errors.py

Put things in there, and change the imports.

You'll feel better once that's done.

Tim