1import codecs
2import os
3import re
4
5from setuptools import find_packages, setup
6
7
8###############################################################################
9
10NAME = "service_identity"
11KEYWORDS = ["cryptography", "openssl", "pyopenssl"]
12CLASSIFIERS = [
13    "Development Status :: 5 - Production/Stable",
14    "Intended Audience :: Developers",
15    "License :: OSI Approved :: MIT License",
16    "Natural Language :: English",
17    "Operating System :: MacOS :: MacOS X",
18    "Operating System :: Microsoft :: Windows",
19    "Operating System :: POSIX :: BSD",
20    "Operating System :: POSIX :: Linux",
21    "Operating System :: POSIX",
22    "Programming Language :: Python :: 2",
23    "Programming Language :: Python :: 2.7",
24    "Programming Language :: Python :: 3",
25    "Programming Language :: Python :: 3.4",
26    "Programming Language :: Python :: 3.5",
27    "Programming Language :: Python :: 3.6",
28    "Programming Language :: Python :: 3.7",
29    "Programming Language :: Python :: Implementation :: CPython",
30    "Programming Language :: Python :: Implementation :: PyPy",
31    "Programming Language :: Python",
32    "Topic :: Security :: Cryptography",
33    "Topic :: Software Development :: Libraries :: Python Modules",
34]
35INSTALL_REQUIRES = [
36    "attrs>=16.0.0",
37    "ipaddress; python_version<'3.3'",
38    "pyasn1-modules",
39    # Place pyasn1 after pyasn1-modules to workaround setuptools install bug:
40    # https://github.com/pypa/setuptools/issues/498
41    "pyasn1",
42    "cryptography",
43]
44EXTRAS_REQUIRE = {
45    "idna": ["idna"],
46    "tests": ["coverage>=4.2.0", "pytest"],
47    "docs": ["sphinx"],
48}
49EXTRAS_REQUIRE["dev"] = (
50    EXTRAS_REQUIRE["tests"] + EXTRAS_REQUIRE["docs"] + ["idna", "pyOpenSSL"]
51)
52
53###############################################################################
54
55HERE = os.path.abspath(os.path.dirname(__file__))
56PACKAGES = find_packages(where="src")
57META_PATH = os.path.join(HERE, "src", NAME, "__init__.py")
58
59
60def read(*parts):
61    """
62    Build an absolute path from *parts* and and return the contents of the
63    resulting file.  Assume UTF-8 encoding.
64    """
65    with codecs.open(os.path.join(HERE, *parts), "rb", "utf-8") as f:
66        return f.read()
67
68
69META_FILE = read(META_PATH)
70
71
72def find_meta(meta):
73    """
74    Extract __*meta*__ from META_FILE.
75    """
76    meta_match = re.search(
77        r"^__{meta}__ = ['\"]([^'\"]*)['\"]".format(meta=meta), META_FILE, re.M
78    )
79    if meta_match:
80        return meta_match.group(1)
81    raise RuntimeError("Unable to find __{meta}__ string.".format(meta=meta))
82
83
84URI = find_meta("uri")
85LONG = (
86    read("README.rst")
87    + "\n\n"
88    + "Release Information\n"
89    + "===================\n\n"
90    + re.search(
91        r"(\d{2}.\d.\d \(.*?\)\n.*?)\n\n\n----\n\n\n",
92        read("CHANGELOG.rst"),
93        re.S,
94    ).group(1)
95    + "\n\n`Full changelog "
96    + "<{uri}en/stable/changelog.html>`_.\n\n"
97    + read("AUTHORS.rst")
98).format(uri=URI)
99
100
101if __name__ == "__main__":
102    setup(
103        name=NAME,
104        description=find_meta("description"),
105        license=find_meta("license"),
106        url=URI,
107        version=find_meta("version"),
108        author=find_meta("author"),
109        author_email=find_meta("email"),
110        maintainer=find_meta("author"),
111        maintainer_email=find_meta("email"),
112        keywords=KEYWORDS,
113        long_description=LONG,
114        packages=PACKAGES,
115        package_dir={"": "src"},
116        zip_safe=False,
117        classifiers=CLASSIFIERS,
118        install_requires=INSTALL_REQUIRES,
119        extras_require=EXTRAS_REQUIRE,
120    )
121