I am trying to implement a python build package and functional testing package for our internal software development processes. My primary goal is to implement a global/standard logger (similar to the reference here) and argparser that all modules will use from within their perspective packages (i.e. the build logger and parser will differ from the test suite logger and parser).
Should this be done in __init__.py of the package? Are there any other methods to achieve this? I have yet to see what the real need for __init__.py is? Perhaps, this answered my own question?
I have written numerous python modules and other apps, but never packages/libraries. This concept seems to introduce new possibilities for me, such as standardizing these processes.
Basically, to summarize, my goals for these packages are:
1.) Eliminate the need for redundant passing/parsing of long lists of arguments and/or accessing the system environment.
2.) Eliminate the myriad of outputs that we’ve seen in the past from varying tests and build scripts.
3.) Provide a self-documenting package that will be easy to use. Any advice on package documentation would be extremely useful, as well. 🙂
This will enable users of these packages to:
1.) Easily access a standard set of arguments. For example, every module in the package will (in order of precedence) parse command-line arguments with standard flags, load a config file, or use default values.
2.) Easily log errors, warnings, and debug statements in a standard way.
3.) As these test/build modules are passed around, this will ultimately enable “users” (i.e. someone who did not write the module) to run it in a universal way.
I suppose I am looking for some real “Pythonic” implementation advice because the variety of options and possibilities out there seem to be overwhelming. Thanks in advance.
For logging look no further than the python logging documentation. It is a very easy to implement logging system that is very flexible.
As to your question about
__init__.py, if you come from other programming languages, think of it as a constructor. If you want some default values assigned on load, then they should go into__init__.py.I am not very familiar with
argparse, so someone else may be able to shed some light on that.