working-directory: ./bindings/python
run: |
pip install -U pip
- pip install pytest requests setuptools_rust numpy pyarrow datasets
- pip install ${{ matrix.torch_version }} tensorflow numpy
- pip install jax jaxlib flax
- python setup.py develop
+ pip install .[numpy,tensorflow]
+ pip install ${{ matrix.torch_version }}
+
+ - name: Install (jax, flax)
+ if: matrix.os != 'windows-latest'
+ working-directory: ./bindings/python
+ run: |
+ pip install .[jax]
+ shell: bash
- name: Check style
working-directory: ./bindings/python
run: |
- pip install black==22.3 click==8.0.4
+ pip install .[quality]
black --check --line-length 119 --target-version py35 py_src/safetensors tests
- name: Run tests
working-directory: ./bindings/python
run: |
cargo test
+ pip install .[testing]
pytest -sv tests/
+import re
from setuptools import setup
from setuptools_rust import Binding, RustExtension
-with open("py_src/safetensors/__init__.py", "r") as f:
- version = f.readline().split("=")[-1].strip().strip('"')
+# IMPORTANT:
+# 1. all dependencies should be listed here with their version requirements if any
+_deps = [
+ "black==22.3", # after updating to black 2023, also update Python version in pyproject.toml to 3.7
+ "click==8.0.4",
+ "flake8>=3.8.3",
+ "flax",
+ "h5py",
+ "huggingface_hub",
+ "isort>=5.5.4",
+ "jax",
+ "numpy",
+ "setuptools_rust",
+ "pytest",
+ "pytest-benchmark",
+ "tensorflow",
+ "torch",
+]
+
+
+# this is a lookup table with items like:
+#
+# tokenizers: "tokenizers==0.9.4"
+# packaging: "packaging"
+#
+# some of the values are versioned whereas others aren't.
+deps = {b: a for a, b in (re.findall(r"^(([^!=<>~ ]+)(?:[!=<>~ ].*)?$)", x)[0] for x in _deps)}
+
+
+def deps_list(*pkgs):
+ return [deps[pkg] for pkg in pkgs]
-with open("requirements-dev.txt", "r") as f:
- testing = f.read().splitlines()
extras = {}
-extras["testing"] = testing
-extras["dev"] = testing
+extras["torch"] = deps_list("torch")
+extras["numpy"] = deps_list("numpy")
+extras["tensorflow"] = deps_list("tensorflow")
+extras["jax"] = deps_list("jax", "flax")
+extras["quality"] = deps_list("black", "isort", "flake8", "click")
+extras["testing"] = deps_list("setuptools_rust", "huggingface_hub", "pytest", "pytest-benchmark", "h5py") + extras["numpy"]
+extras["all"] = extras["torch"] + extras["numpy"] + extras["tensorflow"] + extras["jax"] + extras["quality"] + extras["testing"]
+extras["dev"] = extras["all"]
+
+with open("py_src/safetensors/__init__.py", "r") as f:
+ version = f.readline().split("=")[-1].strip().strip('"')
setup(
name="safetensors",