On Thu, Dec 4, 2008 at 2:43 PM, Alec Warner <[EMAIL PROTECTED]> wrote:
> <nitpick feel free to ignore me>
> Don't put stuff in __init__.py.
>
> Make a file called equery (no .py) and do all the work in the modules
> you import; eg.
>
> from equery import driver
>
> if __name__ == "__main__":
>  driver.Run()
>
> Then put all this code in driver.py (option parsing, signal handling,
> etc...).  Don't try to hide the code in __init__.py; it confuses
> people who are trying to figure out what the module is for (since
> __init__.py has very specific duties in declaring what is in the
> module when you inspect the query module).  Putting the code in a file
> named 'driver.py' or similarly makes it pretty obvious (to me anyway)
> what the code in that file is for (to drive a program).
>
> Does that make sense or am I full of crap?

I see what you're saying, but using a second file, driver.py, just to
do __init__.py's job seems even more confusing. __init__.py is the
standard python constructor, and it's required to be in every module
directory, if I understand correctly. Since you have to have an
__init__.py file in the directory, which gets sourced anyway, it might
as well be used for what it's meant for, which is handling all the
initial setup of the package. If I'm misunderstanding the purpose of
__init__, please let me know.

So two best ways I can think to set it up are:
1) /usr/bin/equery only import equery from /usr/lib/gentoolkit/equery.
__init__.py in that dir runs all the setup work and handles input args
(this is quite common), and imports and runs the requested module.
This is a similar setup used by something like iotop.

or

2) /usr/bin/equery contains all the init stuff and opt handling, then
imports the separate modules as needed. This style is used by
something like pybugz, although you still have to have an __init__.py
in the module folder, it can be a lot sparser.

I was leaning toward #1 because it keeps all the code in the same directory.

>>
>> A little RFC:
>> 1) Spaces or tabs? Python standard is spaces, Gentoo seems to be
>> predominantly tabs. I personally like to use spaces when I'm writing
>> Python, but if that would annoy everyone later on, I'll stick to tabs.
>
> Gentoo has no official coding standards.  I'd personally prefer spaces
> (along with basically everything else in the Google Python Style
> Guide[1]), but I'm probably not going to nitpick.  It is my opinion
> that tabs are used because that is what the tools were written in and
> it is annoying to change from tabs to spaces ;)
>
> [1] http://code.google.com/p/soc/wiki/PythonStyleGuide
>

I'm with you there, I really like that style guide as well. We should
adopt it :)

-Doug

Reply via email to