CoolFace
Apppublic

declare-lab/tango2

sourceHugging Faceupdated 2y agoView on Hugging Face
92likes
setup.py280 linesDownload Raw Back to diffusers
1# Copyright 2023 The HuggingFace Team. 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 at6#7#     http://www.apache.org/licenses/LICENSE-2.08#9# Unless required by applicable law or agreed to in writing, software10# 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 and13# limitations under the License.14 15"""16Simple check list from AllenNLP repo: https://github.com/allenai/allennlp/blob/main/setup.py17 18To create the package for pypi.19 201. Run `make pre-release` (or `make pre-patch` for a patch release) then run `make fix-copies` to fix the index of the21   documentation.22 23   If releasing on a special branch, copy the updated README.md on the main branch for your the commit you will make24   for the post-release and run `make fix-copies` on the main branch as well.25 262. Run Tests for Amazon Sagemaker. The documentation is located in `./tests/sagemaker/README.md`, otherwise @philschmid.27 283. Unpin specific versions from setup.py that use a git install.29 304. Checkout the release branch (v<RELEASE>-release, for example v4.19-release), and commit these changes with the31   message: "Release: <RELEASE>" and push.32 335. Wait for the tests on main to be completed and be green (otherwise revert and fix bugs)34 356. Add a tag in git to mark the release: "git tag v<RELEASE> -m 'Adds tag v<RELEASE> for pypi' "36   Push the tag to git: git push --tags origin v<RELEASE>-release37 387. Build both the sources and the wheel. Do not change anything in setup.py between39   creating the wheel and the source distribution (obviously).40 41   For the wheel, run: "python setup.py bdist_wheel" in the top level directory.42   (this will build a wheel for the python version you use to build it).43 44   For the sources, run: "python setup.py sdist"45   You should now have a /dist directory with both .whl and .tar.gz source versions.46 478. Check that everything looks correct by uploading the package to the pypi test server:48 49   twine upload dist/* -r pypitest50   (pypi suggest using twine as other methods upload files via plaintext.)51   You may have to specify the repository url, use the following command then:52   twine upload dist/* -r pypitest --repository-url=https://test.pypi.org/legacy/53 54   Check that you can install it in a virtualenv by running:55   pip install -i https://testpypi.python.org/pypi diffusers56 57   Check you can run the following commands:58   python -c "from diffusers import pipeline; classifier = pipeline('text-classification'); print(classifier('What a nice release'))"59   python -c "from diffusers import *"60 619. Upload the final version to actual pypi:62   twine upload dist/* -r pypi63 6410. Copy the release notes from RELEASE.md to the tag in github once everything is looking hunky-dory.65 6611. Run `make post-release` (or, for a patch release, `make post-patch`). If you were on a branch for the release,67    you need to go back to main before executing this.68"""69 70import os71import re72from distutils.core import Command73 74from setuptools import find_packages, setup75 76 77# IMPORTANT:78# 1. all dependencies should be listed here with their version requirements if any79# 2. once modified, run: `make deps_table_update` to update src/diffusers/dependency_versions_table.py80_deps = [81    "Pillow",  # keep the PIL.Image.Resampling deprecation away82    "accelerate>=0.11.0",83    "compel==0.1.8",84    "black~=23.1",85    "datasets",86    "filelock",87    "flax>=0.4.1",88    "hf-doc-builder>=0.3.0",89    "huggingface-hub>=0.13.2",90    "requests-mock==1.10.0",91    "importlib_metadata",92    "isort>=5.5.4",93    "jax>=0.2.8,!=0.3.2",94    "jaxlib>=0.1.65",95    "Jinja2",96    "k-diffusion>=0.0.12",97    "librosa",98    "note-seq",99    "numpy",100    "parameterized",101    "protobuf>=3.20.3,<4",102    "pytest",103    "pytest-timeout",104    "pytest-xdist",105    "ruff>=0.0.241",106    "safetensors",107    "sentencepiece>=0.1.91,!=0.1.92",108    "scipy",109    "regex!=2019.12.17",110    "requests",111    "tensorboard",112    "torch>=1.4",113    "torchvision",114    "transformers>=4.25.1",115]116 117# this is a lookup table with items like:118#119# tokenizers: "huggingface-hub==0.8.0"120# packaging: "packaging"121#122# some of the values are versioned whereas others aren't.123deps = {b: a for a, b in (re.findall(r"^(([^!=<>~]+)(?:[!=<>~].*)?$)", x)[0] for x in _deps)}124 125# since we save this data in src/diffusers/dependency_versions_table.py it can be easily accessed from126# anywhere. If you need to quickly access the data from this table in a shell, you can do so easily with:127#128# python -c 'import sys; from diffusers.dependency_versions_table import deps; \129# print(" ".join([ deps[x] for x in sys.argv[1:]]))' tokenizers datasets130#131# Just pass the desired package names to that script as it's shown with 2 packages above.132#133# If diffusers is not yet installed and the work is done from the cloned repo remember to add `PYTHONPATH=src` to the script above134#135# You can then feed this for example to `pip`:136#137# pip install -U $(python -c 'import sys; from diffusers.dependency_versions_table import deps; \138# print(" ".join([ deps[x] for x in sys.argv[1:]]))' tokenizers datasets)139#140 141 142def deps_list(*pkgs):143    return [deps[pkg] for pkg in pkgs]144 145 146class DepsTableUpdateCommand(Command):147    """148    A custom distutils command that updates the dependency table.149    usage: python setup.py deps_table_update150    """151 152    description = "build runtime dependency table"153    user_options = [154        # format: (long option, short option, description).155        ("dep-table-update", None, "updates src/diffusers/dependency_versions_table.py"),156    ]157 158    def initialize_options(self):159        pass160 161    def finalize_options(self):162        pass163 164    def run(self):165        entries = "\n".join([f'    "{k}": "{v}",' for k, v in deps.items()])166        content = [167            "# THIS FILE HAS BEEN AUTOGENERATED. To update:",168            "# 1. modify the `_deps` dict in setup.py",169            "# 2. run `make deps_table_update``",170            "deps = {",171            entries,172            "}",173            "",174        ]175        target = "src/diffusers/dependency_versions_table.py"176        print(f"updating {target}")177        with open(target, "w", encoding="utf-8", newline="\n") as f:178            f.write("\n".join(content))179 180 181extras = {}182 183 184extras = {}185extras["quality"] = deps_list("black", "isort", "ruff", "hf-doc-builder")186extras["docs"] = deps_list("hf-doc-builder")187extras["training"] = deps_list("accelerate", "datasets", "protobuf", "tensorboard", "Jinja2")188extras["test"] = deps_list(189    "compel",190    "datasets",191    "Jinja2",192    "k-diffusion",193    "librosa",194    "note-seq",195    "parameterized",196    "pytest",197    "pytest-timeout",198    "pytest-xdist",199    "requests-mock",200    "safetensors",201    "sentencepiece",202    "scipy",203    "torchvision",204    "transformers",205)206extras["torch"] = deps_list("torch", "accelerate")207 208if os.name == "nt":  # windows209    extras["flax"] = []  # jax is not supported on windows210else:211    extras["flax"] = deps_list("jax", "jaxlib", "flax")212 213extras["dev"] = (214    extras["quality"] + extras["test"] + extras["training"] + extras["docs"] + extras["torch"] + extras["flax"]215)216 217install_requires = [218    deps["importlib_metadata"],219    deps["filelock"],220    deps["huggingface-hub"],221    deps["numpy"],222    deps["regex"],223    deps["requests"],224    deps["Pillow"],225]226 227setup(228    name="diffusers",229    version="0.15.0.dev0",  # expected format is one of x.y.z.dev0, or x.y.z.rc1 or x.y.z (no to dashes, yes to dots)230    description="Diffusers",231    long_description=open("README.md", "r", encoding="utf-8").read(),232    long_description_content_type="text/markdown",233    keywords="deep learning",234    license="Apache",235    author="The HuggingFace team",236    author_email="patrick@huggingface.co",237    url="https://github.com/huggingface/diffusers",238    package_dir={"": "src"},239    packages=find_packages("src"),240    include_package_data=True,241    python_requires=">=3.7.0",242    install_requires=install_requires,243    extras_require=extras,244    entry_points={"console_scripts": ["diffusers-cli=diffusers.commands.diffusers_cli:main"]},245    classifiers=[246        "Development Status :: 5 - Production/Stable",247        "Intended Audience :: Developers",248        "Intended Audience :: Education",249        "Intended Audience :: Science/Research",250        "License :: OSI Approved :: Apache Software License",251        "Operating System :: OS Independent",252        "Programming Language :: Python :: 3",253        "Programming Language :: Python :: 3.7",254        "Programming Language :: Python :: 3.8",255        "Programming Language :: Python :: 3.9",256        "Topic :: Scientific/Engineering :: Artificial Intelligence",257    ],258    cmdclass={"deps_table_update": DepsTableUpdateCommand},259)260 261# Release checklist262# 1. Change the version in __init__.py and setup.py.263# 2. Commit these changes with the message: "Release: Release"264# 3. Add a tag in git to mark the release: "git tag RELEASE -m 'Adds tag RELEASE for pypi' "265#    Push the tag to git: git push --tags origin main266# 4. Run the following commands in the top-level directory:267#      python setup.py bdist_wheel268#      python setup.py sdist269# 5. Upload the package to the pypi test server first:270#      twine upload dist/* -r pypitest271#      twine upload dist/* -r pypitest --repository-url=https://test.pypi.org/legacy/272# 6. Check that you can install it in a virtualenv by running:273#      pip install -i https://testpypi.python.org/pypi diffusers274#      diffusers env275#      diffusers test276# 7. Upload the final version to actual pypi:277#      twine upload dist/* -r pypi278# 8. Add release notes to the tag in github once everything is looking hunky-dory.279# 9. Update the version in __init__.py, setup.py to the new version "-dev" and push to master280