On 5 avr, 22:38, pbreit <pbreitenb...@gmail.com> wrote:
> Applications are totally discrete so there would be no chance of a collision
> (if I understand correctly).
>
> app1
>     modules
>         mypackage1
>
> app2
>     modules
>         mypackage2
>
> Nothing in app1 knows about anything app2 (and vice versa).

The 'modules' directory is not in the Python path so we have to use
local_import to load them.

The applications are not so discrete because they share the same
process and the same modules.

I found that I cannot import from a package to get a module in another
package in the same "modules" directory if I don't use a relative
import. So I do:

import sys

if sys.argv[0] != "web2py.py":
    import p2
else:
    from .. import p2

This way my module will use an absolute import, the Python
recommendation, if used outside of web2py and a relative import when
used in web2py.

But the Pydev static analyzer is giving me an error. This looks like a
bug because the code is working well.

>
> If you don't want to maintain two copies of the same code, you could put it
> in "site-packages" in the "web2py" directory. That folder is accessible by
> any of your apps.

Yes but I would like my applications to be self-contain so I prefer to
use the "modules" directory.

Reply via email to