-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpypi
executable file
·82 lines (74 loc) · 2.32 KB
/
pypi
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
#!/bin/bash
# INSTALL: symlink or copy this file to /usr/local/bin
#
# Create Python package and upload to PyPI
#
# Usage:
# $ pypi [-o out_dir] [-t] [-k] input_dir usr pswd
#
# Positional Arguments:
# * input_dir: full path to folder containing the package's __init__.py
# * usr and pswd: Credentials for PyPI (or Test PyPI)
#
# Options:
# * [-o out_dir]: Save package to out_dir/pypi-upload, defaults to current directory.
# * [-t]: test upload to Test PyPI instead of the actual PyPI
# * [-k]: do not autoremove the pypi-upload folder after uploading
#
# Notes:
# Make sure you have incremented the version number in setup.py before running
# PyPI URLs written for twine v1.12.1
# Parese CLI optional and positional arguments -------------------------------
out_dir="."
repo_url="https://upload.pypi.org/legacy/"
keep=false
while getopts "o:tk" opt; do
case $opt in
o)
if [ ! -d "$OPTARG" ]; then
echo "$OPTARG is not a valid directory"
exit 1
fi
out_dir=$OPTARG;;
t)
repo_url="https://test.pypi.org/legacy/";;
k)
keep=true;;
\?)
exit 1;;
:)
exit 1;;
esac
done
shift $((OPTIND - 1))
if [ "$#" -ne 3 ]; then
echo "You must enter exactly 3 positional arguments"
exit 1
fi
input_dir=$1
usr=$2
pswd=$3
# Determine package name -----------------------------------------------------
pkg_name=$(cat "$input_dir/__init__.py" |
grep ^name= |
sed 's/name=//;s/[^a-zA-Z]//g')
if [ -z $pkg_name ]; then
echo "__init__.py must have 'name=package_name' line"
exit 1
fi
# Move files to package directory --------------------------------------------
if [ ! -d "$out_dir/pypi-upload/$pkg_name" ]; then
mkdir -p "$out_dir/pypi-upload/$pkg_name"
fi
cp $input_dir/*.py $out_dir/pypi-upload/$pkg_name
parent_dir=$(dirname $input_dir)
cp $parent_dir/{LICENSE.txt,README.md,setup.py} $out_dir/pypi-upload
# Build package and upload ---------------------------------------------------
cd $out_dir/pypi-upload
python3 -m setup.py sdist bdist_wheel || true
twine upload --repository-url $repo_url -u $usr -p $pswd dist/*
# Clean up temporary pypi-upload folder --------------------------------------
if [ "$keep" = false ]; then
echo "entered if-statement"
rm -r $parent_dir/pypi-upload
fi