[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: modules, require, magic
- From: Matthew Wild <mwild1@...>
- Date: Sun, 23 Oct 2011 16:03:40 -0400
On 23 October 2011 15:36, Sam Roberts <vieuxtech@gmail.com> wrote:
>
> I actually started using a lint tool for python, because it doesn't
> have a way to make libs like logging globally available across an
> entire app, you have to import it everywhere you use it. (actually, it
> probably does have a way to do this, but would involve doing things to
> the core that would be frowned upon by pythonistas everywhere)
>
> I got tired of integration tests failing because I'd put calls to
> logging.debug() in some code, and forget to add the import, so for the
> first time ever with a dynamic language, I found a lint tool and
> started using it. I feel its a failing in python that I'd not like lua
> to repeat. And its sucked valuable time from me, our integration tests
> take a long time to run and get back to us with a "you forgot to
> import logging, try again" message.
>
I've done this before:
setmetatable(_ENV or _G, {
__index = function (env, modulename)
local ok, module = pcall(require, modulename);
if ok then
rawset(env, modulename, module);
return module;
end
end;
})
I consider it a little hacky, but that's largely subjective (similar
to module() setting globals, but at least the end developer has a
choice here).
Regards,
Matthew
- References:
- modules, require, magic, Eduardo Ochs
- Re: modules, require, magic, Javier Guerra Giraldez
- Re: modules, require, magic, Petite Abeille
- Re: modules, require, magic, Sam Roberts
- Re: modules, require, magic, David Manura
- Re: modules, require, magic, Mark Hamburg
- Re: modules, require, magic, Mark Hamburg
- Re: modules, require, magic, Sam Roberts