setup.py 8.9 KB

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