Let’s start from scratch :
Step : 1
- Login to Pypi : https://pypi.org/account/login/
2. Click on mentioned marked below:
3. Create API token for authentication and save it , otherwise you can’t retrieve the key later.
Step : 2
4. Create folder structure:
5. Let’s discuss about contains of necessary files as below :
a. setup.py
import setuptools
with open(“README.md”, “r”, encoding=”utf-8") as fh:
long_description = fh.read()
setuptools.setup(
name=”pkglogger”, # Replace with your own username
version=”0.0.11",
author=”Avik Das”,
author_email=”avik_das_2017@cba.isb.edu”,
description=”This package help you to keep logs”,
long_description=long_description,
long_description_content_type=”text/markdown”,
url=”https://github.com/pypa/sampleproject",
project_urls={
“Bug Tracker”: “https://github.com/pypa/sampleproject/issues",
},
classifiers=[
“Programming Language :: Python :: 2”,
“License :: OSI Approved :: MIT License”,
“Operating System :: OS Independent”,
],
package_dir={“”: “pkglogger”},
packages=setuptools.find_packages(where=”pkglogger”),
python_requires=”>=2.0",
)
b. README.md :
**#Developer : Avik Das**
- *##Steps to run the package :**
1.pip install pkglogger==<version number>
2. **from** pkglogger **import** pkglogger
3. pkglogger.logger(‘path/’,’’,’’,’’,’’,’’,’’)
4. *var1* = directory where log file will be created
5. *var2* = Logger number
6. *var3* = Function name
7. *var4* = Task status
8. *var5* = Error
9. *var6* = Output path
10. *var7* = URL Link
c.pyproject.toml: ( Important step )
[build-system]
requires = [
“setuptools>=42”,
“wheel”,
“datetime”
]
build-backend = “setuptools.build_meta”
Here , mentioned all necessary packages that need to be imported while running this package after importing.
Step: 3
6. Open “cmd” / “powershell”.
7. Set the path within the package directory :
for cmd : cd /d <path>
for powershell : cd <path>
8. Run following commands sequentially :
a. py -m pip install — upgrade build
b. py -m build ( Now run this command from the same directory where pyproject.toml
is located )
After this command, following files will be created :
Note : Before next command, check within “dist” ( generated by build command ) file whether the “Core Code” is there or not with “__init__.py” file within “.tar” file as shown above.
c. py -m pip install — user — upgrade twine
d. py -m twine upload — repository testpypi dist/*
You will be prompted for a username and password. For the username, use __token__
. For the password, use the token value, including the pypi-
prefix. Use mouse right click for pasting the API Key in cmd/ powershell.
Now, check your pypi account where you can get to see your package.