|
17 | 17 | with open(os.path.join(here, "responder", "__version__.py")) as f: |
18 | 18 | exec(f.read(), about) |
19 | 19 |
|
| 20 | +if sys.argv[-1] == "publish": |
| 21 | + os.system("python setup.py sdist bdist_wheel upload") |
| 22 | + sys.exit() |
| 23 | + |
20 | 24 | required = [ |
21 | 25 | "aiofiles", |
22 | 26 | "apispec>=1.0.0b1", |
@@ -64,6 +68,39 @@ def run(self): |
64 | 68 | os.system("dpkg-buildpackage -rfakeroot -uc -us") |
65 | 69 |
|
66 | 70 |
|
| 71 | +class UploadCommand(Command): |
| 72 | + """Support setup.py publish.""" |
| 73 | + |
| 74 | + description = "Build and publish the package." |
| 75 | + user_options = [] |
| 76 | + |
| 77 | + @staticmethod |
| 78 | + def status(s): |
| 79 | + """Prints things in bold.""" |
| 80 | + print("\033[1m{0}\033[0m".format(s)) |
| 81 | + |
| 82 | + def initialize_options(self): |
| 83 | + pass |
| 84 | + |
| 85 | + def finalize_options(self): |
| 86 | + pass |
| 87 | + |
| 88 | + def run(self): |
| 89 | + try: |
| 90 | + self.status("Removing previous builds…") |
| 91 | + rmtree(os.path.join(here, "dist")) |
| 92 | + except FileNotFoundError: |
| 93 | + pass |
| 94 | + self.status("Building Source distribution…") |
| 95 | + os.system("{0} setup.py sdist bdist_wheel".format(sys.executable)) |
| 96 | + self.status("Uploading the package to PyPI via Twine…") |
| 97 | + os.system("twine upload dist/*") |
| 98 | + self.status("Pushing git tags…") |
| 99 | + os.system("git tag v{0}".format(about["__version__"])) |
| 100 | + os.system("git push --tags") |
| 101 | + sys.exit() |
| 102 | + |
| 103 | + |
67 | 104 | setup( |
68 | 105 | name="responder", |
69 | 106 | version=about["__version__"], |
@@ -111,5 +148,5 @@ def run(self): |
111 | 148 | "Programming Language :: Python :: Implementation :: PyPy", |
112 | 149 | "Topic :: Internet :: WWW/HTTP", |
113 | 150 | ], |
114 | | - cmdclass={"deb": DebCommand}, |
| 151 | + cmdclass={"upload": UploadCommand, "deb": DebCommand}, |
115 | 152 | ) |
0 commit comments