Skip to content

Instantly share code, notes, and snippets.

@lamoboos223
Last active December 10, 2024 15:21
Show Gist options
  • Save lamoboos223/e1b8e3638e3b5eddd01ae0bf2d1c8d73 to your computer and use it in GitHub Desktop.
Save lamoboos223/e1b8e3638e3b5eddd01ae0bf2d1c8d73 to your computer and use it in GitHub Desktop.
Upload package to PyPi and PyPi Test
#!/bin/sh
rm setup.py
rm -rf *.egg.info build/ dist/
curl -s https://raw.githubusercontent.com/lamoboos223/general/main/lama-logo.sh | bash
echo "Creating setup.py file, please submit the package info below."
echo "Library Name (will be displayed on the pypi)?"
read name
echo "Version Number?"
read version_number
echo "Author Name?"
read author_name
echo "Package Description?"
read package_description
echo "package Name (your code that need to be packaged)?"
read package_name
echo "license?"
read license
echo "keywords --> example: ['kafka', 'message-queue']"
read keywords
echo "source code github url?"
read github_url
printf 'import setuptools
with open("README.md") as readme_file:
README = readme_file.read()
setuptools.setup(
name="%s",
version="%s",
author="%s",
description="%s",
long_description_content_type="text/markdown",
long_description=README,
packages=["%s"],
license="%s",
keywords=%s,
url="%s"
)' "$name" "$version_number" "$author_name" "$package_description" "$package_name" "$license" "$keywords" "$github_url" >> setup.py
echo "Created setup.py file."
python3 -m pip install --user --upgrade setuptools
pip install twine
pip install .
python3 setup.py sdist
echo "Select deployment environment:"
echo "
1. Test PyPi
2. Prod PyPi
3. Both"
read choice
case $choice in
"1")
echo "Publishing package $name into Test PyPi environment"
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
;;
"2")
echo "Publishing package $name into Prod PyPi environment"
twine upload dist/*
;;
"3")
echo "Publishing package $name into Test PyPi & Prod PyPi environment"
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
twine upload dist/*
;;
*)
echo "Nice one :) , try next time with the given choices"
rm setup.py
esac
echo "You're all set ^_^"
@lamoboos223
Copy link
Author

lamoboos223 commented Oct 18, 2022

Prerequisites

1- you must be registered into PyPi or PyPi test.
2- Your project should follow the below structure, README file in the root of your project. And you must add __init__.py file in your package directory.

.
+--- hello_world_package
| +--- my_file.py
| +--- __init__.py
+--- README.md

__init__.py

from .my_file import my_class

my_file.py

class my_class():
    
    def my_function():
        print("Hello, World")

import package

from hello_world_package import my_class
my_class.my_function()

@lamoboos223
Copy link
Author

lamoboos223 commented Oct 18, 2022

usage

bash <(curl -s https://gist.githubusercontent.com/lamoboos223/e1b8e3638e3b5eddd01ae0bf2d1c8d73/raw/583ef91f24f59fbf5eac92604b3c2a02d723f4f3/publish_to_pypi.sh)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment