Skip to content

Commit 3a659d7

Browse files
committed
Add dependency to array-api-compat
1 parent fd8bc04 commit 3a659d7

File tree

13 files changed

+351
-263
lines changed

13 files changed

+351
-263
lines changed

.github/workflows/test-vendor.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Test vendoring support
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- main
9+
10+
concurrency:
11+
group: ${{ github.workflow }}-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
env:
15+
# Many color libraries just need this to be set to any value, but at least
16+
# one distinguishes color depth, where "3" -> "256-bit color".
17+
FORCE_COLOR: 3
18+
19+
jobs:
20+
pre-commit-and-lint:
21+
name: Format
22+
runs-on: ubuntu-latest
23+
steps:
24+
- name: Checkout array-api-extra
25+
uses: actions/checkout@v4
26+
with:
27+
path: array-api-extra
28+
29+
- name: Checkout array-api-compat
30+
uses: actions/checkout@v4
31+
with:
32+
repository: data-apis/array-api-compat
33+
path: array-api-compat
34+
35+
- name: Vendor array-api-extra into test package
36+
run: |
37+
cp -a array-api-compat/array_api_compat array-api-extra/vendor_tests/
38+
cp -a array-api-extra/src/array_api_extra array-api-extra/vendor_tests/
39+
40+
- name: Install Python
41+
uses: actions/setup-python@v5
42+
with:
43+
python-version: "3.x"
44+
45+
- name: Install Pixi
46+
uses: prefix-dev/[email protected]
47+
with:
48+
pixi-version: v0.39.0
49+
cache: true
50+
51+
- name: Test package
52+
run: pixi run tests-vendor

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,7 @@ Thumbs.db
162162
# pixi environments
163163
.pixi
164164
*.egg-info
165+
166+
# Vendor tests
167+
vendor_tests/array_api_compat/
168+
vendor_tests/array_api_extra/

docs/index.md

+44-3
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,57 @@ If you require stability, it is recommended to pin `array-api-extra` to
5151
a specific version, or vendor the library inside your own.
5252
```
5353

54+
```{note}
55+
This library depends on array-api-compat. We aim for compatibility with
56+
the latest released version of array-api-compat, and your mileage may vary
57+
with older or dev versions.
58+
```
59+
5460
(vendoring)=
5561

5662
## Vendoring
5763

5864
To vendor the library, clone
59-
[the repository](https://github.com/data-apis/array-api-extra) and copy it into
60-
the appropriate place in your library, like:
65+
[the array-api-extra repository](https://github.com/data-apis/array-api-extra)
66+
and copy it into the appropriate place in your library, like:
6167

6268
```
63-
cp -R array-api-extra/ mylib/vendored/array_api_extra
69+
cp -a array-api-extra/src/array_api_extra mylib/vendored/
70+
```
71+
72+
`array-api-extra` depends on `array-api-compat`. You may either add a dependency
73+
in your own project to `array-api-compat` or vendor it too:
74+
75+
1. Clone
76+
[the array-api-compat repository](https://github.com/data-apis/array-api-compat)
77+
and copy it next to your vendored array-api-extra:
78+
79+
```
80+
cp -a array-api-compat/array_api_compat mylib/vendored/
81+
```
82+
83+
2. Create a new hook file which array-api-extra will use instead of the
84+
top-level `array-api-compat` if present:
85+
86+
```
87+
echo 'from mylib.vendored.array_api_compat import *' > mylib/vendored/_array_api_compat_vendor.py
88+
```
89+
90+
This also allows overriding `array-api-compat` functions if you so wish. E.g.
91+
your `mylib/vendored/_array_api_compat_vendor.py` could look like this:
92+
93+
```python
94+
from mylib.vendored.array_api_compat import *
95+
from mylib.vendored.array_api_compat import array_namespace as _array_namespace_orig
96+
97+
98+
def array_namespace(*xs, **kwargs):
99+
import mylib
100+
101+
if any(isinstance(x, mylib.MyArray) for x in xs):
102+
return mylib
103+
else:
104+
return _array_namespace_orig(*xs, **kwargs)
64105
```
65106

66107
(usage)=

pixi.lock

+35-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ classifiers = [
2626
"Typing :: Typed",
2727
]
2828
dynamic = ["version"]
29-
dependencies = []
29+
dependencies = ["array-api-compat"]
3030

3131
[project.optional-dependencies]
3232
tests = [
@@ -96,6 +96,7 @@ numpy = "*"
9696
[tool.pixi.feature.tests.tasks]
9797
tests = { cmd = "pytest" }
9898
tests-ci = { cmd = "pytest -ra --cov --cov-report=xml --cov-report=term --durations=20" }
99+
tests-vendor = { cmd = "pytest vendor_tests" }
99100

100101
[tool.pixi.feature.docs.dependencies]
101102
sphinx = ">=7.0"

0 commit comments

Comments
 (0)