Skip to content

Commit adb5e13

Browse files
committed
feat(setup.py): add custom build and publish commands
- Introduced `build` command for packaging the project. - Added `publish` command with version option to streamline the PyPI upload process.
1 parent 4061a59 commit adb5e13

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

setup.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,41 @@
1-
from setuptools import setup, find_packages
1+
import os
2+
from setuptools import setup, find_packages, Command
23

34
from pathlib import Path
45
this_directory = Path(__file__).parent
56
long_description = (this_directory / "README.md").read_text()
67

8+
9+
class BuildCommand(Command):
10+
description = 'Build the package'
11+
user_options = []
12+
13+
def initialize_options(self):
14+
pass
15+
16+
def finalize_options(self):
17+
pass
18+
19+
def run(self):
20+
os.system('python setup.py sdist')
21+
22+
23+
class PublishCommand(Command):
24+
description = 'Publish the package to PyPI'
25+
user_options = [('version=', 'v', 'version number of the package to be uploaded')]
26+
version = None
27+
28+
def initialize_options(self):
29+
pass
30+
31+
def finalize_options(self):
32+
if self.version is None:
33+
raise Exception("Version number is required. Use --version=<version_number>")
34+
35+
def run(self):
36+
os.system(f"twine upload ./dist/django-appwrite-{self.version}.tar.gz")
37+
38+
739
setup(
840
name='django-appwrite',
941
version='1.5.0',
@@ -37,4 +69,8 @@
3769
"Programming Language :: Python :: 3.9",
3870
"Programming Language :: Python :: 3.10"
3971
],
72+
cmdclass={
73+
'build': BuildCommand,
74+
'publish': PublishCommand,
75+
},
4076
)

0 commit comments

Comments
 (0)