├── README.md ├── pymod.sh └── pymod_installer.sh /README.md: -------------------------------------------------------------------------------- 1 | ![](https://img.shields.io/badge/-BASH-yellowgreen?style=flat&logo=shell) 2 | 3 | # pypi_uploader 4 | A command to upload Python module to pypi.org server 5 | 6 | Create a directory anywhere with name `container` with the following structure 7 | 8 | ``` 9 | 10 | container 11 | |__ 12 | | |__ 13 | | |__ . 14 | | |__ . 15 | | |__ 16 | |__README.md 17 | 18 | ``` 19 | 20 | 21 | Required Installations 22 | 23 | 1) git 24 | 25 | ``` 26 | $ yum insall git 27 | ``` 28 | 29 | 2) python3 30 | 31 | ``` 32 | $ yum install python3 33 | ``` 34 | 35 | Run the following command to download the script and making the `pymod` command 36 | 37 | ``` 38 | $ wget https://raw.githubusercontent.com/YashIndane/pypi_uploader/main/pymod_installer.sh ; bash pymod_installer.sh 39 | ``` 40 | 41 | Usage 42 | 43 | Be in same directory where the `container` directory is present and execute following command- 44 | 45 | ``` 46 | $ pymod --github-username --github-token 47 | --pypi-username --pypi-password 48 | --author-name --version 49 | ``` 50 | -------------------------------------------------------------------------------- /pymod.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | #This bash script will upload your python module to pypi.org 4 | # 5 | #Create a directory anywhere with name 'container' with the following structure 6 | # 7 | # container 8 | # |__ 9 | # | |__ 10 | # | |__ . 11 | # | |__ . 12 | # | |__ 13 | # |__README.md 14 | # 15 | #Required Installations 16 | #1)git 17 | # $ yum insall git 18 | # 19 | #2)python3 20 | # $ yum install python3 21 | # 22 | #Executing the following command in the directory where 'container' directory is present 23 | # $ pymod --github-username --github-token 24 | # --pypi-username --pypi-password 25 | # --author-name --version 26 | # 27 | #Author: Yash Indane 28 | #Email: yashindane46@gmail.com 29 | 30 | ARGS=$(getopt -a --options a:b:c:d:e:v: --long "github-username:,github-token:,pypi-username:,pypi-password:,author-name:,version:" -- "$@") 31 | 32 | eval set -- "$ARGS" 33 | 34 | while true; do 35 | case "$1" in 36 | -a|--github-username) 37 | GITHUB_USERNAME="$2" 38 | shift 2;; 39 | -b|--github-token) 40 | GITHUB_TOKEN="$2" 41 | shift 2;; 42 | -c|--pypi-username) 43 | PYPI_USERNAME="$2" 44 | shift 2;; 45 | -d|--pypi-password) 46 | PYPI_PASSWORD="$2" 47 | shift 2;; 48 | -e|--author-name) 49 | AUTHOR_NAME="$2" 50 | shift 2;; 51 | -v|--version) 52 | VERSION="$2" 53 | shift 2;; 54 | --) 55 | break;; 56 | esac 57 | done 58 | 59 | printf "UPGRADING PIP\n" 60 | sudo python3 -m pip install --upgrade pip 61 | 62 | printf "INSTALLING WHEEL\n" 63 | sudo pip3 install wheel 64 | 65 | printf "UPGRADING SETUPTOOLS\n" 66 | sudo pip3 install --upgrade setuptools 67 | 68 | printf "UNINSTALLING TWINE\n" 69 | echo 'Y' | sudo pip3 uninstall twine 70 | 71 | printf "INSTALLING TWINE\n" 72 | sudo pip3 install twine 73 | 74 | printf "UNINSTALLING URLLIB3\n" 75 | echo 'Y' | sudo pip3 uninstall urllib3 76 | 77 | printf "INSTALLING URLLIB3\n" 78 | sudo pip3 install urllib3 79 | 80 | sudo touch container/__init__.py 81 | 82 | #Getting the module directory name 83 | declare -a dirs 84 | i=1 85 | cd container 86 | for d in */ 87 | do 88 | dirs[i++]="${d%/}" 89 | done 90 | 91 | module_dir=${dirs[1]} 92 | 93 | cd $module_dir 94 | 95 | #Reading file names 96 | while read line 97 | do 98 | 99 | #Getting file name 100 | filename=$(echo $line | awk '{ print $10 }') 101 | 102 | #Removing file extension 103 | filename=$(echo $filename | cut -f 1 -d '.') 104 | 105 | if [ ! -z $filename ] 106 | then 107 | #Editing the file 108 | echo "from $module_dir.$filename import *" >> ../__init__.py 109 | fi 110 | 111 | ((i++)) 112 | 113 | done < <(ls -ls) 114 | 115 | mv ../__init__.py . 116 | 117 | cd .. 118 | 119 | #Creating the LICENSE.txt 120 | printf "CREATING LICENSE FILE\n" 121 | sudo touch LICENSE.txt 122 | 123 | #Editing LICENSE.txt file 124 | printf "EDITING LICENSE FILE\n" 125 | sudo echo "MIT License 126 | 127 | Copyright (c) 2021 $AUTHOR_NAME 128 | 129 | Permission is hereby granted, free of charge, to any person obtaining a copy 130 | of this software and associated documentation files (the 'Software'), to deal 131 | in the Software without restriction, including without limitation the rights 132 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 133 | copies of the Software, and to permit persons to whom the Software is 134 | furnished to do so, subject to the following conditions: 135 | 136 | The above copyright notice and this permission notice shall be included in all 137 | copies or substantial portions of the Software. 138 | 139 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 140 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 141 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 142 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 143 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 144 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 145 | SOFTWARE." >> LICENSE.txt 146 | 147 | #Creating setup.py file 148 | printf "CREATING SETUP FILE\n" 149 | sudo touch setup.py 150 | 151 | #Editing setup.py file 152 | printf "EDITING SETUP FILE\n" 153 | sudo echo "import setuptools 154 | 155 | with open('README.md' , 'r') as f: 156 | long_description = f.read() 157 | 158 | setuptools.setup( 159 | name='$module_dir', 160 | version='$VERSION', 161 | author='$AUTHOR_NAME', 162 | author_email='', 163 | description='', 164 | long_description=long_description, 165 | long_description_content_type='text/markdown', 166 | url='https://github.com/$GITHUB_USERNAME/$module_dir', 167 | packages=setuptools.find_packages(), 168 | classifiers=[ 169 | 'Programming Language :: Python :: 3', 170 | 'License :: OSI Approved :: MIT License', 171 | 'Operating System :: OS Independent', 172 | ], 173 | python_requires='>=3.6', 174 | )" >> setup.py 175 | 176 | #Making the GiHub repository 177 | printf "MAKING THE GITHUB REPOSITORY\n" 178 | sudo curl https://$GITHUB_USERNAME:$GITHUB_TOKEN@api.github.com/user/repos -d '{"name":"'$module_dir'","private":false}' 179 | 180 | #Initialize git 181 | printf "INITIALIZING GIT\n" 182 | sudo git init 183 | 184 | #Adding to staging 185 | sudo git add . 186 | 187 | #Making the commit 188 | printf "MAKING COMMIT\n" 189 | sudo git commit -m "first commit" 190 | 191 | #Getting to main branch 192 | sudo git branch -M main 193 | 194 | #Adding origin 195 | sudo git remote add origin https://github.com/$GITHUB_USERNAME/$module_dir.git 196 | 197 | #Push the code 198 | printf "PUSHING THE CODE\n" 199 | sudo git push https://$GITHUB_USERNAME:$GITHUB_TOKEN@github.com/$GITHUB_USERNAME/$module_dir.git --all 200 | 201 | #Compiling setup.py file 202 | printf "COMPILING SETUP FILE\n" 203 | sudo python3 setup.py sdist bdist_wheel 204 | 205 | #Upload module to pypi.org 206 | printf "UPLOADING MODULE TO PYPI.ORG\n" 207 | sudo python3 -m twine upload --repository-url https://upload.pypi.org/legacy/ dist/* -u $PYPI_USERNAME -p $PYPI_PASSWORD 208 | -------------------------------------------------------------------------------- /pymod_installer.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | #This script installs pymod command to system 4 | 5 | mkdir /pymod_dir 6 | wget https://raw.githubusercontent.com/YashIndane/pypi_uploader/main/pymod.sh -P /pymod_dir 7 | chmod +x /pymod_dir/pymod.sh 8 | ln -s /pymod_dir/pymod.sh /bin/pymod 9 | --------------------------------------------------------------------------------