setup.py 9.0 KB

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