The instances therefore consist of:
/home/roundup/issue_tracker/
__init__.py
instance_config.py
select_db.py
dbinit.py
interfaces.py
db/
html/
detectors/
The roundup library code, when asked to do something, is passed the
instance_home "/home/roundup/issue_tracker". It does:
path, instance = os.path.split(instance_home)
sys.path.insert(0, path)
try:
instance = __import__(instance)
finally:
del sys.path[0]
Of course, the fatal flaw with all this is that if "instance" (the string) is
the same name as an existing imported module, we're stuffed. An early adopter
tried "roundup" with obvious consequences ;)
So what I need to know is if there is some way to import the instance_home
package as "instance" rather than as "roundup".
Any advice appreciated...
Richard
This looks like a lost cause (*). It's just plain too icky :(
Oh well.
Richard
* even if I manage to convince the import mechanisms to import /tmp/roundup
as "instance", there's imports in the /tmp/roundup package "from roundup
import foo" which are always going to break. Ho hum.
Hey, this is a fun conversation I'm having with myself here :)
The above comment was written because I was doing:
>>> import imp, sys
>>> sys.path.insert(0,'/tmp')
>>> imp.load_module('instance', None, '/tmp/roundup', ('', '', 5))
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "./roundup/templates/classic/__init__.py", line 9, in ?
from interfaces import *
File "./roundup/templates/classic/interfaces.py", line 6, in ?
from roundup import cgi_client, mailgw
ImportError: cannot import name cgi_client
... but further investigation shows that the "sys.path.insert(0,'/tmp')" is
not needed...
>>> import imp, sys
>>> imp.load_module('instance', None, '/tmp/roundup', ('', '', 5))
<module 'instance' from '/tmp/roundup/__init__.pyc'>
>>> sys.modules['roundup']
<module 'roundup' from 'roundup/__init__.pyc'>
Yay! :)
Sorry for the noise :)
Richard
On Fri, 3 Aug 2001, Richard Jones wrote:
> Hey, this is a fun conversation I'm having with myself here :)
I'm glad you're enjoying it.
I haven't been able to get a word in, myself!
> >>> import imp, sys
> >>> imp.load_module('instance', None, '/tmp/roundup', ('', '', 5))
> <module 'instance' from '/tmp/roundup/__init__.pyc'>
> >>> sys.modules['roundup']
> <module 'roundup' from 'roundup/__init__.pyc'>
There's also:
imp.load_package( name, path )
( which doesn't appear to be in the documentation. )
You might also want to add:
sys.modules['instance'] = instance
But I'm not quite sure what you're doing, so maybe not.
What is 'roundup' ?
-- Steve Majewski
Thanks for the following anyway :)
> > >>> import imp, sys
> > >>> imp.load_module('instance', None, '/tmp/roundup', ('', '', 5))
> >
> > <module 'instance' from '/tmp/roundup/__init__.pyc'>
> >
> > >>> sys.modules['roundup']
> >
> > <module 'roundup' from 'roundup/__init__.pyc'>
>
> There's also:
>
> imp.load_package( name, path )
>
> ( which doesn't appear to be in the documentation. )
And does work, and is much cleaner. Thanks!
> You might also want to add:
>
> sys.modules['instance'] = instance
No, I just need the instance in the local namespace, so this isn't necessary.
> What is 'roundup' ?
It's my implementation of Ping's software carpentry submission :)
http://roundup.sourceforge.net/
Richard
On Thu, 2 Aug 2001, I absentmindedly wrote:
>
> You might also want to add:
>
> sys.modules['instance'] = instance
>
Nevermind!
I forgot that your original problem was when instance is
already another module name.
If the names are not going into sys.modules, then I must assume
that they are only going to be imported once. (True?)
-- Steve Majewski
I currently can't think of a situation where the instance would be imported
more than once.
I just tested multiple imports anyway, and it seemed to work ok...
Richard
Richard Jones wrote:
> In the roundup project, I (possibly foolishly) decided to make the
> roundup instances python packages.
I'd quibble with that "possibly" :-).
[snip]
> The roundup library code, when asked to do something, is passed the
> instance_home "/home/roundup/issue_tracker". It does:
>
> path, instance = os.path.split(instance_home)
> sys.path.insert(0, path)
> try:
> instance = __import__(instance)
> finally:
> del sys.path[0]
Which means that roundup will not work with freeze, mac's
BuildApplication, Installer or py2exe.
If these roundup extensions (is that a fair characterization?)
were installed as subpackages of roundup, then they might be
workable.
Your later post (using imp.load_module or imp.load_package) is
pure poison for these tools.
Don't know anything about imp.load_package, but imp.load_module
is sort of equivalent to:
if sys.modules.has_key('mymodule'):
reload(mymodule)
else:
import mymodule
so I'd be careful of side effects in normal Python, too.
- Gordon
They're not extensions, they're working instances of roundup.
There's two separate components of a roundup installation: the software and
one or more instances. The software is installed in site-packages, and is a
standard python package. It contains all the core functionality, and the
"templates" for making instances. Instances contain the actual data that is
created when you use roundup. Further, it contains the schema for that data
and view information. This is done using python modules that extend the basic
software, allowing high levels of site customisation. The instances would
never be packaged up for transport like the software would, so I don't
believe that there's an issue with freeze etc.
The instance-as-package idea has worked well so far, with some glitches to do
with working with python's import mechanisms. I'm not sure how we could have
achieved the same level of flexibility using any other scheme. I'm completely
open to suggestions though.
Richard
ps. does the above make sense? If it does, I'll insert it, or something like
it, into the README.