setup.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import glob
  15. import itertools
  16. import os
  17. from pathlib import Path
  18. from setuptools import find_packages, setup
  19. DEP_SPECS = {
  20. "aiohttp": ">= 3.9",
  21. "bce-python-sdk": ">= 0.9",
  22. "chardet": "",
  23. "chinese-calendar": "",
  24. "colorlog": "",
  25. "decord": "== 0.6.0; (platform_machine == 'x86_64' or platform_machine == 'AMD64') and sys_platform != 'darwin'",
  26. "faiss-cpu": "",
  27. "fastapi": ">= 0.110",
  28. "filelock": "",
  29. "filetype": ">= 1.2",
  30. "ftfy": "",
  31. "GPUtil": ">= 1.4",
  32. "imagesize": "",
  33. "Jinja2": "",
  34. "joblib": "",
  35. "langchain": "== 0.2.17",
  36. "langchain-community": "== 0.2.17",
  37. "langchain-core": "",
  38. "langchain-openai": "== 0.1.25",
  39. "lxml": "",
  40. "matplotlib": "",
  41. "numpy": [
  42. "== 1.24.4; python_version < '3.12'",
  43. "== 1.26.4; python_version >= '3.12'",
  44. ],
  45. "openai": "== 1.63.2",
  46. "opencv-contrib-python": "== 4.10.0.84",
  47. "openpyxl": "",
  48. "packaging": "",
  49. "pandas": "",
  50. "pillow": "",
  51. "premailer": "",
  52. "prettytable": "",
  53. "py-cpuinfo": "",
  54. "pyclipper": "",
  55. "pycocotools": "",
  56. "pydantic": ">= 2",
  57. "PyMuPDF": "",
  58. "PyYAML": "== 6.0.2",
  59. "regex": "",
  60. "requests": "",
  61. "ruamel.yaml": "",
  62. "scikit-image": "",
  63. "scikit-learn": "",
  64. "shapely": "",
  65. "soundfile": "",
  66. "starlette": ">= 0.36",
  67. "tokenizers": "== 0.19.1",
  68. "tqdm": "",
  69. "typing-extensions": "",
  70. "ujson": "",
  71. "uvicorn": ">= 0.16",
  72. "yarl": ">= 1.9",
  73. }
  74. REQUIRED_DEPS = [
  75. "chardet",
  76. "colorlog",
  77. "filelock",
  78. "GPUtil",
  79. "numpy",
  80. "packaging",
  81. # Currently it is not easy to make `pandas` optional
  82. "pandas",
  83. "pillow",
  84. "prettytable",
  85. "py-cpuinfo",
  86. "pydantic",
  87. "PyYAML",
  88. "requests",
  89. "ruamel.yaml",
  90. "typing-extensions",
  91. "ujson",
  92. ]
  93. EXTRAS = {
  94. "base": {
  95. "cv": [
  96. "faiss-cpu",
  97. "matplotlib",
  98. "opencv-contrib-python",
  99. "pycocotools",
  100. # Currently `PyMuPDF` is required by the image batch sampler
  101. "PyMuPDF",
  102. "scikit-image",
  103. ],
  104. "multimodal": [
  105. "ftfy",
  106. "Jinja2",
  107. "opencv-contrib-python",
  108. # For the same reason as in `cv`
  109. "PyMuPDF",
  110. "regex",
  111. ],
  112. "ie": [
  113. "ftfy",
  114. "imagesize",
  115. "langchain",
  116. "langchain-community",
  117. "langchain-core",
  118. "langchain-openai",
  119. "lxml",
  120. "openai",
  121. "opencv-contrib-python",
  122. "openpyxl",
  123. "premailer",
  124. "pyclipper",
  125. "PyMuPDF",
  126. "scikit-learn",
  127. "shapely",
  128. "tokenizers",
  129. ],
  130. "ocr": [
  131. "ftfy",
  132. "imagesize",
  133. "lxml",
  134. "opencv-contrib-python",
  135. "openpyxl",
  136. "premailer",
  137. "pyclipper",
  138. "PyMuPDF",
  139. "scikit-learn",
  140. "shapely",
  141. "tokenizers",
  142. ],
  143. "speech": [
  144. "ftfy",
  145. "Jinja2",
  146. "regex",
  147. "soundfile",
  148. "tqdm",
  149. ],
  150. "ts": [
  151. "chinese-calendar",
  152. "joblib",
  153. "matplotlib",
  154. "scikit-learn",
  155. ],
  156. "video": [
  157. "decord",
  158. "opencv-contrib-python",
  159. ],
  160. },
  161. "plugins": {
  162. "serving": [
  163. "aiohttp",
  164. "bce-python-sdk",
  165. "fastapi",
  166. "filetype",
  167. "starlette",
  168. "uvicorn",
  169. "yarl",
  170. ],
  171. },
  172. }
  173. def _get_dep_specs(deps):
  174. dep_specs = []
  175. for dep in deps:
  176. val = DEP_SPECS[dep]
  177. if not isinstance(val, list):
  178. val = [val]
  179. for v in val:
  180. if not v:
  181. dep_specs.append(dep)
  182. else:
  183. dep_specs.append(dep + " " + v)
  184. return dep_specs
  185. def _sort_dep_specs(dep_specs):
  186. return sorted(dep_specs, key=str.lower)
  187. def readme():
  188. """get readme"""
  189. with open("README.md", "r", encoding="utf-8") as file:
  190. return file.read()
  191. def dependencies():
  192. dep_specs = _get_dep_specs(REQUIRED_DEPS)
  193. return _sort_dep_specs(dep_specs)
  194. def extras():
  195. dic = {}
  196. all_dep_specs = set()
  197. for group_name, group in EXTRAS.items():
  198. group_dep_specs = set()
  199. for extra_name, extra_deps in group.items():
  200. extra_dep_specs = _get_dep_specs(extra_deps)
  201. dic[extra_name] = _sort_dep_specs(extra_dep_specs)
  202. group_dep_specs.update(extra_dep_specs)
  203. dic[group_name] = _sort_dep_specs(group_dep_specs)
  204. all_dep_specs.update(group_dep_specs)
  205. dic["all"] = _sort_dep_specs(all_dep_specs)
  206. return dic
  207. def version():
  208. """get version"""
  209. with open(os.path.join("paddlex", ".version"), "r") as file:
  210. return file.read().rstrip()
  211. def get_data_files(directory: str, filetypes: list = None):
  212. all_files = []
  213. filetypes = filetypes or []
  214. for root, _, files in os.walk(directory):
  215. rel_root = os.path.relpath(root, directory)
  216. for file in files:
  217. filepath = os.path.join(rel_root, file)
  218. filetype = os.path.splitext(file)[1][1:]
  219. if filetype in filetypes:
  220. all_files.append(filepath)
  221. return all_files
  222. def packages_and_package_data():
  223. """get packages and package_data"""
  224. def _recursively_find(pattern, exts=None):
  225. for dir_ in glob.iglob(pattern):
  226. for root, _, files in os.walk(dir_):
  227. for f in files:
  228. if exts is not None:
  229. ext = os.path.splitext(f)[1]
  230. if ext not in exts:
  231. continue
  232. yield os.path.join(root, f)
  233. pkgs = find_packages(exclude=["tests", "*.tests", "*.tests.*", "tests.*"])
  234. pkg_data = []
  235. for p in itertools.chain(
  236. _recursively_find("paddlex/configs/*", exts=[".yml", ".yaml"]),
  237. ):
  238. if Path(p).suffix in (".pyc", ".pyo"):
  239. continue
  240. pkg_data.append(Path(p).relative_to("paddlex").as_posix())
  241. pipeline_config = [
  242. Path(p).relative_to("paddlex").as_posix()
  243. for p in glob.glob("paddlex/pipelines/*.yaml")
  244. ]
  245. pkg_data.append("inference/pipelines/ppchatocrv3/ch_prompt.yaml")
  246. pkg_data.extend(pipeline_config)
  247. pkg_data.append(".version")
  248. pkg_data.append("hpip_links.html")
  249. pkg_data.append("inference/utils/hpi_model_info_collection.json")
  250. ops_file_dir = "paddlex/ops"
  251. ops_file_types = ["h", "hpp", "cpp", "cc", "cu"]
  252. return pkgs, {
  253. "paddlex.ops": get_data_files(ops_file_dir, ops_file_types),
  254. "paddlex": pkg_data,
  255. }
  256. if __name__ == "__main__":
  257. pkgs, pkg_data = packages_and_package_data()
  258. s = setup(
  259. name="paddlex",
  260. version=version(),
  261. description=("Low-code development tool based on PaddlePaddle."),
  262. long_description=readme(),
  263. long_description_content_type="text/markdown",
  264. author="PaddlePaddle Authors",
  265. author_email="",
  266. install_requires=dependencies(),
  267. extras_require=extras(),
  268. packages=pkgs,
  269. package_data=pkg_data,
  270. entry_points={
  271. "console_scripts": [
  272. "paddlex = paddlex.__main__:console_entry",
  273. ],
  274. },
  275. # PyPI package information
  276. classifiers=[
  277. "Development Status :: 4 - Beta",
  278. "Intended Audience :: Developers",
  279. "Intended Audience :: Education",
  280. "Intended Audience :: Science/Research",
  281. "License :: OSI Approved :: Apache Software License",
  282. "Programming Language :: Python :: 3.8",
  283. "Programming Language :: Python :: 3.9",
  284. "Programming Language :: Python :: 3.10",
  285. "Programming Language :: Python :: 3.11",
  286. "Programming Language :: Python :: 3.12",
  287. "Topic :: Scientific/Engineering",
  288. "Topic :: Scientific/Engineering :: Mathematics",
  289. "Topic :: Scientific/Engineering :: Artificial Intelligence",
  290. "Topic :: Software Development",
  291. "Topic :: Software Development :: Libraries",
  292. "Topic :: Software Development :: Libraries :: Python Modules",
  293. ],
  294. license="Apache 2.0",
  295. keywords=["paddlepaddle"],
  296. )