Skip to content

Commit 8f55520

Browse files
authored
Add setup.py commands for building and publishing (#31)
1 parent de77bb2 commit 8f55520

File tree

1 file changed

+87
-4
lines changed

1 file changed

+87
-4
lines changed

setup.py

Lines changed: 87 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,95 @@
1-
from setuptools import find_packages, setup
1+
import os
2+
import sys
3+
from pathlib import Path
4+
from shutil import rmtree
5+
from typing import List, Tuple
6+
7+
from setuptools import Command, find_packages, setup
8+
9+
# -----------------------------------------------------------------------------
10+
11+
here = os.path.abspath(os.path.dirname(__file__))
12+
13+
# read the contents of your README file
14+
this_directory = Path(__file__).parent
15+
long_description = (this_directory / "README.md").read_text()
16+
long_description_content_type = "text/markdown; charset=UTF-8; variant=GFM"
17+
18+
# -----------------------------------------------------------------------------
19+
20+
21+
class BaseCommand(Command):
22+
user_options: List[Tuple[str, str, str]] = []
23+
24+
@staticmethod
25+
def status(s: str) -> None:
26+
"""Prints things in bold."""
27+
print("\033[1m{0}\033[0m".format(s)) # noqa: T001
28+
29+
def system(self, command: str) -> None:
30+
os.system(command) # noqa: S605
31+
32+
def initialize_options(self):
33+
pass
34+
35+
def finalize_options(self):
36+
pass
37+
38+
39+
class BuildCommand(BaseCommand):
40+
"""Support setup.py building."""
41+
42+
description = "Build the package."
43+
44+
def run(self):
45+
try:
46+
self.status("Removing previous builds…")
47+
rmtree(os.path.join(here, "dist"))
48+
except OSError:
49+
pass
50+
51+
self.status("Building Source and Wheel (universal) distribution…")
52+
self.system("{0} -m build --sdist --wheel .".format(sys.executable))
53+
54+
self.status("Checking wheel contents…")
55+
self.system("check-wheel-contents dist/*.whl")
56+
57+
self.status("Running twine check…")
58+
self.system("{0} -m twine check dist/*".format(sys.executable))
59+
60+
61+
class UploadTestCommand(BaseCommand):
62+
"""Support uploading to test PyPI."""
63+
64+
description = "Upload the package to the test PyPI."
65+
66+
def run(self):
67+
self.status("Uploading the package to PyPi via Twine…")
68+
self.system(
69+
"twine upload --repository-url https://test.pypi.org/legacy/ dist/*"
70+
)
71+
72+
73+
class UploadCommand(BaseCommand):
74+
"""Support uploading to PyPI."""
75+
76+
description = "Upload the package to PyPI."
77+
78+
def run(self):
79+
self.status("Uploading the package to PyPi via Twine…")
80+
self.system("twine upload dist/*")
81+
282

383
# -----------------------------------------------------------------------------
484

585
DESCRIPTION = "Python DB-API and SQLAlchemy interface for Airtable."
686

787
setup(
888
name="sqlalchemy-airtable",
9-
version="0.0.1.dev0",
89+
version="0.0.1.dev1",
1090
description=DESCRIPTION,
11-
long_description=DESCRIPTION,
91+
long_description=long_description,
92+
long_description_content_type=long_description_content_type,
1293
author="Alex Rothberg",
1394
author_email="[email protected]",
1495
url="https://github.com/cancan101/airtable-db-api",
@@ -45,6 +126,8 @@
45126
],
46127
# $ setup.py publish support.
47128
cmdclass={
48-
# 'upload': UploadCommand,
129+
"buildit": BuildCommand,
130+
"uploadtest": UploadTestCommand,
131+
"upload": UploadCommand,
49132
},
50133
)

0 commit comments

Comments
 (0)