|
47 | 47 | """
|
48 | 48 |
|
49 | 49 | import os
|
| 50 | +import re |
50 | 51 | import shutil
|
| 52 | +from distutils.core import Command |
51 | 53 | from pathlib import Path
|
52 | 54 |
|
53 | 55 | from setuptools import find_packages, setup
|
|
69 | 71 | shutil.rmtree(stale_egg_info)
|
70 | 72 |
|
71 | 73 |
|
72 |
| -extras = {} |
73 |
| - |
74 |
| -extras["ja"] = ["fugashi>=1.0", "ipadic>=1.0.0,<2.0", "unidic_lite>=1.0.7", "unidic>=1.0.2"] |
75 |
| -extras["sklearn"] = ["scikit-learn"] |
76 |
| - |
77 |
| -# keras2onnx and onnxconverter-common version is specific through a commit until 1.7.0 lands on pypi |
78 |
| -extras["tf"] = [ |
79 |
| - "tensorflow>=2.0", |
| 74 | +# IMPORTANT: |
| 75 | +# 1. all dependencies should be listed here with their version requirements if any |
| 76 | +# 2. once modified, run: `make deps_table_update` to update src/transformers/dependency_versions_table.py |
| 77 | +_deps = [ |
| 78 | + "black>=20.8b1", |
| 79 | + "cookiecutter==1.7.2", |
| 80 | + "dataclasses", |
| 81 | + "datasets", |
| 82 | + "faiss-cpu", |
| 83 | + "fastapi", |
| 84 | + "filelock", |
| 85 | + "flake8>=3.8.3", |
| 86 | + "flax==0.2.2", |
| 87 | + "fugashi>=1.0", |
| 88 | + "ipadic>=1.0.0,<2.0", |
| 89 | + "isort>=5.5.4", |
| 90 | + "jax>=0.2.0", |
| 91 | + "jaxlib==0.1.55", |
| 92 | + "keras2onnx", |
| 93 | + "numpy", |
80 | 94 | "onnxconverter-common",
|
81 |
| - "keras2onnx" |
82 |
| - # "onnxconverter-common @ git+git://github.com/microsoft/onnxconverter-common.git@f64ca15989b6dc95a1f3507ff6e4c395ba12dff5#egg=onnxconverter-common", |
83 |
| - # "keras2onnx @ git+git://github.com/onnx/keras-onnx.git@cbdc75cb950b16db7f0a67be96a278f8d2953b48#egg=keras2onnx", |
84 |
| -] |
85 |
| -extras["tf-cpu"] = [ |
| 95 | + "onnxruntime-tools>=1.4.2", |
| 96 | + "onnxruntime>=1.4.0", |
| 97 | + "packaging", |
| 98 | + "parameterized", |
| 99 | + "protobuf", |
| 100 | + "psutil", |
| 101 | + "pydantic", |
| 102 | + "pytest", |
| 103 | + "pytest-xdist", |
| 104 | + "python>=3.6.0", |
| 105 | + "recommonmark", |
| 106 | + "regex!=2019.12.17", |
| 107 | + "requests", |
| 108 | + "sacremoses", |
| 109 | + "scikit-learn", |
| 110 | + "sentencepiece==0.1.91", |
| 111 | + "sphinx-copybutton", |
| 112 | + "sphinx-markdown-tables", |
| 113 | + "sphinx-rtd-theme==0.4.3", # sphinx-rtd-theme==0.5.0 introduced big changes in the style. |
| 114 | + "sphinx==3.2.1", |
| 115 | + "starlette", |
86 | 116 | "tensorflow-cpu>=2.0",
|
87 |
| - "onnxconverter-common", |
88 |
| - "keras2onnx" |
89 |
| - # "onnxconverter-common @ git+git://github.com/microsoft/onnxconverter-common.git@f64ca15989b6dc95a1f3507ff6e4c395ba12dff5#egg=onnxconverter-common", |
90 |
| - # "keras2onnx @ git+git://github.com/onnx/keras-onnx.git@cbdc75cb950b16db7f0a67be96a278f8d2953b48#egg=keras2onnx", |
| 117 | + "tensorflow>=2.0", |
| 118 | + "timeout-decorator", |
| 119 | + "tokenizers==0.9.4", |
| 120 | + "torch>=1.0", |
| 121 | + "tqdm>=4.27", |
| 122 | + "unidic>=1.0.2", |
| 123 | + "unidic_lite>=1.0.7", |
| 124 | + "uvicorn", |
91 | 125 | ]
|
92 |
| -extras["torch"] = ["torch>=1.0"] |
| 126 | + |
| 127 | + |
| 128 | +# tokenizers: "tokenizers==0.9.4" lookup table |
| 129 | +# support non-versions file too so that they can be checked at run time |
| 130 | +deps = {b: a for a, b in (re.findall(r"^(([^!=<>]+)(?:[!=<>].*)?$)", x)[0] for x in _deps)} |
| 131 | + |
| 132 | + |
| 133 | +def deps_list(*pkgs): |
| 134 | + return [deps[pkg] for pkg in pkgs] |
| 135 | + |
| 136 | + |
| 137 | +class DepsTableUpdateCommand(Command): |
| 138 | + """ |
| 139 | + A custom distutils command that updates the dependency table. |
| 140 | + usage: python setup.py deps_table_update |
| 141 | + """ |
| 142 | + |
| 143 | + description = "build runtime dependency table" |
| 144 | + user_options = [ |
| 145 | + # format: (long option, short option, description). |
| 146 | + ("dep-table-update", None, "updates src/transformers/dependency_versions_table.py"), |
| 147 | + ] |
| 148 | + |
| 149 | + def initialize_options(self): |
| 150 | + pass |
| 151 | + |
| 152 | + def finalize_options(self): |
| 153 | + pass |
| 154 | + |
| 155 | + def run(self): |
| 156 | + entries = "\n".join([f' "{k}": "{v}",' for k, v in deps.items()]) |
| 157 | + content = [ |
| 158 | + "# THIS FILE HAS BEEN AUTOGENERATED. To update:", |
| 159 | + "# 1. modify the `_deps` dict in setup.py", |
| 160 | + "# 2. run `make deps_table_update``", |
| 161 | + "deps = {", |
| 162 | + entries, |
| 163 | + "}", |
| 164 | + "" |
| 165 | + ] |
| 166 | + target = "src/transformers/dependency_versions_table.py" |
| 167 | + print(f"updating {target}") |
| 168 | + with open(target, "w") as f: |
| 169 | + f.write("\n".join(content)) |
| 170 | + |
| 171 | + |
| 172 | +extras = {} |
| 173 | + |
| 174 | +extras["ja"] = deps_list("fugashi", "ipadic", "unidic_lite", "unidic") |
| 175 | +extras["sklearn"] = deps_list("scikit-learn") |
| 176 | + |
| 177 | +extras["tf"] = deps_list("tensorflow", "onnxconverter-common", "keras2onnx") |
| 178 | +extras["tf-cpu"] = deps_list("tensorflow-cpu", "onnxconverter-common", "keras2onnx") |
| 179 | + |
| 180 | +extras["torch"] = deps_list("torch") |
93 | 181 |
|
94 | 182 | if os.name == "nt": # windows
|
95 |
| - extras["retrieval"] = ["datasets"] # faiss is not supported on windows |
96 |
| - extras["flax"] = [] # jax is not supported on windows |
| 183 | + extras["retrieval"] = deps_list("datasets") # faiss is not supported on windows |
| 184 | + extras["flax"] = [] # jax is not supported on windows |
97 | 185 | else:
|
98 |
| - extras["retrieval"] = ["faiss-cpu", "datasets"] |
99 |
| - extras["flax"] = ["jaxlib==0.1.55", "jax>=0.2.0", "flax==0.2.2"] |
100 |
| - |
101 |
| -extras["tokenizers"] = ["tokenizers==0.9.4"] |
102 |
| -extras["onnxruntime"] = ["onnxruntime>=1.4.0", "onnxruntime-tools>=1.4.2"] |
103 |
| -extras["modelcreation"] = ["cookiecutter==1.7.2"] |
| 186 | + extras["retrieval"] = deps_list("faiss-cpu", "datasets") |
| 187 | + extras["flax"] = deps_list("jax", "jaxlib", "flax") |
104 | 188 |
|
105 |
| -extras["serving"] = ["pydantic", "uvicorn", "fastapi", "starlette"] |
| 189 | +extras["tokenizers"] = deps_list("tokenizers") |
| 190 | +extras["onnxruntime"] = deps_list("onnxruntime", "onnxruntime-tools") |
| 191 | +extras["modelcreation"] = deps_list("cookiecutter") |
106 | 192 |
|
107 |
| -extras["sentencepiece"] = ["sentencepiece==0.1.91", "protobuf"] |
108 |
| -extras["retrieval"] = ["faiss-cpu", "datasets"] |
109 |
| -extras["testing"] = ["pytest", "pytest-xdist", "timeout-decorator", "parameterized", "psutil"] + extras["retrieval"] + extras["modelcreation"] |
110 |
| -# sphinx-rtd-theme==0.5.0 introduced big changes in the style. |
111 |
| -extras["docs"] = ["recommonmark", "sphinx==3.2.1", "sphinx-markdown-tables", "sphinx-rtd-theme==0.4.3", "sphinx-copybutton"] |
112 |
| -extras["quality"] = ["black >= 20.8b1", "isort >= 5.5.4", "flake8 >= 3.8.3"] |
| 193 | +extras["serving"] = deps_list("pydantic", "uvicorn", "fastapi", "starlette") |
113 | 194 |
|
| 195 | +extras["sentencepiece"] = deps_list("sentencepiece", "protobuf") |
| 196 | +extras["retrieval"] = deps_list("faiss-cpu", "datasets") |
| 197 | +extras["testing"] = ( |
| 198 | + deps_list("pytest", "pytest-xdist", "timeout-decorator", "parameterized", "psutil") |
| 199 | + + extras["retrieval"] |
| 200 | + + extras["modelcreation"] |
| 201 | +) |
| 202 | +extras["docs"] = deps_list("recommonmark", "sphinx", "sphinx-markdown-tables", "sphinx-rtd-theme", "sphinx-copybutton") |
| 203 | +extras["quality"] = deps_list("black", "isort", "flake8") |
114 | 204 |
|
115 | 205 | extras["all"] = extras["tf"] + extras["torch"] + extras["flax"] + extras["sentencepiece"] + extras["tokenizers"]
|
116 | 206 |
|
117 |
| -extras["dev"] = extras["all"] + extras["testing"] + extras["quality"] + extras["ja"] + extras["docs"] + extras["sklearn"] + extras["modelcreation"] |
| 207 | +extras["dev"] = ( |
| 208 | + extras["all"] |
| 209 | + + extras["testing"] |
| 210 | + + extras["quality"] |
| 211 | + + extras["ja"] |
| 212 | + + extras["docs"] |
| 213 | + + extras["sklearn"] |
| 214 | + + extras["modelcreation"] |
| 215 | +) |
118 | 216 |
|
119 | 217 |
|
| 218 | +# when modifying the following list, make sure to update src/transformers/dependency_versions_check.py |
| 219 | +install_requires = [ |
| 220 | + deps["dataclasses"] + ";python_version<'3.7'", # dataclasses for Python versions that don't have it |
| 221 | + deps["filelock"], # filesystem locks, e.g., to prevent parallel downloads |
| 222 | + deps["numpy"], |
| 223 | + deps["packaging"], # utilities from PyPA to e.g., compare versions |
| 224 | + deps["regex"], # for OpenAI GPT |
| 225 | + deps["requests"], # for downloading models over HTTPS |
| 226 | + deps["sacremoses"], # for XLM |
| 227 | + deps["tokenizers"], |
| 228 | + deps["tqdm"], # progress bars in model download and training scripts |
| 229 | +] |
| 230 | + |
120 | 231 | setup(
|
121 | 232 | name="transformers",
|
122 | 233 | version="4.0.0-rc-1",
|
|
130 | 241 | url="https://github.com/huggingface/transformers",
|
131 | 242 | package_dir={"": "src"},
|
132 | 243 | packages=find_packages("src"),
|
133 |
| - install_requires=[ |
134 |
| - "numpy", |
135 |
| - "tokenizers == 0.9.4", |
136 |
| - # dataclasses for Python versions that don't have it |
137 |
| - "dataclasses;python_version<'3.7'", |
138 |
| - # utilities from PyPA to e.g. compare versions |
139 |
| - "packaging", |
140 |
| - # filesystem locks e.g. to prevent parallel downloads |
141 |
| - "filelock", |
142 |
| - # for downloading models over HTTPS |
143 |
| - "requests", |
144 |
| - # progress bars in model download and training scripts |
145 |
| - "tqdm >= 4.27", |
146 |
| - # for OpenAI GPT |
147 |
| - "regex != 2019.12.17", |
148 |
| - # for XLM |
149 |
| - "sacremoses", |
150 |
| - ], |
151 | 244 | extras_require=extras,
|
152 | 245 | entry_points={"console_scripts": ["transformers-cli=transformers.commands.transformers_cli:main"]},
|
153 | 246 | python_requires=">=3.6.0",
|
| 247 | + install_requires=install_requires, |
154 | 248 | classifiers=[
|
155 | 249 | "Development Status :: 5 - Production/Stable",
|
156 | 250 | "Intended Audience :: Developers",
|
|
163 | 257 | "Programming Language :: Python :: 3.7",
|
164 | 258 | "Topic :: Scientific/Engineering :: Artificial Intelligence",
|
165 | 259 | ],
|
| 260 | + cmdclass={"deps_table_update": DepsTableUpdateCommand}, |
166 | 261 | )
|
0 commit comments