Skip to content

site dirs may be a better solution #1

@craynic

Description

@craynic

I found it very ugly to do this tricky work.
What this package does is to check the init.py when importing EVERY package, If the file does not exist (means it may be a namespaced package), it creates the file. Many problems come with it.

  1. The package dir may not be writable, which will cause an IOError, and further an ImportError. This makes it failed to import the package, and very hard to debug.
  2. It will search the dirs that is not a package. For example, usr/lib/python2.7/config.
  3. It produced error when importing pycrypto in my environment. I don't know why.

I suggest to use sitedir to import namespaced packages. When calling plugin code, plugin site dirs will be inserted into PYTHONPATH in dispatch module, we can just add the two dirs to sitedir in plugin __init__.py. Python will look for the .pth files in site dirs and make it possible to import namespaced packages.
Example:

import sys
import site
site.addsitedir(sys.path[0])
site.addsitedir(sys.path[1])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions