-
Notifications
You must be signed in to change notification settings - Fork 10
/
setup.py
84 lines (65 loc) · 2.75 KB
/
setup.py
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
# -*- coding: utf-8 -*-
import os
import setuptools
# ======================================================================================================================
# Fill in this information for each package.
# ======================================================================================================================
AUTHOR = "Hao Xue"
EMAIL = "xuehaoperth@gmail.com"
PACKAGE_NAME = "pytp"
DESCRIPTION = "Useful Tools for Trajectory Prediction."
REPO = "https://github.com/xuehaouwa/Trajectory-Prediction-Tools"
# ======================================================================================================================
# Automatic Package Setup Script.
# ======================================================================================================================
with open("version", "r") as f:
VERSION = f.readline()
def find_packages_under(path):
""" Recursive list all of the packages under a specific package."""
all_packages = setuptools.find_packages()
packages = []
for package in all_packages:
package_split = package.split(".")
if package_split[0] == path:
packages.append(package)
return packages
def copy_version_to_package(path):
""" Copy the single source of truth version number into the package as well. """
init_file = os.path.join(path, "__init__.py")
with open(init_file, "r") as original_file:
lines = original_file.readlines()
with open(init_file, "w") as new_file:
for line in lines:
if "__version__" not in line:
new_file.write(line)
else:
new_file.write("__version__ = \"{}\"\n".format(VERSION))
copy_version_to_package(PACKAGE_NAME)
setuptools.setup(
author=AUTHOR,
author_email=EMAIL,
name=PACKAGE_NAME,
description=DESCRIPTION,
version=VERSION,
url=REPO,
packages=find_packages_under(PACKAGE_NAME),
package_dir={PACKAGE_NAME: PACKAGE_NAME},
install_requires=[
"python-dotenv"
],
classifiers=[
"Programming Language :: Python :: 3.6"
],
)
# ===================================================================================================
# Upload to PyPI. Get the user and password from the environment.
# ===================================================================================================
key_repo_user = "REPO_USER"
key_repo_pass = "REPO_PASS"
if key_repo_user in os.environ and key_repo_pass in os.environ:
repo_user = os.environ[key_repo_user]
repo_pass = os.environ[key_repo_pass]
with open("upload_to_pypi.sh", 'w') as f:
f.write('#!/usr/bin/env bash\n')
f.write('pip install twine\n')
f.write('twine upload -u {} -p {} dist/*\n'.format(repo_user, repo_pass))