-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
127 lines (114 loc) · 5.17 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
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
import setuptools, glob, os, fnmatch, shutil, shlex
from setup_import.fix_import import main
# main(('--application-directories', '.:void_terminal', 'void_terminal/crazy_functions/Langchain知识库.py',))
# main(('void_terminal/crazy_functions/Langchain知识库.py',))
def pack_up_fix_import():
source_list = glob.glob('./void_terminal/**/*.py', recursive=True)
confuse_list = [os.path.basename(t).rsplit('.py')[0] for t in glob.glob('./void_terminal/*.py')]
from setup_import.fix_import import main
try:
shutil.copytree('fake_gradio', 'void_terminal/fake_gradio')
except:
...
for fp in source_list:
main(('--application-directories', '.:void_terminal', fp,))
with open(fp, 'r', encoding='utf-8', newline='') as fd:
buf = fd.read()
# disable gradio
buf = buf.replace("import gradio as gr",
"import fake_gradio as gr")
buf = buf.replace("import gradio",
"import fake_gradio as gradio")
# align 1st-layer import
buf = buf.replace("import core_functional",
"import void_terminal.core_functional")
buf = buf.replace("importlib.import_module('config')",
"importlib.import_module('void_terminal.config')")
buf = buf.replace("importlib.import_module('config_private')",
"importlib.import_module('void_terminal.config_private')")
# disable path check
buf = buf.replace(
"def validate_path_safety(path_or_url, user):",
"def validate_path_safety(path_or_url:str, user:str): return True\n\ndef validate_path_safety_replaced(path_or_url, user):",
)
# fix message
buf = buf.replace(r"""AssertionError("你提供了错误的API_KEY。\n\n1. 临时解决方案:直接在输入区键入api_key,然后回车提交。\n\n2. 长效解决方案:在config.py中配置。")""",
r"""AssertionError("You have not provide an API_KEY. \n\n1. In python, run `void_terminal.set_conf('API_KEY', value='sk-abcd')` to load api key\n\n2. In bash, run `vt --set_conf API_KEY 'sk-abcd'`")""")
with open(fp, 'w', encoding='utf-8', newline='') as fd:
fd.write(buf)
return
pack_up_fix_import()
try:
shutil.copyfile('__init__.py', 'void_terminal/__init__.py')
shutil.copyfile('__init__.py', 'void_terminal/__init__.py')
except:
msg = "You must first clone the mother project with `git clone --depth=1 https://github.com/binary-husky/gpt_academic.git void_terminal`."
for i in range(100): print(msg)
raise RuntimeError(msg)
with open("README.md", "r", encoding="utf-8") as fh:
long_description = fh.read()
def _process_requirements(type):
if type == 'install_requires':
packages = open('void_terminal/requirements.txt').read().strip().split('\n')
requires = []
for pkg in packages:
if pkg.startswith('git+ssh'):
return_code = os.system('pip install {}'.format(pkg))
assert return_code == 0, 'error, status_code is: {}, exit!'.format(return_code)
if pkg.startswith('./docs'):
continue
elif pkg.startswith('pydantic'):
requires.append('pydantic')
elif pkg.startswith('https://'):
...
else:
requires.append(pkg)
return requires
else:
packages = open('void_terminal/requirements.txt').read().strip().split('\n')
requires = []
for pkg in packages:
if pkg.startswith('https://'):
requires.append(pkg)
else:
...
return requires
def package_files(directory, black_list):
paths = []
for (path, directories, filenames) in os.walk(directory):
for filename in filenames:
if not any([k in filename or k in path for k in black_list]):
paths.append(os.path.join('..', path, filename))
else:
print('ignore', filename)
return paths
extra_files = package_files('void_terminal',
black_list=['multi-language', 'gpt_log', '.git', 'private_upload', 'multi_language.py', 'build', '.github', '.vscode', '__pycache__', 'venv'])
setuptools.setup(
name="void-terminal",
version="1.1.2",
author="Qingxu",
author_email="[email protected]",
description="LLM based APIs",
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/binary-husky/void-terminal",
project_urls={
"Bug Tracker": "https://github.com/binary-husky/void-terminal/issues",
},
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
],
entry_points = {
'console_scripts': ['vt=void_terminal:cli'],
},
package_dir={"": "."},
package_data={"": extra_files},
include_package_data=True,
packages=setuptools.find_packages(where="."),
python_requires=">=3.8",
install_requires=_process_requirements(type='install_requires'),
dependency_links=_process_requirements(type='dependency_links'),
)