-
Notifications
You must be signed in to change notification settings - Fork 2
/
setup.py
114 lines (90 loc) · 3.27 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
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
import os
import re
import sys
import subprocess
from shutil import rmtree
import setuptools
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
def find_version(fname):
"""Attempts to find the version number in the file names fname.
Raises RuntimeError if not found.
"""
version = ""
with open(fname, "r") as fp:
regex = re.compile(r'__version__ = [\'"]([^\'"]*)[\'"]')
for line in fp:
m = regex.match(line)
if m:
version = m.group(1)
break
if not version:
raise RuntimeError("Cannot find version information")
return version
def read(fname):
with open(os.path.join(os.path.dirname(__file__), fname), "r") as fh:
return fh.read()
__version__ = find_version("universal_analytics/__init__.py")
class ReleaseCommand(setuptools.Command):
"""Support setup.py release and upload on PyPi."""
description = "Build and publish the package."
user_options = []
@staticmethod
def status(s):
"""Prints things in bold."""
print("\033[1m{0}\033[0m".format(s))
def initialize_options(self):
pass
def finalize_options(self):
pass
def _run(self, s, command):
try:
self.status(s + "\n" + " ".join(command))
subprocess.check_call(command)
except subprocess.CalledProcessError as error:
sys.exit(error.returncode)
def run(self):
try:
self.status("Removing previous builds…")
rmtree(os.path.join(BASE_DIR, "dist"))
except OSError:
pass
self._run(
"Building Source and Wheel (universal) distribution…",
[sys.executable, "setup.py", "sdist", "bdist_wheel", "--universal"],
)
self._run(
"Installing Twine dependency…",
[sys.executable, "-m", "pip", "install", "twine"],
)
self._run(
"Uploading the package to PyPI via Twine…",
[sys.executable, "-m", "twine", "upload", "dist/*"],
)
self._run("Creating git tags…", ["git", "tag", f"v{__version__}"])
self._run("Pushing git tags…", ["git", "push", "--tags"])
setuptools.setup(
name="universal-analytics-python3",
version=__version__,
author="Dmitri Vasilishin",
author_email="[email protected]",
description="Universal analytics python library",
long_description=read("README.md"),
long_description_content_type="text/markdown",
url="https://github.com/dmvass/universal-analytics-python3",
packages=setuptools.find_packages(exclude=("test*",)),
classifiers=[
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
keywords=["python", "analytics", "google-analytics"],
install_requires=["httpx>=0.10.0"],
setup_requires=["pytest-runner", "flake8"],
tests_require=["coverage", "pytest", "pytest-asyncio", "asynctest"],
cmdclass={"release": ReleaseCommand}
)