Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python setuptools using 'scripts' keyword in setup.py

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.
)
like image 998
Will_of_fire Avatar asked Jul 15 '17 03:07

Will_of_fire


People also ask

What is scripts in setup py?

The setup script is the centre of all activity in building, distributing, and installing modules using the Distutils. The main purpose of the setup script is to describe your module distribution to the Distutils, so that the various commands that operate on your modules do the right thing.

What does Python setuptools setup do?

setuptools allows you to install a package without copying any files to your interpreter directory (e.g. the site-packages directory). This allows you to modify your source code and have the changes take effect without you having to rebuild and reinstall. Here's how to do it: pip install --editable .

How do I manually install Setuptools in Python?

Step 1: Download the latest source package of Setuptools for Python3 from here. Step 2: Extract the downloaded package using the given command. Step 3: Go to the setuptools-60.2. 0 folder and enter the following command to install the package.

How do I setup Python py?

To install a package that includes a setup.py file, open a command or terminal window and: cd into the root directory where setup.py is located. Enter: python setup.py install.


1 Answers

Its mainly used to define the additional scripts you'll be using in your package. Here's a snippet from the reference link:

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

Reference: http://python-packaging.readthedocs.io/en/latest/command-line-scripts.html#the-scripts-keyword-argument

like image 86
worker_bee Avatar answered Oct 20 '22 23:10

worker_bee