Reputation: 9746
If I wrote a function like this :
def my_function():
# do something
I can create a command that run this function using :
entry_points = {
'console_scripts': [
'my_command = module:my_function',
],
},
Suppose I have the following class:
class MyPackage:
def __init__(self):
# manage something with argparse and others ...
def main(self):
# do the job
Is there a way to use the main method of the class MyPackage
or must I write a basic function ?
Upvotes: 2
Views: 540
Reputation: 94473
I believe it can be a class method or a static method but not an instance method.
class MyPackage:
def __init__(self):
# manage something with argparse and others ...
@classmethod
def main_classm(cls):
# do the job
@staticmethod
def main_stat():
# do the job
entry_points = {
'console_scripts': [
'command1 = module:MyPackage.main_classm',
'command2 = module:MyPackage.main_stat',
],
},
Upvotes: 2