|
1 | | -from setuptools import find_packages, setup |
| 1 | +#!/usr/bin/env python |
| 2 | +# -*- coding: utf-8 -*- |
2 | 3 |
|
| 4 | +# Note: To use the 'upload' functionality of this file, you must: |
| 5 | +# $ pipenv install twine --dev |
| 6 | + |
| 7 | +import codecs |
| 8 | +import os |
| 9 | +import re |
| 10 | +import sys |
| 11 | + |
| 12 | +from shutil import rmtree |
| 13 | + |
| 14 | +from setuptools import Command, find_packages, setup |
| 15 | + |
| 16 | +NAME = "zelos-crashd" |
| 17 | +META_PATH = os.path.join("src", "crashd", "__init__.py") |
3 | 18 | PACKAGES = find_packages(where="src") |
| 19 | +KEYWORDS = [ |
| 20 | + "emulation", |
| 21 | + "dynamic analysis", |
| 22 | + "binary analysis", |
| 23 | + "zelos", |
| 24 | + "crash", |
| 25 | + "vulnerability assessment", |
| 26 | +] |
| 27 | +PROJECT_URLS = { |
| 28 | + "Bug Tracker": "https://github.com/zeropointdynamics/zelos-crashd/issues", |
| 29 | + "Source Code": "https://github.com/zeropointdynamics/zelos-crashd", |
| 30 | +} |
| 31 | +CLASSIFIERS = [ |
| 32 | + "Development Status :: 4 - Beta", |
| 33 | + "Natural Language :: English", |
| 34 | + "License :: OSI Approved :: GNU Affero General Public License v3", |
| 35 | + "Operating System :: OS Independent", |
| 36 | + "Programming Language :: Python", |
| 37 | + "Programming Language :: Python :: 3", |
| 38 | + "Programming Language :: Python :: 3.6", |
| 39 | + "Programming Language :: Python :: 3.7", |
| 40 | + "Programming Language :: Python :: 3.8", |
| 41 | +] |
| 42 | +INSTALL_REQUIRES = [ |
| 43 | + "zelos>=0.2.0", |
| 44 | + "graphviz", |
| 45 | + "pyelftools@git+git://github.com/eliben/pyelftools.git@7ca16680f4eb01e6b6bbbc222f18de56460426d1", |
| 46 | +] |
| 47 | + |
| 48 | +######################################################################## |
| 49 | + |
| 50 | +HERE = os.path.abspath(os.path.dirname(__file__)) |
| 51 | + |
| 52 | + |
| 53 | +def read(*parts): |
| 54 | + """ |
| 55 | + Build an absolute path from *parts* and and return the contents of |
| 56 | + the resulting file. Assume UTF-8 encoding. |
| 57 | + """ |
| 58 | + with codecs.open(os.path.join(HERE, *parts), "rb", "utf-8") as f: |
| 59 | + return f.read() |
| 60 | + |
| 61 | + |
| 62 | +META_FILE = read(META_PATH) |
| 63 | + |
| 64 | + |
| 65 | +def find_meta(meta): |
| 66 | + """ |
| 67 | + Extract __*meta*__ from META_FILE. |
| 68 | + """ |
| 69 | + meta_match = re.search( |
| 70 | + r"^__{meta}__ = ['\"]([^'\"]*)['\"]".format(meta=meta), META_FILE, re.M |
| 71 | + ) |
| 72 | + if meta_match: |
| 73 | + return meta_match.group(1) |
| 74 | + raise RuntimeError("Unable to find __{meta}__ string.".format(meta=meta)) |
| 75 | + |
4 | 76 |
|
5 | | -setup( |
6 | | - name="zelos_crashd", |
7 | | - # install_requires=["zelos", "graphviz"], |
8 | | - install_requires=[], |
9 | | - include_package_data=True, |
10 | | - packages=PACKAGES, |
11 | | - package_dir={"": "src"}, |
12 | | - entry_points={ |
13 | | - "zelos.plugins": [ |
14 | | - "asan=crashd.asan", |
15 | | - "dataflow=crashd.taint", |
16 | | - "ida=crashd.static_analysis", |
17 | | - ], |
18 | | - }, |
| 77 | +VERSION = find_meta("version") |
| 78 | +URL = find_meta("url") |
| 79 | +LONG = ( |
| 80 | + read("README.md") |
| 81 | + + "\n\n" |
| 82 | + + read("CHANGELOG.md") |
| 83 | + + "\n\n" |
| 84 | + + read("AUTHORS.md") |
19 | 85 | ) |
| 86 | + |
| 87 | + |
| 88 | +class UploadCommand(Command): |
| 89 | + """Support setup.py upload.""" |
| 90 | + |
| 91 | + description = "Build and publish the package." |
| 92 | + user_options = [] |
| 93 | + |
| 94 | + @staticmethod |
| 95 | + def status(s): |
| 96 | + """Prints things in bold.""" |
| 97 | + print("\033[1m{0}\033[0m".format(s)) |
| 98 | + |
| 99 | + def initialize_options(self): |
| 100 | + pass |
| 101 | + |
| 102 | + def finalize_options(self): |
| 103 | + pass |
| 104 | + |
| 105 | + def run(self): |
| 106 | + try: |
| 107 | + self.status("Removing previous builds…") |
| 108 | + rmtree(os.path.join(HERE, "dist")) |
| 109 | + except OSError: |
| 110 | + pass |
| 111 | + |
| 112 | + self.status("Building Source and Wheel (universal) distribution…") |
| 113 | + os.system( |
| 114 | + "{0} setup.py sdist bdist_wheel --universal".format(sys.executable) |
| 115 | + ) |
| 116 | + |
| 117 | + self.status("Uploading the package to PyPI via Twine…") |
| 118 | + os.system("twine upload dist/*") |
| 119 | + |
| 120 | + self.status("Pushing git tags…") |
| 121 | + os.system("git tag v{0}".format(VERSION)) |
| 122 | + os.system("git push --tags") |
| 123 | + |
| 124 | + sys.exit() |
| 125 | + |
| 126 | + |
| 127 | +if __name__ == "__main__": |
| 128 | + setup( |
| 129 | + name=NAME, |
| 130 | + description=find_meta("description"), |
| 131 | + license=find_meta("license"), |
| 132 | + url=URL, |
| 133 | + project_urls=PROJECT_URLS, |
| 134 | + version=VERSION, |
| 135 | + author=find_meta("author"), |
| 136 | + author_email=find_meta("email"), |
| 137 | + maintainer=find_meta("author"), |
| 138 | + maintainer_email=find_meta("email"), |
| 139 | + keywords=KEYWORDS, |
| 140 | + long_description=LONG, |
| 141 | + long_description_content_type="text/markdown", |
| 142 | + packages=PACKAGES, |
| 143 | + package_dir={"": "src"}, |
| 144 | + python_requires=">=3.6.0", |
| 145 | + zip_safe=False, |
| 146 | + classifiers=CLASSIFIERS, |
| 147 | + install_requires=INSTALL_REQUIRES, |
| 148 | + include_package_data=True, |
| 149 | + options={"bdist_wheel": {"universal": "1"}}, |
| 150 | + setup_requires=["wheel"], |
| 151 | + cmdclass={"upload": UploadCommand}, |
| 152 | + entry_points={ |
| 153 | + "zelos.plugins": [ |
| 154 | + "asan=crashd.asan", |
| 155 | + "dataflow=crashd.taint", |
| 156 | + "ida=crashd.static_analysis", |
| 157 | + ], |
| 158 | + }, |
| 159 | + ) |
0 commit comments