Closed vsajip closed 1 year ago
It's not recommended practice to configure logging from a library - it should be only done by an application. I think it is out of place in init.py.
Indeed, I'm surprised nobody's raised this earlier. Thanks.
Conversely, main.py is supposed to be provided as a means of e.g. running code when you do python -m lunr, but that doesn't work because it contains only function definitions, and moreover it's imported by init.py.
I wasn't aware of this convention, is there a place where these are laid out or is it just common knowledge? Could you provide an example?
is there a place where these are laid out or is it just common knowledge?
It's documented here. See also this Stack Overflow thread.
TIL, thank you.
Other differences from convention:
__version__
is used rather than __VERSION__
.__init__.py
, it's perfectly OK to have sizeable amounts of code in it (examples: venv
, logging
packages in the stdlib have most of their core functionality in __init__.py
). You could just move the stuff in your __main__.py
to __init__.py
and that wouldn't IMO be controversial.Thanks for this project, by the way. I maintain some static sites using the Nikola static site generator and have just started looking at client-side search support using lunr.js
, so it's useful to be able to build the index using Python as part of the static site workflow!
That's great to hear, I'm glad you find it useful 🙂
It's not recommended practice to configure logging from a library - it should be only done by an application. I think it is out of place in
__init__.py
. https://github.com/yeraydiazdiaz/lunr.py/blob/f5876a968adaaa24c2076b1084f86aee9f24c51e/lunr/__init__.py#L7Conversely,
__main__.py
is supposed to be provided as a means of e.g. running code when you dopython -m lunr
, but that doesn't work because it contains only function definitions, and moreover it's imported by__init__.py
.These usages are unconventional/not normal practice.