Documentation for how to use setup.py (Python)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Markus Becker 73ff286c6a Added setup.py generator 2 months ago
setup_generate Added setup.py generator 2 months ago
.gitignore Added setup.py generator 2 months ago
LICENSE Initial commit 2 months ago
README.md Update 'README.md' 2 months ago
setup.py Added setup.py generator 2 months ago

README.md

setup-py

Documentation for how to use setup.py (setuptools) to package python applications.

Introduction

I've made this a collection of the useful features of setuptools and a tutorial on how to package python apps (for development purposes).

Basics

This tutorial is meant to be used in pure-python applications which are versioned with git. To get started, create a file called setup.py in the root of your Repository and copy/complete this content into it:

from setuptools import setup, find_packages

setup(
    name="<application name>",
    version="0.0.1",
    author="<author name>",
    author_email="<author email>",
    description="<one-line description>",
    url="<url of upstream repository>",
    license='<license>',
    packages=find_packages(),
    install_requires=[], # add dependencies here
    entry_points={
        'console_scripts': [
            '<executable> = <package>:<function>' # on install the executable will be placed in PATH
        ],
    },
    python_requires=">=3.0", # if python 3
)

Local developing

After creating the setup.py file you can install your application in a editable way by calling pip install -e . in the root of your repository. If you then change the code any new processes will use the updated code (changes to the setup.py file require a new call to pip install -e . to have an effect).

The entry_points variable in the setup call is going to allow you to execute your python code. Here's an example how this works. Imagine a directory structure as follows:

.
├── setup.py
└── my_package
    └── my_module.py

With a function called main in my_module.py. If you want to be able to call into my_module:main with the command my_executable you will need to create this entry point in setup.py:

setup(
    # ...
    entry_points={
        'console_scripts': [
            'my_executable = my_package.my_module:main',
        ],
    },
    # ...
)

Installing from remote

Using pip you can install your app after pushing it to the remote with:

pip3 install --user -U git+https://cfbrk.de/mtib/setup-py.git@master
#                          <--           URL          -->    <-TAG->

Useful advanced features

Automatic versioning

Simply remove the version line and add the lines:

setup(
    # ...
    use_scm_version=True,
    # ...
    install_requires=[
        # ...
        'setuptools_scm',
        # ...
    ],
    # ...
)

In your application you can use:

import setuptools_scm

print(setuptools_scm.get_version())