An app should have a main function. This function should be defined something like so:
class MyApp(appcli.App):
@classmethod
def main(cls):
app = cls.from_params()
app.do_something()
This problem is what to call the do_something() method. It's basically the main function that the user themselves writes, and so it also wants to be called main(), but I think it makes the most sense to reserve the name main() for the static method that actually can be used as an entry point. So, my options are:
Hard-code a name like do_main() or _main(). The do_ prefix is my normal idiom for this kind of thing, but it's unattractive.
Provide a @main decorator. I'd have to do some error checking (e.g. exactly one main function), but it stays in the background.
Because I already have a metaclass, I could inject the @main decorator directly into the namespace where class methods are evaluated. That would let it save a direct reference to the method, so I wouldn't need to search through every defined method for a hit.
I'd have to think about how to implement the injection idea in a way that suports inheritance. Maybe I would ultimately have the decorator be sugar for some more explicit method of specifying the main function (e.g. hardcoded name).
I could name the static method entry_point(), then use the name main() for the regular member function.
An app should have a main function. This function should be defined something like so:
This problem is what to call the
do_something()
method. It's basically the main function that the user themselves writes, and so it also wants to be calledmain()
, but I think it makes the most sense to reserve the namemain()
for the static method that actually can be used as an entry point. So, my options are:do_main()
or_main()
. Thedo_
prefix is my normal idiom for this kind of thing, but it's unattractive.@main
decorator. I'd have to do some error checking (e.g. exactly one main function), but it stays in the background.@main
decorator directly into the namespace where class methods are evaluated. That would let it save a direct reference to the method, so I wouldn't need to search through every defined method for a hit.entry_point()
, then use the namemain()
for the regular member function.