On 6 avr, 13:23, Jonathan Lundell <jlund...@pobox.com> wrote:
> How about this, as a means of adding the app-specific modules/ to sys.path: 
> in a thread-local object 'localthing', store the path to the current 
> application's modules/ directory in something.modules.
>
> Subclass str thus:
>
> class LocalModules(str):
>   def __str__(self):
>     return str(localthing.modules)
>
> In the web2py startup logic:
>
> sys.path.append(LocalModules("modules")) # the value isn't important, though 
> it could be used to generalize this construct
>
> In the web2py request logic:
>
> something.modules = <path to current application's modules directory>
>
> This could be generalized somewhat by having LocalModules get the real string 
> ("modules" in this example) from super, and fetch the attribute of that name 
> from localthing.

No, this will not work. sys.path takes string. We can had a marker
like "__modules__" in sys.path then we add a Python loader in
sys.path_hooks for the marker. The new Python loader will read the
thread local variable from web2py (could be bended pretty much
anywhere). But I think this solution would be more complex then the
previous one I just described.

Reply via email to