24

I am trying to understand how python packaging works using setuptools.

One of the arguments for setup() function is scripts . The documentation doesn't specify what that argument is used for. Any help would be great!! Here is some sample code where scripts is used.

from setuptools import setup, find_packages
setup(
    name="HelloWorld",
    version="0.1",
    packages=find_packages(),
    scripts=['say_hello.py'],

    # Project uses reStructuredText, so ensure that the docutils get
    # installed or upgraded on the target machine
    install_requires=['docutils>=0.3'],

    package_data={
        # If any package contains *.txt or *.rst files, include them:
        '': ['*.txt', '*.rst'],
        # And include any *.msg files found in the 'hello' package, too:
        'hello': ['*.msg'],
    },

    # metadata for upload to PyPI
    author="Me",
    author_email="[email protected]",
    description="This is an Example Package",
    license="PSF",
    keywords="hello world example examples",
    url="http://example.com/HelloWorld/",   # project home page, if any

    # could also include long_description, download_url, classifiers, etc.
)

1 Answer 1

22

Its mainly used to define the additional scripts you'll be using in your package. Here's a snippet from the official documentation on python-packaging:

#!/usr/bin/env python
import funniest 
print funniest.joke() 

Then we can declare the script in setup() like this:

setup(
    ...
    scripts=['bin/funniest-joke'],
    ... 
    ) 

When we install the package, setuptools will copy the script to our PATH and make it available for general use. This has advantage of being generalizeable to non-python scripts, as well: funniest-joke could be a shell script, or something completely different.

Sign up to request clarification or add additional context in comments.

2 Comments

It's important to stress that the scripts keyword DOES NOT WORK in Windows! If there is no specific reason, please use the 2nd option console_scripts setuptools entry-point, as described in the reference link, which is officially "blessed": packaging.python.org/guides/…
notice for entry_points: The functions you specify are called with no arguments, and their return value is passed to sys.exit() ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.