Python - Regular Package (Shipping | Packaging)

Card Puncher Data Processing

About

Code Versioning - Release and Code Shipping - Deployment in Python

How to release regular package adapted from https://packaging.python.org/tutorials/packaging-projects/ (they are using the setuptools framework)

Steps

With python 3.

Structure

/project_home
   /hello_world_pkg
       __init__.py
  setup.py

where:

name = "hello_nico"

Building a distribution

Update the building tool

  • run this command from the package directory (where setup.py is located) ???
python -m pip install --user --upgrade setuptools wheel

where:

Build

cd ./project
python setup.py sdist bdist_wheel

where:

This will create 3 sub directories:

  • build
  • dist
  • hello_nico.egg-info

Python Build Artifact Setup Py

The most important are in the dist subdirectory:

dist/
  hello_nico_pkg-0.0.1-py3-none-any.whl
  hello_nico_pkg-0.0.1.tar.gz

where:

Note: the full output of the command is:

running sdist
running egg_info
writing hello_nico.egg-info\PKG-INFO
writing dependency_links to hello_nico.egg-info\dependency_links.txt
writing top-level names to hello_nico.egg-info\top_level.txt
reading manifest file 'hello_nico.egg-info\SOURCES.txt'
writing manifest file 'hello_nico.egg-info\SOURCES.txt'
running check
creating hello-nico-0.0.2
creating hello-nico-0.0.2\hello_nico.egg-info
creating hello-nico-0.0.2\hello_nico_pkg
copying files to hello-nico-0.0.2...
copying README.md -> hello-nico-0.0.2
copying setup.py -> hello-nico-0.0.2
copying hello_nico.egg-info\PKG-INFO -> hello-nico-0.0.2\hello_nico.egg-info
copying hello_nico.egg-info\SOURCES.txt -> hello-nico-0.0.2\hello_nico.egg-info
copying hello_nico.egg-info\dependency_links.txt -> hello-nico-0.0.2\hello_nico.egg-info
copying hello_nico.egg-info\top_level.txt -> hello-nico-0.0.2\hello_nico.egg-info
copying hello_nico_pkg\__init__.py -> hello-nico-0.0.2\hello_nico_pkg
Writing hello-nico-0.0.2\setup.cfg
creating dist
Creating tar archive
removing 'hello-nico-0.0.2' (and everything under it)
running bdist_wheel
running build
running build_py
installing to build\bdist.win32\wheel
running install
running install_lib
creating build\bdist.win32\wheel
creating build\bdist.win32\wheel\hello_nico_pkg
copying build\lib\hello_nico_pkg\__init__.py -> build\bdist.win32\wheel\.\hello_nico_pkg
running install_egg_info
Copying hello_nico.egg-info to build\bdist.win32\wheel\.\hello_nico-0.0.2-py3.7.egg-info
running install_scripts
creating build\bdist.win32\wheel\hello_nico-0.0.2.dist-info\WHEEL
creating 'dist\hello_nico-0.0.2-py3-none-any.whl' and adding 'build\bdist.win32\wheel' to it
adding 'hello_nico_pkg/__init__.py'
adding 'hello_nico-0.0.2.dist-info/METADATA'
adding 'hello_nico-0.0.2.dist-info/WHEEL'
adding 'hello_nico-0.0.2.dist-info/top_level.txt'
adding 'hello_nico-0.0.2.dist-info/RECORD'
removing build\bdist.win32\wheel

Upload

Create an account to the repo

Create an account on Test PyPI.

Update the deploy tool

  • twine upload the archive to Test PyPI
python -m pip install --user --upgrade twine
REM Optional Add the scripts location to the path
set PATH=C:\Users\gerard\AppData\Roaming\Python\Python37\Scripts;%PATH%

Deploy

  • upload all of the archives under the dist sub-directory.
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
Enter your username: gerardnico
Enter your password:
Uploading distributions to https://test.pypi.org/legacy/
Uploading hello_nico-0.0.1-py3-none-any.whl
100%| 4.48k/4.48k [00:01<00:00, 2.88kB/s]
Uploading hello nico-0.0.1.tar.gz
100%| 4.23k/4.23k [00:01<00:00, 3.16kB/s]

It may take a minute or two for your project to appear on the site.

The package can be then see at:

https://test.pypi.org/project/package-name

Tintin ! In our case: https://test.pypi.org/project/hello-nico

On the real index, you can see if your package has successfully uploaded by navigating to the URL https://pypi.org/project/

Python Test Pypi Hello Nico
Use it
  • Syntax
python -m pip install --index-url https://test.pypi.org/simple/ packageName
cd c:\tmp
mkdir venv
cd venv
Scripts\python -m pip install --index-url https://test.pypi.org/simple/ hello-nico
Looking in indexes: https://test.pypi.org/simple/
Collecting hello-nico
  Downloading https://test-files.pythonhosted.org/packages/e2/37/eb9576a8b8b5a1881ace829edcb49e5a118ac10c50b3f78172b84a7efc8c/hello_nico-0.0.1-py3-none-any.whl
Installing collected packages: hello-nico
Successfully installed hello-nico-0.0.1

  • The package was installed
ls Lib\site-packages\hello_nico-0.0.1.dist-info
INSTALLER  METADATA  RECORD  WHEEL  top_level.txt

Import to test
  • Start Python
Scripts\python.exe
  • Import the module and access the property defined in the init.py file
import hello_nico_pkg
hello_nico_pkg.name
'hello_nico'

Documentation / Reference





Discover More
Card Puncher Data Processing
Python - (Shipping|Packaging)

in Python Shipping in Python is defined in the setuptools framework, that uses pip and to distribute code in the wheel format See
Card Puncher Data Processing
Python - Package

in Python Physically, package are the directories and modules are the files within this directories. Logically, a package is a module (parent module): which can contain: modules (submodules)...
Card Puncher Data Processing
Python - Regular Package

A regular package is a directory containing an init file. Package can be installed via distribution package. See distribution package installation. See Their location can be chosen during...
Card Puncher Data Processing
Python - Wheel Archive (whl - bdist_wheel)

Wheel is a compiled archive format with the .whl extension. A wheel is a built package that can be installed without needing to go through the “build” process. Installing wheels is substantially faster...
Card Puncher Data Processing
Python 3 - SetupTools

setuptools is an framework enhancement over distutils that allow to more easily build and distribute Python distributions. See ...
Card Puncher Data Processing
Python Package - init .py

A regular package is typically implemented as a directory containing an __init__.py file. The __init__.py file is tells Python that you can use the folder to import a module. (The default behavior is...



Share this page:
Follow us:
Task Runner