-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
96 lines (75 loc) · 2.13 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
"""
@author axiner
@version v1.0.0
@created 2021/12/12 13:14
@abstract
@description
@history
"""
import os
import re
import sys
from pathlib import Path
from shutil import rmtree
from pkg_resources import yield_lines
from setuptools import Command, setup
from versions import Versions
here = Path(__file__).absolute().parent
__verison__ = Versions.ALL[0][0]
with open('README.md', 'r', encoding='utf8') as f:
long_description = f.read()
with open('requirements.txt', 'r', encoding='utf8') as f:
install_requires = list(yield_lines(f.read()))
def update_version():
"""update version"""
vfile = here.joinpath('pytcli/__init__.py').as_posix()
with open(vfile, 'r', encoding='utf8') as fp:
file = fp.read()
with open(vfile, 'w', encoding='utf8') as fp:
file = re.sub(r'__version__ = "[\d.]+"', rf'__version__ = "{__verison__}"', file)
fp.write(file)
def bu():
"""build"""
update_version()
try:
print('Removing previous builds...')
rmtree(os.path.join(here, 'dist'))
except OSError:
pass
print('Building Source or Wheel distribution...')
# os.system('{0} setup.py sdist bdist_wheel'.format(sys.executable))
os.system('{0} setup.py bdist_wheel'.format(sys.executable))
class BuildCommand(Command):
"""support setup.py build"""
description = 'Build the package.'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
bu()
sys.exit()
class UploadCommand(Command):
"""support setup.py build&upload"""
description = 'Build and upload the package.'
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
bu()
print('Uploading the package to PyPI via Twine...')
os.system('twine upload dist/*')
sys.exit()
setup(
version=__verison__,
long_description=long_description,
long_description_content_type='text/markdown',
install_requires=install_requires,
cmdclass={
'bu': BuildCommand,
'up': UploadCommand,
},
)