This repository has been archived by the owner on May 25, 2020. It is now read-only.
forked from justinmayer/django-autoslug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpypi_packager.sh
executable file
·124 lines (107 loc) · 3.63 KB
/
pypi_packager.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
# This script generates a package and submits it to the Python Package Index
# Copyright (C) 2017-2018 Marc Bourqui
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#==============================================================================
#title :pypi_packager.sh
#description :This script will build a source distribution and wheel. It
# converts a README.md to README.rst for nice rendering on PyPI.
#author :https://github.com/mbourqui
#licence :GNU GPL-3.0
#date :20170526
#version :1.2.1
#usage :bash pypi_packager.sh
#requires :pandoc
#==============================================================================
PROGRAM_NAME=$(basename "$0")
VERSION=1.2.1
PROJECT_NAME=$(basename $(pwd))
PACKAGE_NAME=${PROJECT_NAME//-/_} # Replace all - with _
copyright() {
echo "$PROGRAM_NAME Copyright (C) 2017-2018 Marc Bourqui"
}
usage() {
copyright
echo "
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it under certain
conditions, see <http://www.gnu.org/licenses/> for details.
Script to build source distribution and wheel for a python package. Also
converts a README.md to README.rst thanks to pandoc for nice rendering on PyPI.
Usage: $PROGRAM_NAME [-h,--help,-v,--version] [-s,--submit|-t,--test]
Options:
-s, --submit upload the package to PyPI.
-t, --test upload the package to TestPyPI.
-h, --help display this help and exit
-v, --version output version information and exit"
}
# Parse arguments
TEMP=$(getopt -n $PROGRAM_NAME -o sthv --long submit,test,help,version -- "$@")
if [ $? != 0 ] ; then usage >&2 ; exit 1 ; fi
eval set -- "$TEMP"
while true; do
case $1 in
-s|--submit)
SUBMIT=1; shift; continue
;;
-t|--test)
TEST=1; shift; continue
;;
-h|--help)
usage
exit
;;
-v|--version)
echo $VERSION
exit
;;
--)
# no more arguments to parse
shift
break
;;
*)
break
;;
esac
done
eval set -- "$@"
if [ -n "$SUBMIT" -a -n "$TEST" ]; then
echo "ERROR: Incompatible options"
echo
usage
exit 1
fi
copyright
echo "Thank you for using this utility"
# Clear previous compilations to prevent potential issues and limit disk space
# usage
rm -f README.rst
rm -rf dist/ build/ ${PACKAGE_NAME}.egg-info/
# Generate doc as restructured text for nice PyPI rendering
pandoc --from=markdown --to=rst --output=README.rst README.md
# Source distribution
python setup.py sdist
# Wheel
python setup.py bdist_wheel
if [ -n "$SUBMIT" ]; then
# Pre-registration to PyPI is no longer required or supported, upload
# directly
twine upload dist/*
elif [ -n "$TEST" ]; then
# Upload to TestPyPI
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
pip install --index-url https://test.pypi.org/legacy/ $PACKAGE_NAME
fi