This is a test version of Biostars. For the public version, visit https://www.biostars.org.
python setup tools console_scripts with arguments

I want to implement my pypy.py script on commandline, I need to work with setup tools but the console_script does not work properly as my pypy.py needs two arguments, please guide me how can I modify it properly to work on commendline.

python.py

def main(agru1, argu2):

    "do something"

 if __name__ == "__main__":
        main()

when I include it in my setup.py file, as console_script as follow

setup( 
     entry_points={
        'console_scripts': [

                'pypy = pypy.pypy:main'],
    }

)

And I get the following error when I run it on commandline:

Traceback (most recent call last):
File "/usr/local/bin/python", line 9, in <module>
load_entry_point('Pypy==0.1', 'console_scripts', 'pypy')()
TypeError: main() takes at least 2 arguments (0 given)
python setuptools

1 answer

A fast way of doing it is with sys.argv:

Then you can just pass two positional arguments, when running from the command line. Note that the code assumes that there will be two arguments, and as it is, it will break with less than two and it will ignore any extra args.

For a nicer, more sophisticated CLI, try docopt.

Thanks, how should I include main(argv[1], argv[2]) in the setup.py ( as mentioned above) ?

error still the same if I use your explanation .... !

Log in to answer this question.