Package Installation (setuptools)

Prerequisites

  • Virtual environment recommended (but not necessary)

$ python -m pip install setuptools wheel twine

Files

from setuptools import setup

setup(
    name='python-course-2022-11-07',
    version='0.0.1',
    description='Lotsa coding',

    # long_description='blah',
    # long_description_content_type='text/markdown',

    url='https://company.com',
    author='Joerg Faschingbauer',

    # https://pypi.org/classifiers/
    classifiers=[
        #   3 - Alpha
        #   4 - Beta
        #   5 - Production/Stable
        'Development Status :: 5 - Production/Stable',
        # 'Intended Audience :: Developers',
        # 'Topic :: Software Development :: Build Tools',
        # 'License :: OSI Approved :: MIT License',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
        'Programming Language :: Python :: 3.8',
        'Programming Language :: Python :: 3.9',
        'Programming Language :: Python :: 3 :: Only',
    ],

    keywords='training, examples, stuff',  # Optional
    package_dir = {'': 'src'},
    packages = ['.'],
    scripts=['bin/do-the-acquisition.py'],
    python_requires='>=3.6, <4',
    install_requires=[
        'paho-mqtt',
    ],
)
[build-system]
requires = [
    "setuptools>=41",
    "wheel"
]
build-backend = "setuptools.build_meta"

Test “Installation”

$ python -m pip install --editable ~/work/2022-11-07/
... yadda ...
  • Actually, not an installation

  • Creates links to source package

  • Can use the package as if it were installed

  • Source code is still editable

  • very helpful

  • ⟶ don’t need to set $PYTHONPATH into src/

Source Distribution

$ cd ~/work/2022-11-07/
$ python setup.py sdist
... yadda ...

Manifest

  • A file MANIFEST.in that contains all that need packaging

  • Written manually by default

  • Tool support: check-manifest

    $ python -m pip install check-manifest
    
  • Create (and add) MANIFEST.in

    $ check-manifest --create
    $ git add MANIFEST.in
    

Packaging

$ python setup.py bdist_wheel sdist
... yadda ...
$ ls -l dist/
total 20
-rw-r--r--. 1 jfasch jfasch  1954 Nov 30 18:32 python_course_2022_11_07-0.0.1-py3-none-any.whl
-rw-r--r--. 1 jfasch jfasch 12549 Nov 30 18:32 python-course-2022-11-07-0.0.1.tar.gz

Installing From Wheel File

$ python -m pip install ~/work/2022-11-07/dist/python_course_2022_11_07-0.0.1-py3-none-any.whl

Publishing On PyPI

  • TO BE DONE

    • twine

    • API Token