Setuptools does not pass arguments for entry_points

I use setuptools for Python script I wrote

After installation, do the following:

$ megazord -i input -d database -v xx-xx -w yy-yy 

Like me if I ran it. / like _this

However, I get:

 Traceback (most recent call last): File "/usr/local/bin/megazord", line 9, in <module> load_entry_point('megazord==1.0.0', 'console_scripts', 'megazord')() TypeError: main() takes exactly 1 argument (0 given) 

Setuptools doesn't seem to send my arguments to main () for analysis (using optparse)

Here is my setuptools configuration for entry_points:

 entry_points = { 'console_scripts': [ 'megazord = megazord.megazord:main', 'megazord-benchmark = megazord.benchmark:main', 'megazord-hash = megazord.mzhash:main', 'megazord-mutate = megazord.mutator:main', ] } 

Any ideas?

+6
python setuptools distutils
source share
3 answers

At the console_scripts setuptools entry point, a function with no arguments is required.

Fortunately, optparse (Parser for command line options) does not need to pass any arguments, it will read in sys. argv [1:] and use this when entering.

+13
source share

Just to give a complete idea of ​​what megazord.py will look megazord.py , using @Jeffrey Harris' suggestion to use a beautiful library for parsing inputs.

 import argparse def main(): ''' Example of taking inputs for megazord bin''' parser = argparse.ArgumentParser(prog='my_megazord_program') parser.add_argument('-i', nargs='?', help='help for -i blah') parser.add_argument('-d', nargs='?', help='help for -d blah') parser.add_argument('-v', nargs='?', help='help for -v blah') parser.add_argument('-w', nargs='?', help='help for -w blah') args = parser.parse_args() collected_inputs = {'i': args.i, 'd': args.d, 'v': args.v, 'w': args.w} print 'got input: ', collected_inputs 

And using it, as in the above, you can get

 $ megazord -i input -d database -v xx-xx -w yy-yy got input: {'i': 'input', 'd': 'database', 'w': 'yy-yy', 'v': 'xx-xx'} 

And since they are all optional arguments,

 $ megazord got input: {'i': None, 'd': None, 'w': None, 'v': None} 
+10
source share

this is a list with all the arguments for ArgumentParser: "" "An object to parse command line strings in Python objects.

 Keyword Arguments: - prog -- The name of the program (default: sys.argv[0]) - usage -- A usage message (default: auto-generated from arguments) - description -- A description of what the program does - epilog -- Text following the argument descriptions - parents -- Parsers whose arguments should be copied into this one - formatter_class -- HelpFormatter class for printing help messages - prefix_chars -- Characters that prefix optional arguments - fromfile_prefix_chars -- Characters that prefix files containing additional arguments - argument_default -- The default value for all arguments - conflict_handler -- String indicating how to handle conflicts - add_help -- Add a -h/-help option - allow_abbrev -- Allow long options to be abbreviated unambiguously 
0
source share

All Articles