Conversation
--> kosh.setup() can now be called without it starting to serve() Example (python shell): >>> # still need to set the CLI args (simulate) >>> import sys >>> sys.argv[:] = ["__main__", "--config_file", "kosh.ini", "--log_level", "DEBUG"] >>> # now "start" kosh >>> import kosh.kosh >>> app = kosh.kosh.kosh() >>> app.setup() >>> # now we can manipulate the kosh instance, e.g. >>> from kosh.utility.instance import instance >>> lexicon = instance.lexicons["hoenig"] >>> from kosh.elastic.search import search >>> search.entries(lexicon, "lemma_ksh", "aach", "term", 10) ... # ...
|
First of all, I second Your idea. But may I ask for Your thoughts about utilizing and/or trimming down the current execution path if kosh is run as sys.argv[:] = ["__main__", "--config_file", "kosh.ini", "--log_level", "DEBUG"]
import kosh.koshAnd the current structure of the entrypoint module, def main() -> None:
kosh().main()
if __name__ == "__main__":
main()
class kosh:
# [...]
def main(self) -> None:
# [...]it seems to me that, at least, the I'm not quite sure yet if and how this could benefit the execution path and therefor debugging the code and I'm also no against merging Your pull request but I my gut tells me there's a greater benefit to be had here. |
|
My idea was to mostly keep the same structure but only extract the setup code into its method. As the intended main use-case is running the server, I didn't want to modify too much, so The I believe the global Line 40 in aa05346 With # untested, not sure about path prefixes or not, and whether kosh needs to be installed or not
# run when installed and called from CLI (`python -m kosh` ?)
def main() -> None:
kosh().main()
# so run as script `./kosh.py` / `python kosh.py`
if __name__ == "__main__":
main()As as side note, Flask suggests a |
This change just refactors and extracts some setup code from
kosh.main()tokosh.setup. No other changes.This allows to call
kosh.setup()without startingkoshwith the blockingkosh.serve()which hinders interactive debugging.Example (python shell):