-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
148 lines (120 loc) · 4.41 KB
/
setup.py
File metadata and controls
148 lines (120 loc) · 4.41 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
-------------------------------------------------------------------------
This file is part of the RAGSDK project.
Copyright (c) 2025 Huawei Technologies Co.,Ltd.
RAGSDK is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
-------------------------------------------------------------------------
"""
import datetime
import glob
import logging
import os
import shutil
import stat
from pathlib import Path
import yaml
from setuptools import setup, find_packages
from setuptools.command.build_py import build_py as build_py_orig
this_directory = Path(__file__).parent
long_description = (this_directory / "README.md").read_text()
build_folder = ('build/bdist*', 'build/lib')
cache_folder = ('mx_rag.egg-info', '_package_output')
pwd = os.path.dirname(os.path.realpath(__file__))
pkg_dir = os.path.join(pwd, "build/lib")
def get_ci_version_info():
"""
Get version information from ci config file
:return: version number
"""
ci_version_file = this_directory.joinpath('ci', 'config', 'config.ini')
version = '7.0.RC1'
logging.info("get version from %s", ci_version_file)
try:
R_FLAGS = os.O_RDONLY
MODES = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH
with os.fdopen(os.open(ci_version_file, R_FLAGS, MODES), 'r') as f:
for line in f:
line = line.strip()
if not line or line.startswith('#'):
continue
if ':' in line:
key, value = line.split(':', 1)
else:
continue
if key.strip() == 'version':
version = value.strip()
break
except Exception as ex:
logging.warning("get version failed, %s", str(ex))
return version
def build_dependencies():
"""generate python file"""
version_file = os.path.join(pkg_dir, 'mx_rag', 'version.py')
version_file_dir = os.path.join(pkg_dir, 'mx_rag')
if not os.path.exists(version_file_dir):
os.makedirs(version_file_dir, exist_ok=True)
with os.fdopen(os.open(version_file, os.O_WRONLY | os.O_CREAT, mode=stat.S_IRUSR | stat.S_IWUSR), 'w') as f:
f.write(f"__version__ = '{get_ci_version_info()}'\n")
f.write(f"__build_time__ = '{datetime.date.today()}'\n")
def clean():
for folder in cache_folder:
if os.path.exists(folder):
shutil.rmtree(folder)
for pattern in build_folder:
for name in glob.glob(pattern):
if os.path.exists(name):
shutil.rmtree(name)
def get_all_py_files():
src_dir = f"{pwd}/mx_rag"
file_list = []
for name in glob.glob(f"{src_dir}/**/*.py", recursive=True):
file = name[len(src_dir) + 1:]
file_list.append(file)
return file_list
def get_all_json_files():
src_dir = f"{pwd}/mx_rag"
file_list = []
for name in glob.glob(f"{src_dir}/evaluate/**/*.json", recursive=True):
file = name[len(src_dir) + 1:]
file_list.append(file)
for name in glob.glob(f"{src_dir}/tools/**/*.json", recursive=True):
file = name[len(src_dir) + 1:]
file_list.append(file)
return file_list
clean()
build_dependencies()
required_package = []
package_data = {'': get_all_py_files() + get_all_json_files()}
class BuildBy(build_py_orig):
def find_package_modules(self, package, package_dir):
modules = super().find_package_modules(package, package_dir)
res = []
for pkg, mod, file in modules:
res.append((pkg, mod, file))
return res
setup(
name='mx_rag',
version=get_ci_version_info(),
platforms=['linux', ],
description='RAGSDK is library to build RAG system',
python_requires='>= 3.10, <3.12',
long_description=long_description,
long_description_content_type="text/markdown",
install_requires=required_package,
package_data=package_data,
packages=find_packages(exclude=["*test*"]),
include_package_data=True,
cmdclass={
'build_py': BuildBy,
},
)
clean()