Create a setup.py file, PyCharm has a tool for this. Tools -> create setup.py a basic setup.py file looks like this:
from setuptools import setup
with open('README.md') as readme:
long_description = readme.read()
setup(
name='PACKAGE_NAME',
version='VERSION',
packages=['PACKAGENAME'],
install_requires=['REQUIREMENTS'],
keywords='insert keywords',
long_description=long_description,
long_description_content_type="text/markdown",
url='URL TO PROJECT',
author='Kevin',
author_email='example@example.com',
description='Example description',
project_urls={
'Expackage': 'https://github.com/EXAMPLEUSER/EXAMPLE'}
)
After you've made the setup.py file, you have to build a distribution for the package. You can do this by executing this in the command line:
python setup.py bdist_wheel
Before you move on you need to ensure that your package still works, you can test it by executing
pip install -e .
and then you have to make sure that everything works the way it's supposed to.
If everything works, you can add a LICENSE to your package (optional). To help you choose the correct license for your project please visit: https://choosealicense.com. You can add the license to your project by creating a LICENSE.txt file in the root folder of your project. Then just copy and paste the text from choosealicense into the LICENSE.txt file and add the License name to the setup.py file, like so:
setup(
license='MIT'
)
(Optional) You can also add some classifiers to your setup.py file to categorize each release, describing who it's for, what systems it can run on, and how mature it is. A list of classifiers can be found at https://pypi.org/classifiers/. Example:
setup(
classifiers=['Development Status :: 1 - Planning']
)
After testing your previous test, you need to create a source distribution. You do this by executing:
python setup.py sdist
When this is done, test your package again and make sure everything is working!
Now run check-manifest, it creates a MANIFEST.in file for your package
pip install check-manifest
check-manifest --create
git add MANIFEST.in
Now finally build your package again by running
python setup.py bdist_wheel sdist
Your package is now ready to be uploaded to a PyPi server! I recommend first uploading to the https://test.pypi.org repository to test if everything works after installing it from PyPi.
You can use twine to upload to the test.pypi:
pip install twine
python -m twine upload --repository-url https://test.pypi.org/legacy/ dist/*
To upload to the normal PyPi website:
python -m twine upload dist*/
username: __token__
password: INSERT YOUR API TOKEN
You can add an API token to your account by visiting https://pypi.org/manage/account/token/
To upload to your own custom PyPi server:
with setup.py:
python setup.py sdist upload -r http://YOUR_IP:PORT/simple --trusted-host YOUR_IP
with twine:
python -m twine upload -r http://YOUR_IP:PORT/simple dist/* --trusted-host YOUR_IP