setup.py 9.7 KB

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