setup.py 9.8 KB

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