How to install Setuptools Python with windows shell

Before learning Setuptools, it is important to understand the fundamentals of Distutils.

Python comes with a module called distutils that provides a set of tools to distribute your Python applications. It provides the following :

  1. A skeleton to provide standard metadata fields such as the author, author email, version,license and many others.
  2. A set of helper who knows how to build a distribution over the code of a package -it's containing one or more modules. Even you can create a set of precompiled python files or a real installer for Windows.

But distutils is limited to the package, and doesn't provide a way to define its dependencies over other packages. setuptools enhances this by adding a basic dependency system and a lot of other features. It also provides an automatic package

finder that knows how to fetch dependencies and install them automatically. This tool has become very popular and is now almost mandatory when writing Python applications that are meant to be distributed.

Let's understand the checklist for Setuptools:


setup.py

we need in order to use setup tools to package and distribute the application ,you setup a file that will be placed at the root of your project this file will continue the necessary information to build package and distribute your python code and it also serve as an entry points to all the commands need to run to do all.

README.md

The essential details about your project are contained in a plain text file. its a manual for installation and necessary software packages.

License

A crucial part of your package will be the License file. This is a very important file to add to your project as it describes the rights that your package developers have and the rights that other people who use your code have choosing a license for your code should be mandatory step  before distributing.

Manifest

The last mandatory thing for the setup tool is, of course, your code under one top-level python package for easier distribution, there are also optional things you can add a manifest dot in the file which describes files that should be included in your distribution but are not included by default. it contains the version, package name, MainClass and etc.

CGF

Information about configurations and settings is stored. It is utilized by a number of programs, so different CFG files may store data in a variety of formats. The majority of the time, CFG files shouldn't be manually opened, but they could be saved in a text format that can be read by a text editor.

Practice example for addition and subtraction operation .

  1. Create a dir and place a file __init__.py 
  2. another file setup.py placed in to the same dir  
  3. create another dir named knowladgehunt
  4. create same __init__.py just create
  5. create cal.py paste the code 
  6. Open the window terminal
  7. Check your files by command dir

    Directory: D:\KnowledgeHunt\setuptools


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----        12/24/2022   9:12 PM                knowladgehunt
-a----        12/24/2022   8:58 PM            614 setup.py
-a----        12/24/2022  12:53 PM              0 __init__.py

    

__init__.py just create it 

setup.py

import setuptools

setuptools.setup(

    include_package_data=True,

    name='knowladgehunt',

    version='1.0.0',

    description='knowladgehunt python module',

    url='https://github.com/knowladgehunt/examples/setuptool',

    author='knowladgehunt',

    author_email='contactus@test.com',

    packages=setuptools.find_packages(),

    install_requires=['pandas', 'pytest'

    ],

    long_description='knowladgehunt python module',

    long_description_content_type="text/markdown",

    license="knowladgehunt",

    classifiers=[

        "Programming Language :: Python :: 3",

         "Operating System :: OS Independent",

    ],

)


knowladgehunt/__init__.py
knowladgehunt/cal.py

def add(a, b):

    return a+b

def sub(a, b):

    return a-b


Run the command  tree /F

D:\KnowledgeHunt\setuptools> tree /F

Folder PATH listing for volume New Volume
Volume serial number is 8413-049D
D:.
│   setup.py
│   __init__.py
└───knowladgehunt
        cal.py
        __init__.py

and Run the command as below 

pip install . or pip3 install .

Now your package will be created accordingly 














Let's check how the module in your package will work

PS D:\KnowledgeHunt\setuptools> python

Python 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)] on win32

Type "help", "copyright", "credits" or "license" for more information.

>>> import knowladgehunt

>>> from knowladgehunt import cal

>>> cal.add(3,2)

5

>>> 

The add function returned 5 when I called it with the two parameters (3,2). Wow! package is fine.:)


Comments