This blog will explain the structure of the project and how to upload the software.
Let’s see an example by creating a module Myadd. In this we create a python program which contains a definition to add two numbers.
Lets create a directory Myadd where the name is same as module.
“Myadd”
void add(a,b):
sum = a+b
print(“The sum is %d” % sum)
We also added __init__.py and README.rst file in the module.
$ ls
Myadd README.rst
In My Myadd directory, we can find the __init.py__ file.
License
We have to add a license to our project, so that it will not republished by anyone again. Usually the projects are licensed under MIT.
Installing Setuptools
Let’s install, setup tools using virtualenv, and also we can install the wheel.
$ pip install setuptools wheel
Then we want to create setup.py which is used for installing the software.
from setuptools import find_package, setup
find_package is used to find and load the external setting into the program.
Python Package Indexing
It is the repository of the software in the python programming language. The pip command in which we normally use to install the software fetches the packages from the PyPI.
Uploading the Project
The project has to be uploaded to the server (test.pypi.org).For this twine command is used. Before that we want to install twine.
$ pip install twine
$ twine upload –repository-url https://test.pypi.org/legacy/ dist/*
Then it will ask for the username and password. After completing, the project will be uploaded to the test server.