]> khamidou — GitHub mirrors - safetensors.git/commitdiff
pip install .[dev] (#68)
authorMishig <dmishig@gmail.com>
Wed, 16 Nov 2022 15:35:03 +0000 (16:35 +0100)
committerGitHub <noreply@github.com>
Wed, 16 Nov 2022 15:35:03 +0000 (16:35 +0100)
* Update setup.py

* add click==8.0.4 to setup.py

* gh actions use pip install .[dev]

* Update binding local dev readme

* fix gh action

* fix gh action

* fix gh action ?

* don't install jax flax on windows

* try removing unused deps

.github/workflows/python-bench.yml
.github/workflows/python.yml
bindings/python/README.md
bindings/python/pyproject.toml
bindings/python/requirements-dev.txt [deleted file]
bindings/python/setup.py

index bc511d925617cf78d6e52cd584faa2ffeec7c69d..f7cbe23849d3c9ca9bc7d44ac76875d3b0dbf72e 100644 (file)
@@ -32,10 +32,7 @@ jobs:
         working-directory: ./bindings/python
         run: |
           pip install -U pip
-          pip install pytest pytest-benchmark setuptools_rust
-          pip install torch tensorflow numpy
-          pip install jax jaxlib flax
-          python setup.py develop
+          pip install .[dev]
 
       - name: Run tests
         working-directory: ./bindings/python
index b2c2ba2535786e9085b75ef27c4ed451964c29ec..f7ae26b49a06144f83c45ca5fb28665d17a319e7 100644 (file)
@@ -60,19 +60,25 @@ jobs:
         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/
index 9ffe96e0f7bda79e6a08225ab1eadd676183c3cc..9b8e2bc550bf56caa9b41d215c9c9eb624db11c3 100644 (file)
@@ -46,14 +46,15 @@ loaded = load_file("./model.safetensors")
 ### Developing
 
 ```
-pip install setuptools_rust
-python setup.py develop
+# inside ./safetensors/bindings/python
+pip install .[dev]
 ```
 Should be enough to install this library locally.
 
 ### Testing
 
 ```
-pip install pytest   # We don't require pytest, but it's a common library used across HF.
+# inside ./safetensors/bindings/python
+pip install .[dev]
 pytest -sv tests/
 ```
index 291558c9a3deaa48eb4f7cc16e3379b1dda8c782..554dd83245c11ae6554d94919845590785976d19 100644 (file)
@@ -1,3 +1,7 @@
+[build-system]
+requires = ["setuptools", "wheel", "setuptools-rust"]
+build-backend = "setuptools.build_meta"
+
 [tool.black]
 line-length = 119
 target-version = ['py35']
diff --git a/bindings/python/requirements-dev.txt b/bindings/python/requirements-dev.txt
deleted file mode 100644 (file)
index 3727104..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-black==22.3  # after updating to black 2023, also update Python version in pyproject.toml to 3.7
-isort>=5.5.4
-flake8>=3.8.3
-pytest
-numpy
-setuptools_rust
-huggingface_hub
index 49a95ceadb94473f92348a8b24e8524f7dab4067..d13d4ffa7dd33f3344a73daaea361e412bcd7d7b 100644 (file)
@@ -1,17 +1,54 @@
+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",