Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add console_script/entry point to setup.py that call a class function python

I want to add an entry point to setup.py that calls a static method of a class. Is that possible, and if so how? I've tried, and looked up documentation, but can not figure out how to do it.

Example: Package format:

mypackage/
   setup.py
   mypackage/
      test.py

test.py contains:

class TestClass:
   @staticmethod
   test_func():
      print("test print statement")

setup.py contains console scripts that look like:

entry_points={
        'console_scripts': [
            'run_console_script = mypackage.test:TestClass.test_func'
         ]}

But when I run the above code, it doesn't error, and yet nothing is printed.

like image 546
Justin Furuness Avatar asked Jan 25 '26 00:01

Justin Furuness


1 Answers

According to setuptools' documentation on "Automatic Script Creation" entry-points can only be functions:

The way to use this feature is to define “entry points” in your setup script that indicate what function the generated script should import and run.

like image 114
sinoroc Avatar answered Jan 29 '26 20:01

sinoroc



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!