How to install python cli scripts using setuptools without duplicates?

I have 2 Python scripts that can be used from the shell, since they are thanks to argparse.

Relevant part of setup.py:

setup(
    # (...)
    zip_safe=True,
    scripts=['bin/bgce.py', 'bin/sizes.py'],
    packages=find_packages(),
    data_files=data_files,
    entry_points = {
        'console_scripts': [
            'bgce = bgce:main',
            'sizes = sizes:main',]
    }
)

I end up with bgce, bgce.py, sizes, .py sizes in / usr / local / bin. All 4 works.

If I don’t point out either the packages or the script line, there are no duplicates, but the files fail as follows:

Traceback (most recent call last):
File "/usr/local/bin/bgce", line 9, in <module>
    load_entry_point('Backtestground==1.0', 'console_scripts', 'bgce')()
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 305, in load_entry_point return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 2244, in load_entry_point return ep.load()
File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 1954, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
ImportError: No module named bgce

What can I do to set only bgce and sizes, there are no duplicates with annoying (to complete the tab) .py attached?

+5
source share
2 answers

Make sure that the actual modules have a major function like this:

def main():
    try:
        some_stuff()
    except KeyboardInterrupt :
        print ""
        sys.exit()

if __name__ == "__main__" :
    main()

if __name__ == "__main__" : main(), distutils . (Catching ^ C :) , , , - . , , !

+4

IIRC: bgce.py .py , , .

0

All Articles