forked from PyPtt/PyPtt
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsetup.py
More file actions
128 lines (103 loc) · 4.34 KB
/
setup.py
File metadata and controls
128 lines (103 loc) · 4.34 KB
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import os
import subprocess
import time
from setuptools import setup
def version_automation_script():
is_merged = os.environ.get('GITHUB_EVENT_NAME') == 'pull_request'
print('is_merged:', is_merged)
# read the main version from __init__.py
with open('PyPtt/__init__.py', 'r', encoding='utf-8') as f:
data = f.read().strip()
main_version = data.split('_main_version = ')[1].split('\n')[0].strip().strip('\'')
print('main_version version:', main_version)
version = None
pypi_version = None
for i in range(5):
try:
# Use wget to retrieve the PyPI version information
subprocess.run(['wget', '-q', '-O', 'pypi_version.json', 'https://pypi.org/pypi/PyPtt/json'], check=True)
with open('pypi_version.json', 'r', encoding='utf-8') as f:
pypi_data = f.read()
pypi_version = pypi_data.split('"version":')[1].split('"')[1]
if pypi_version.startswith(main_version):
min_pypi_version = pypi_version.split('.')[-1]
# the next version
version = f"{main_version}.{int(min_pypi_version) + 1}"
else:
version = f"{main_version}.0"
break
except subprocess.CalledProcessError:
time.sleep(1)
if version is None or pypi_version is None:
raise ValueError('Can not get version from pypi')
if not is_merged:
commit_file = '/tmp/commit_hash.txt'
if os.path.exists(commit_file):
with open(commit_file, 'r', encoding='utf-8') as f:
commit_hash = f.read().strip()
else:
max_hash_length = 5
try:
commit_hash = subprocess.check_output(['git', 'rev-parse', '--long', 'HEAD']).decode('utf-8').strip()
except subprocess.CalledProcessError:
commit_hash = '0' * max_hash_length
commit_hash = ''.join([x for x in list(commit_hash) if x.isdigit()])
if len(commit_hash) < max_hash_length:
commit_hash = commit_hash + '0' * (max_hash_length - len(commit_hash))
commit_hash = commit_hash[:max_hash_length]
with open(commit_file, 'w', encoding='utf-8') as f:
f.write(commit_hash)
version = f"{version}.dev{commit_hash}"
if '__version__' in data:
current_version = data.split('__version__ = ')[1].split('\n')[0].strip().strip('\'')
data = data.replace(f"__version__ = '{current_version}'", f"__version__ = '{version}'")
else:
data += f'\n\n__version__ = \'{version}\''
with open('PyPtt/__init__.py', 'w', encoding='utf-8') as f:
f.write(data)
f.write('\n')
return version
version = version_automation_script()
print('the next version:', version)
setup(
name='PyPtt', # Required
version=version, # Required
description='PyPtt\ngithub: https://github.com/PyPtt/PyPtt', # Required
long_description=open('README.md', encoding="utf-8").read(), # Optional
long_description_content_type='text/markdown',
url='https://pyptt.cc/', # Optional
author='CodingMan', # Optional
author_email='pttcodingman@gmail.com', # Optional
# https://pypi.org/classifiers/
classifiers=[ # Optional
'Development Status :: 5 - Production/Stable',
'Operating System :: OS Independent',
'Intended Audience :: Developers',
'Topic :: Communications :: BBS',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Internet',
'License :: OSI Approved :: GNU Lesser General Public License v3 (LGPLv3)',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3 :: Only',
'Natural Language :: Chinese (Traditional)',
'Natural Language :: English',
],
keywords=['PTT', 'crawler', 'bot', 'library', 'websockets'], # Optional
python_requires='>=3.8',
packages=['PyPtt'],
install_requires=[
'progressbar2',
'websockets',
'uao',
'requests',
'AutoStrEnum',
'PyYAML',
],
package_data={
'PyPtt': ['lang/*.yaml'],
}
)