Import question

Andrew Degtiariov andrew.degtiariov at gmail.com
Fri Feb 5 11:21:47 EST 2010


Code of our project has split into several packages and we deploy the
project using buildout.
All worked fine until I need to dynamically inspect python modules.

Here is structure of our src directory


├───project.api.config
│   ├───project
│   │   └───api
│   │       └───config
│   │           └───settings
│   └───project.api.config.egg-info
├───project.api.contacts
│   ├───project
│   │   └───api
│   │       └───contacts
│   │           ├───importer
│   │           └───views
│   └───project.api.contacts.egg-info
├───project.api.core
│   ├───project
│   │   └───api
│   │       └───core
│   │           ├───js
│   │           ├───lib
│   │           ├───management
│   │           │   └───commands
│   │           ├───middleware
│   │           ├───sessions
│   │           └───users
│   └───project.api.core.egg-info


Buildout by itself generates bin/python which look like:
import sys

sys.path[0:0] = [
  'c:\\users\\ad\\project\\src\\project.api.core',
  'c:\\users\\ad\\project\\src\\project.api.config',
  'c:\\users\\ad\\project\\src\\project.api.contacts',
  'c:\\users\\ad\\project\\eggs\\lockfile-0.8-py2.6.egg',
  'c:\\users\\ad\\project\\parts\\django',
  'c:\\users\\ad\\project\\eggs\\web.py-0.33-py2.6.egg',
....

Regular code like "import project.api.config" worked fine, but now I'm tryed
__import__('project.api.config'):

$ bin/python

>>> import project.api.config
>>> __import__('project.api.config')
<module 'project from
'c:\users\ad\project\src\project.api.contacts\project\__init__.pyc'>
>>>

What's wrong?
Ok, I'm trying imp:
>>> import imp
>>> imp.find_module('project.api.config')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No module named project.api.config
>>> import sys
>>> sys.path[1]
'c:\\users\\ad\\project\\src\\project.api.config'
>>> imp.find_module('project.api.config', sys.path[1])
Traceback (most recent call last):
  File "<console>", line 1, in <module>
ImportError: No frozen submodule named
c:\users\ad\project\src\project.api.config.project.api.config
>>>

There is setup.py for project.api.config:

import os
from setuptools import setup, find_packages

name = "project.api.config"
install_requires = [
        'zc.buildout',
        'setuptools',
        'web.py>=0.33',
        'project.api.core',
        'Django>=1.1.0',
        'lockfile'
]

if sys.platform != 'win32':
    install_requires.append('python-daemon')

setup(
    name = name,
    version = "1.0",
    author = "Andrew Degtiariov",
    author_email = "andrew.degtiariov at gmail.com",
    description = "...",
    license = "Commercial",
    packages=find_packages(os.path.dirname(__file__), exclude=['ez_setup']),
    namespace_packages=['project, 'project.api'],
    include_package_data=True,
    zip_safe=False,
    install_requires = install_requires
)

What's wrong? We really need to split the code for several eggs and want
that all of our package's names starts from 'project.api'

--
Andrew Degtiariov
DA-RIPE
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100205/06fe1f2a/attachment.html>


More information about the Python-list mailing list