python setup tools console_scripts with arguments
1
0
Entering edit mode
8.0 years ago
ahmedakhokhar ▴ 150

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 • 4.6k views
ADD COMMENT
0
Entering edit mode
8.0 years ago

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.

ADD COMMENT
0
Entering edit mode

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 .... !

ADD REPLY

Login before adding your answer.

Traffic: 2111 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6