filmov
tv
How to Create Python Package and Upload to PyPi
Показать описание
Create new project
pip install --upgrade pip
pip install twine wheel setuptools
create README.md
# my_test_project
This is a simple test project
create LICENSE.txt
MIT License
Copyright (c) 2024 The Urban Penguin
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
from setuptools import setup, find_packages
from os import path
setup(
name='my_test_project_am', # name of packe which will be package dir below project
version='0.0.1',
author='The Urban Penguin',
description='Simple test package',
long_description=long_description,
long_description_content_type='text/markdown',
packages=find_packages(), auto_discover packages
install_requires=[],
)
Now in package create module with function
project-
- README.md
- LICENSE.txt
- my_test_project_am/
- add_two_numbers()
Now create sdist (source dist) and bdist (Binary dist) files
To distribute your Python packages via PyPI (Python Package Index), it's common practice to generate both source distribution (sdist) and built distribution (often a wheel, which is a kind of binary distribution).
Here's why you might want to create both types:
Source Distribution (sdist):
Built Distribution (wheel):
Ideally, when publishing a package to PyPi, you'd upload both source (sdist) and built (wheel) distributions. This is because not all platforms or versions of Python out there may be compatible with a pre-built wheel file, but theoretically, they could all install from the source distribution. On the other hand, wheel is faster and easier to install, which is why it's preferred when compatible
check for errors or warning with twine
twine check dist/*
upload to testpypi ( you'll need API or username and password depending on your system )
create new project
Комментарии