📦 A Human's Ultimate Guide to setup.py.

Overview

📦 setup.py (for humans)

This repo exists to provide an example setup.py file, that can be used to bootstrap your next Python project. It includes some advanced patterns and best practices for setup.py, as well as some commented–out nice–to–haves.

For example, this setup.py provides a $ python setup.py upload command, which creates a universal wheel (and sdist) and uploads your package to PyPi using Twine, without the need for an annoying setup.cfg file. It also creates/uploads a new git tag, automatically.

In short, setup.py files can be daunting to approach, when first starting out — even Guido has been heard saying, "everyone cargo cults thems". It's true — so, I want this repo to be the best place to copy–paste from :)

Check out the example!

Installation

cd your_project

# Download the setup.py file:
#  download with wget
wget https://raw.githubusercontent.com/navdeep-G/setup.py/master/setup.py -O setup.py

#  download with curl
curl -O https://raw.githubusercontent.com/navdeep-G/setup.py/master/setup.py

To Do

  • Tests via $ setup.py test (if it's concise).

Pull requests are encouraged!

More Resources

License

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

Comments
  • Introduce setup.cfg

    Introduce setup.cfg

    The best development in the python packaging field in the last years is the introduction of the setup.cfg:

    • declarative description
    • simple to read
    • easy to diff

    It reduces the need for error prone, cargo cult boilerplate code in the setup.py. A nice setup.py should look like this (if it should exist at all):

    from setuptools import setup
    
    if __name__ == "__main__":
        setup()
    

    IMHO, the rest should be declaratively described without arbitrary code execution in the setup.cfg

    opened by sebastianneubauer 18
  • [question] What about parsing requirements.txt?

    [question] What about parsing requirements.txt?

    https://github.com/kennethreitz/setup.py/blob/c5a82dc3670b5fa65e4d5da578d992c38b62d524/setup.py#L22

    2 years ago I was playing with this http://j.mp/setup_py and one of the features is using pip.req.parse_requirements('requirements.txt') to populate the requires and avoid duplicity.

    What do you think about this? on advantage of having a requirements.txt is to use pyup.io and satefy to check updates and audit the requirements for security failures.

    opened by rochacbruno 10
  • FileNotFoundError not available in python2

    FileNotFoundError not available in python2

    FileNotFoundError is not defined in python2

    $ python setup.py publish running publish Removing previous builds… Traceback (most recent call last): File "setup.py", line 101, in 'publish': PublishCommand, File "/usr/lib/python2.7/distutils/core.py", line 151, in setup dist.run_commands() File "/usr/lib/python2.7/distutils/dist.py", line 953, in run_commands self.run_command(cmd) File "/usr/lib/python2.7/distutils/dist.py", line 972, in run_command cmd_obj.run() File "setup.py", line 60, in run except FileNotFoundError: NameError: global name 'FileNotFoundError' is not defined

    opened by remyleone 6
  • Cannot read the the version file

    Cannot read the the version file

    I have my directory structure like so

    setup.py
    MANIFEST.in
    LICENSE
    README.md
    pipfile
    pipfile.lock
    cryptowatch:
        - cryptowatch
        - __version__.py
        - __init__.py
        - utlitiesFile.py
    

    When I run python setup.py I am given this error:

    Traceback (most recent call last):
      File "setup.py", line 25, in <module>
        with open(os.path.join(here, NAME, '__version__.py')) as f:
    IOError: [Errno 2] No such file or directory: '/home/fsociety/git/bitbucket/cryptowatch/crypotowatch/__version__.py'
    

    I know I have a file there and I even went as far as making it executable with chmod a+x __version__.py but sill no luck.

    Is there something I am doing wrong here?

    I have modified the setup.py a little but only information not the actual code, just in case I screwed something up while doing that here it is:

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    import codecs
    import os
    import sys
    
    from setuptools import find_packages, setup
    
    # Package meta-data.
    NAME = 'crypotowatch'
    DESCRIPTION = 'Track prices and account balaces bitcoin, ethereum, and litecoin'
    URL = 'https://github.com/alexanderepstein/cryptowatch'
    EMAIL = '[email protected]'
    AUTHOR = 'Alexander Epstein'
    
    here = os.path.abspath(os.path.dirname(__file__))
    
    # Import the README and use it as the long-description.
    with codecs.open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
        long_description = '\n' + f.read()
    
    # Load the package's __version__.py module as a dictionary.
    about = {}
    with open(os.path.join(here, NAME, "__version__.py")) as f:
        exec(f.read(), about)
    
    # Support "$ setup.py publish".
    if sys.argv[-1] == "publish":
        os.system("python setup.py sdist bdist_wheel upload")
        sys.exit()
    
    # What packages are required for this module to be executed?
    required = [
         'requests', 'Adafruit_GPIO'
    ]
    
    # Dependencies only for versions less than Python 2.7:
    # if sys.version_info < (2, 7):
    #     required.append('requests[security]')
    
    # Where the magic happens:
    setup(
        name=NAME,
        version=about['__version__'],
        description=DESCRIPTION,
        long_description=long_description,
        author=AUTHOR,
        author_email=EMAIL,
        url=URL,
        packages=find_packages(exclude=('tests',)),
    #     entry_points={
    #         'console_scripts': ['mycli=mymodule:cli'],
    #     },
        install_requires=required,
        include_package_data=True,
        license='MIT',
        classifiers=[
            'License :: OSI Approved :: MIT License',
            'Programming Language :: Python',
            'Programming Language :: Python :: 2.6',
            'Programming Language :: Python :: 2.7',
            'Programming Language :: Python :: Implementation :: CPython',
            'Programming Language :: Python :: Implementation :: PyPy'
        ],
    )
    
    
    opened by alexanderepstein 6
  • Consider adding examples for extras_require

    Consider adding examples for extras_require

    Perhaps the project could benefit from adding syntax examples for two useful features, commonly seen in the wild:

    • extras, e.g. myproj[this,stuff]
    • conditional deps, i.e. environment markers (e.g., requiring backports only when needed)

    Additionally, I think the UploadCommand thing is feature bloat and should be removed. It doesn't really belong here directly in setup.py, being duplicated in each and every project. Maybe just add a comment or a link to a good guide about how to use twine?

    opened by wimglenn 5
  • Remind people to change the license trove

    Remind people to change the license trove

    Defaults are important. Most people are just going to copy and paste this and be satisfied that it works after they (probably) change the things they're expected to change. That means it's important to give the user as much of a sense of control over the data they're probably going to change as we can. This PR defines an interface for changing the project's platform support and provides it to the user.

    Also, it adds a comment reminding you to change the classifier to match your license if you change the license, because I've already forgotten to do that.

    opened by lethargilistic 4
  • Don't encourage Python2 support :)

    Don't encourage Python2 support :)

    It's probably better to comment out the Python2 classifiers (especially 2.6!) so you only show they're possible, rather than suggest they're desirable as a default.

    opened by funkybob 4
  • ENH: Autodetect README file and its MIME type

    ENH: Autodetect README file and its MIME type

    Check through a small list of likely candidates for README filenames: ['README.rst', 'README.md', 'README.txt', 'README'] and use the first one which exists.

    We then infer the long_description_content_type argument from the file extension of the readme file.

    opened by scottclowe 3
  • Remove reference to

    Remove reference to "The Hitchhiker's Guide to Packaging"

    Should we point people directly to this? https://packaging.python.org/

    The Hitchhiker's guide, although probably a great source of information, is outdated. Written in 2009, the last commit was in 2010.

    I believe that given the state of python packaging, it is not a good reference to keep hanging around.

    enhancement 
    opened by supermitch 3
  • Version bump as part of setup.py?

    Version bump as part of setup.py?

    How can we do a nice version bump for major/minor/micro changes?

    It might be nice as an extra possible command in setup.py? Would this be possible?

    Or do you think it more fits in pipenv?

    opened by kootenpv 3
  • Example hooks for binder

    Example hooks for binder

    This PR adds an example notebook that imports the package. This doesn't add much for setup.py repository, but for those using Binder it's nice to have an example since you need a setup.py file to import the package automatically. Currently there is no example for binder (that I can find) that has a setup.py, so this repository seemed like the obvious place to start.

    opened by cranmer 2
  • Add test, username and password options to upload command.

    Add test, username and password options to upload command.

    This pull provides 3 options to upload command:

    • --test Upload the package to https://test.pypi.org/legacy/ PyPI testing mirror.
    • --username=foo Specifies the username used to authenticate uploading the package to PyPI.
    • --password=bar Specifies the password used to authenticate uploading the package to PyPI.

    Also, I've updated the quotation marks of exclude arguments passed to find_packages option for unify the strings style used in setup.py file.

    opened by mondeja 0
  • Update LICENSE to be public domain.

    Update LICENSE to be public domain.

    The readme says the software is in the public domain. This pull request makes the license file match that. Below are further details.

    ** The readme says the software is in the public domain. The LICENSE file says it is the MIT license.

    Neither of these were added by the navdeep, though the master branch seems to now be the one created by ken-reitz who did add these. Additionally, the readme was recently updated by navdeep:

    https://github.com/navdeep-G/setup.py/commit/46f7cd41a5d58adde653aae19c54cf689a3b2a91

    From the above, I infer that the correct license should be the Unlicense license. I copied and pasted the text from the github template. Presumably, it is the same as the below link.

    https://unlicense.org/

    opened by AdityaSavara 1
  • resolve pylint conventions and a warning

    resolve pylint conventions and a warning

    Update to resolve pylint conventions and a warning

    The below is the results of pylint, pycodestyle, and flake8:

    (setup.py) bash-3.2$ pylint setup.py 
    ************* Module setup
    setup.py:1:0: C0114: Missing module docstring (missing-module-docstring)
    setup.py:38:0: C0103: Constant name "here" doesn't conform to UPPER_CASE naming style (invalid-name)
    setup.py:44:8: C0103: Constant name "long_description" doesn't conform to UPPER_CASE naming style (invalid-name)
    setup.py:46:4: C0103: Constant name "long_description" doesn't conform to UPPER_CASE naming style (invalid-name)
    setup.py:49:0: C0103: Constant name "about" doesn't conform to UPPER_CASE naming style (invalid-name)
    setup.py:51:4: C0103: Constant name "project_slug" doesn't conform to UPPER_CASE naming style (invalid-name)
    setup.py:53:8: W0122: Use of exec (exec-used)
    setup.py:65:4: C0103: Argument name "s" doesn't conform to snake_case naming style (invalid-name)
    setup.py:69:4: C0116: Missing function or method docstring (missing-function-docstring)
    setup.py:72:4: C0116: Missing function or method docstring (missing-function-docstring)
    setup.py:75:4: C0116: Missing function or method docstring (missing-function-docstring)
    
    ------------------------------------------------------------------
    Your code has been rated at 7.80/10 (previous run: 7.80/10, +0.00)
    
    (setup.py) bash-3.2$ pycodestyle setup.py 
    setup.py:36:80: E501 line too long (81 > 79 characters)
    setup.py:83:80: E501 line too long (86 > 79 characters)
    setup.py:106:80: E501 line too long (81 > 79 characters)
    (setup.py) bash-3.2$ flake8 setup.py 
    setup.py:36:80: E501 line too long (81 > 79 characters)
    setup.py:83:80: E501 line too long (86 > 79 characters)
    setup.py:106:80: E501 line too long (81 > 79 characters)
    (setup.py) bash-3.2$
    

    This branch resolves above conventions and a warning as below:

    (setup.py) bash-3.2$ pylint setup.py 
    
    -------------------------------------------------------------------
    Your code has been rated at 10.00/10 (previous run: 7.80/10, +2.20)
    
    (setup.py) bash-3.2$ pycodestyle setup.py 
    (setup.py) bash-3.2$ flake8 setup.py 
    (setup.py) bash-3.2$
    
    opened by SeungYeop-Yang 0
  • .travis.yml setup

    .travis.yml setup

    It would be nice if you also provide .travis.yml for Travis CI. In the script, it should test out a few commands with setup.py such as python setup.py install, etc.

    enhancement 
    opened by alext234 2
Owner
Navdeep Gill
Data Scientist & Software Engineer
Navdeep Gill
Get you an ultimate lexer generator using Fable; port OCaml sedlex to FSharp, Python and more!

NOTE: currently we support interpreted mode and Python source code generation. It's EASY to compile compiled_unit into source code for C#, F# and othe

Taine Zhao 15 Aug 6, 2022
Ultimate Microsoft Edge Uninstaller!

Ultimate Microsoft Edge Uninstaller

null 1 Feb 8, 2022
Sabe is a python framework written for easy web server setup.

Sabe is a python framework written for easy web server setup. Sabe, kolay web sunucusu kurulumu için yazılmış bir python çerçevesidir. Öğrenmesi kola

null 2 Jan 1, 2022
📽 Streamlit application powered by a PyScaffold project setup

streamlit-demo Streamlit application powered by a PyScaffold project setup. Work in progress: The idea of this repo is to demonstrate how to package a

PyScaffold 2 Oct 10, 2022
SpaCy3Urdu: run command to setup assets(dataset from UD)

Project setup run command to setup assets(dataset from UD) spacy project assets It uses project.yml file and download the data from UD GitHub reposito

Muhammad Irfan 1 Dec 14, 2021
Python project setup, updater, and launcher

Launcher Python project setup, updater, and launcher Purpose: Increase project productivity and provide features easily. Once installed as a git submo

DAAV, LLC 1 Jan 7, 2022
Python project setup, updater, and launcher

pyLaunch Python project setup, updater, and launcher Purpose: Increase project productivity and provide features easily. Once installed as a git submo

DAAV, LLC 1 Jan 7, 2022
MoBioTools A simple yet versatile toolkit to automatically setup quantum mechanics/molecular mechanics

A simple yet versatile toolkit to setup quantum mechanical/molecular mechanical (QM/MM) calculations from molecular dynamics trajectories.

MoBioChem 17 Nov 27, 2022
Short, introductory guide for the Python programming language

100 Page Python Intro This book is a short, introductory guide for the Python programming language.

Sundeep Agarwal 185 Dec 26, 2022
Coursework project for DIP class. The goal is to use vision to guide the Dashgo robot through two traffic cones in bright color.

Coursework project for DIP class. The goal is to use vision to guide the Dashgo robot through two traffic cones in bright color.

Yueqian Liu 3 Oct 24, 2022
Developer guide for Hivecoin project

Hivecoin-developer Developer guide for Hivecoin project. Install Content are writen in reStructuredText (RST) and rendered with Sphinx. Much of the co

tweetyf 1 Nov 22, 2021
Python: Wrangled and unpivoted gaming datasets. Tableau: created dashboards - Market Beacon and Player’s Shopping Guide.

Created two information products for GameStop. Using Python, wrangled and unpivoted datasets, and created Tableau dashboards.

Zinaida Dvoskina 2 Jan 29, 2022
Project Guide for ASAM OpenX standards

ASAM Project Guide Important This guide is a work in progress and subject to change! Hosted version available at: ASAM Project Guide (Link) Includes:

ASAM e.V. 2 Mar 17, 2022
A tool to guide you for team selection based on mana and ruleset using your owned cards.

Splinterlands_Teams_Guide A tool to guide you for team selection based on mana and ruleset using your owned cards. Built With This project is built wi

Ruzaini Subri 3 Jul 30, 2022
Research using python - Guide for development of research code (using Anaconda Python)

Guide for development of research code (using Anaconda Python) TL;DR: One time s

Ziv Yaniv 1 Feb 1, 2022
A community-driven python bot that aims to be as simple as possible to serve humans with their everyday tasks

JARVIS on Messenger Just A Rather Very Intelligent System, now on Messenger! Messenger is now used by 1.2 billion people every month. With the launch

Swapnil Agarwal 1.3k Jan 7, 2023
The ultimate Python library in building OAuth, OpenID Connect clients and servers. JWS,JWE,JWK,JWA,JWT included.

Authlib The ultimate Python library in building OAuth and OpenID Connect servers. JWS, JWK, JWA, JWT are included. Authlib is compatible with Python2.

Hsiaoming Yang 3.4k Jan 4, 2023
The ultimate Python library in building OAuth, OpenID Connect clients and servers. JWS,JWE,JWK,JWA,JWT included.

Authlib The ultimate Python library in building OAuth and OpenID Connect servers. JWS, JWK, JWA, JWT are included. Authlib is compatible with Python2.

Hsiaoming Yang 2.3k Feb 17, 2021
Ultimate Score Server for RealistikOsu

USSR Ultimate Score Server for RealistikOsu (well not just us but it makes the acronym work.) Also I wonder how long this name will last. What is this

RealistikOsu! 15 Dec 14, 2022
A Non-Autoregressive Transformer based TTS, supporting a family of SOTA transformers with supervised and unsupervised duration modelings. This project grows with the research community, aiming to achieve the ultimate TTS.

A Non-Autoregressive Transformer based TTS, supporting a family of SOTA transformers with supervised and unsupervised duration modelings. This project grows with the research community, aiming to achieve the ultimate TTS.

Keon Lee 237 Jan 2, 2023