yeraydiazdiaz / lunr.py

A Python implementation of Lunr.js 🌖
http://lunr.readthedocs.io
MIT License
187 stars 16 forks source link

Logging is configured in __init__.py and __main__.py has no runnable code (just function definitions) #119

Closed vsajip closed 1 year ago

vsajip commented 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. https://github.com/yeraydiazdiaz/lunr.py/blob/f5876a968adaaa24c2076b1084f86aee9f24c51e/lunr/__init__.py#L7

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.

These usages are unconventional/not normal practice.

yeraydiazdiaz commented 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?

vsajip commented 1 year ago

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.

yeraydiazdiaz commented 1 year ago

TIL, thank you.

vsajip commented 1 year ago

Other differences from convention:

vsajip commented 1 year ago

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!

yeraydiazdiaz commented 1 year ago

That's great to hear, I'm glad you find it useful 🙂