diff --git a/.github/workflows/array-api-tests.yml b/.github/workflows/array-api-tests.yml index 67ae76f5..36533342 100644 --- a/.github/workflows/array-api-tests.yml +++ b/.github/workflows/array-api-tests.yml @@ -78,6 +78,9 @@ jobs: python -m pip install -r ${GITHUB_WORKSPACE}/array-api-tests/requirements.txt python -m pip install pytest-xdist + - name: Install array-api-compat + run: python -m pip install ${GITHUB_WORKSPACE}/array-api-compat + - name: Dump pip environment run: pip freeze diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml index 826c5239..a2c518e7 100644 --- a/.github/workflows/publish-package.yml +++ b/.github/workflows/publish-package.yml @@ -41,7 +41,7 @@ jobs: - name: Install python-build and twine run: | - python -m pip install --upgrade pip "setuptools<=67" + python -m pip install --upgrade pip meson-python python -m pip install build twine python -m pip list diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c27283ed..0b87a0a8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -66,3 +66,9 @@ jobs: - name: Run Tests run: pytest -v + + - name: Run vendoring tests + run: | + rm -rf vendor_tests/array_api_compat + cp -r src/array_api_compat vendor_tests/ + pytest -v vendor_tests diff --git a/.gitignore b/.gitignore index 4b61f865..5a8fd789 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +pixi.lock +vendor_tests/array_api_compat + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/docs/dev/releasing.md b/docs/dev/releasing.md index 21d3c36a..d04a3717 100644 --- a/docs/dev/releasing.md +++ b/docs/dev/releasing.md @@ -44,15 +44,14 @@ - [ ] **Update the version.** - You must edit + You must edit the version in: ``` array_api_compat/__init__.py + pyproject.toml + meson.build ``` - and update the version (the version is not computed from the tag because - that would break vendorability). - - [ ] **Update the [changelog](../changelog.md).** Edit diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..3846ddec --- /dev/null +++ b/meson.build @@ -0,0 +1,75 @@ +project( + 'array_api_compat', + version: '1.15.0.dev0', + license: 'MIT', + license_files: ['LICENSE'] +) + +py = import('python').find_installation() + +sources_raw = { + 'array_api_compat': [ + 'src/array_api_compat/__init__.py', + 'src/array_api_compat/_internal.py', + ], + + 'array_api_compat/common': [ + 'src/array_api_compat/common/__init__.py', + 'src/array_api_compat/common/_aliases.py', + 'src/array_api_compat/common/_fft.py', + 'src/array_api_compat/common/_helpers.py', + 'src/array_api_compat/common/_linalg.py', + 'src/array_api_compat/common/_typing.py', + ], + + 'array_api_compat/cupy': [ + 'src/array_api_compat/cupy/__init__.py', + 'src/array_api_compat/cupy/_aliases.py', + 'src/array_api_compat/cupy/_info.py', + 'src/array_api_compat/cupy/_typing.py', + 'src/array_api_compat/cupy/fft.py', + 'src/array_api_compat/cupy/linalg.py', + ], + + 'array_api_compat/dask': [ + 'src/array_api_compat/dask/__init__.py', + ], + + 'array_api_compat/dask/array': [ + 'src/array_api_compat/dask/array/__init__.py', + 'src/array_api_compat/dask/array/_aliases.py', + 'src/array_api_compat/dask/array/_info.py', + 'src/array_api_compat/dask/array/fft.py', + 'src/array_api_compat/dask/array/linalg.py', + ], + + 'array_api_compat/numpy': [ + 'src/array_api_compat/numpy/__init__.py', + 'src/array_api_compat/numpy/_aliases.py', + 'src/array_api_compat/numpy/_info.py', + 'src/array_api_compat/numpy/_typing.py', + 'src/array_api_compat/numpy/fft.py', + 'src/array_api_compat/numpy/linalg.py', + ], + + 'array_api_compat/torch': [ + 'src/array_api_compat/torch/__init__.py', + 'src/array_api_compat/torch/_aliases.py', + 'src/array_api_compat/torch/_info.py', + 'src/array_api_compat/torch/_typing.py', + 'src/array_api_compat/torch/fft.py', + 'src/array_api_compat/torch/linalg.py', + ], +} + +sources = {} +foreach subdir, paths : sources_raw + sources += { subdir : files(paths) } +endforeach + +foreach subdir, files : sources + py.install_sources(files, subdir: subdir) +endforeach + +subdir('tests') +subdir('vendor_tests') diff --git a/pixi.toml b/pixi.toml new file mode 100644 index 00000000..4c36837c --- /dev/null +++ b/pixi.toml @@ -0,0 +1,65 @@ +[workspace] +channels = ["https://prefix.dev/conda-forge"] +platforms = ["linux-64", "osx-arm64", "win-64"] +preview = ["pixi-build"] +requires-pixi = ">=0.68.1" + +### array-api-compat package definition ### + +[package.build.backend] +name = "pixi-build-python" +version = ">=0.5.1" + +[package.host-dependencies] +meson-python = "*" + +### workspace environments ### + +[environments] +docs = ["docs"] +tests = ["tests"] + +### default feature definition ### + +[dev] +# this pulls in array-api-compat's host dependencies +array-api-compat.path = "." + +[dependencies] +array-api-compat.path = "." + +### non-default feature definitions ### + +[feature.tests.dependencies] +pytest = "*" +array-api-strict = "*" +numpy = "*" + +[feature.tests.tasks.tests] +cmd = "pytest -v" +description = "Run tests" + +[feature.tests.tasks.clean-vendor-compat] +cmd = "rm -rf vendor_tests/array_api_compat" +description = "Delete the existing vendored version of array-api-compat" + +[feature.tests.tasks.copy-vendor-compat] +cmd = "cp -r src/array_api_compat vendor_tests/" +depends-on = ["clean-vendor-compat"] +description = "Vendor a clean copy of array-api-extra" + +[feature.tests.tasks.tests-vendor] +cmd = "pytest -v vendor_tests" +depends-on = ["copy-vendor-compat"] +description = "Run vendoring tests" + +[feature.docs.dependencies] +furo = "*" +linkify-it-py = "*" +myst-parser = "*" +sphinx = "*" +sphinx-copybutton = "*" +sphinx-autobuild = "*" + +[feature.docs.tasks] +docs = { cmd = "make html", cwd = "docs", description = "Build docs" } diff --git a/pyproject.toml b/pyproject.toml index d7339170..e77cabbf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,10 +1,10 @@ [build-system] -requires = ["setuptools", "setuptools-scm"] -build-backend = "setuptools.build_meta" +requires = ["meson-python"] +build-backend = "mesonpy" [project] name = "array-api-compat" -dynamic = ["version"] +version = "1.15.0.dev0" description = "A wrapper around NumPy and other array libraries to make them compatible with the Array API standard" readme = "README.md" requires-python = ">=3.10" @@ -55,12 +55,10 @@ dev = [ homepage = "https://data-apis.org/array-api-compat/" repository = "https://github.com/data-apis/array-api-compat/" -[tool.setuptools.dynamic] -version = {attr = "array_api_compat.__version__"} -[tool.setuptools.packages.find] -include = ["array_api_compat*"] -namespaces = false +[tool.pytest.ini_options] +testpaths = ["tests"] + [tool.ruff.lint] preview = true diff --git a/array_api_compat/__init__.py b/src/array_api_compat/__init__.py similarity index 100% rename from array_api_compat/__init__.py rename to src/array_api_compat/__init__.py diff --git a/array_api_compat/_internal.py b/src/array_api_compat/_internal.py similarity index 100% rename from array_api_compat/_internal.py rename to src/array_api_compat/_internal.py diff --git a/array_api_compat/common/__init__.py b/src/array_api_compat/common/__init__.py similarity index 100% rename from array_api_compat/common/__init__.py rename to src/array_api_compat/common/__init__.py diff --git a/array_api_compat/common/_aliases.py b/src/array_api_compat/common/_aliases.py similarity index 100% rename from array_api_compat/common/_aliases.py rename to src/array_api_compat/common/_aliases.py diff --git a/array_api_compat/common/_fft.py b/src/array_api_compat/common/_fft.py similarity index 100% rename from array_api_compat/common/_fft.py rename to src/array_api_compat/common/_fft.py diff --git a/array_api_compat/common/_helpers.py b/src/array_api_compat/common/_helpers.py similarity index 100% rename from array_api_compat/common/_helpers.py rename to src/array_api_compat/common/_helpers.py diff --git a/array_api_compat/common/_linalg.py b/src/array_api_compat/common/_linalg.py similarity index 100% rename from array_api_compat/common/_linalg.py rename to src/array_api_compat/common/_linalg.py diff --git a/array_api_compat/common/_typing.py b/src/array_api_compat/common/_typing.py similarity index 100% rename from array_api_compat/common/_typing.py rename to src/array_api_compat/common/_typing.py diff --git a/array_api_compat/cupy/__init__.py b/src/array_api_compat/cupy/__init__.py similarity index 100% rename from array_api_compat/cupy/__init__.py rename to src/array_api_compat/cupy/__init__.py diff --git a/array_api_compat/cupy/_aliases.py b/src/array_api_compat/cupy/_aliases.py similarity index 100% rename from array_api_compat/cupy/_aliases.py rename to src/array_api_compat/cupy/_aliases.py diff --git a/array_api_compat/cupy/_info.py b/src/array_api_compat/cupy/_info.py similarity index 100% rename from array_api_compat/cupy/_info.py rename to src/array_api_compat/cupy/_info.py diff --git a/array_api_compat/cupy/_typing.py b/src/array_api_compat/cupy/_typing.py similarity index 100% rename from array_api_compat/cupy/_typing.py rename to src/array_api_compat/cupy/_typing.py diff --git a/array_api_compat/cupy/fft.py b/src/array_api_compat/cupy/fft.py similarity index 100% rename from array_api_compat/cupy/fft.py rename to src/array_api_compat/cupy/fft.py diff --git a/array_api_compat/cupy/linalg.py b/src/array_api_compat/cupy/linalg.py similarity index 100% rename from array_api_compat/cupy/linalg.py rename to src/array_api_compat/cupy/linalg.py diff --git a/array_api_compat/dask/__init__.py b/src/array_api_compat/dask/__init__.py similarity index 100% rename from array_api_compat/dask/__init__.py rename to src/array_api_compat/dask/__init__.py diff --git a/array_api_compat/dask/array/__init__.py b/src/array_api_compat/dask/array/__init__.py similarity index 100% rename from array_api_compat/dask/array/__init__.py rename to src/array_api_compat/dask/array/__init__.py diff --git a/array_api_compat/dask/array/_aliases.py b/src/array_api_compat/dask/array/_aliases.py similarity index 100% rename from array_api_compat/dask/array/_aliases.py rename to src/array_api_compat/dask/array/_aliases.py diff --git a/array_api_compat/dask/array/_info.py b/src/array_api_compat/dask/array/_info.py similarity index 100% rename from array_api_compat/dask/array/_info.py rename to src/array_api_compat/dask/array/_info.py diff --git a/array_api_compat/dask/array/fft.py b/src/array_api_compat/dask/array/fft.py similarity index 100% rename from array_api_compat/dask/array/fft.py rename to src/array_api_compat/dask/array/fft.py diff --git a/array_api_compat/dask/array/linalg.py b/src/array_api_compat/dask/array/linalg.py similarity index 100% rename from array_api_compat/dask/array/linalg.py rename to src/array_api_compat/dask/array/linalg.py diff --git a/array_api_compat/numpy/__init__.py b/src/array_api_compat/numpy/__init__.py similarity index 100% rename from array_api_compat/numpy/__init__.py rename to src/array_api_compat/numpy/__init__.py diff --git a/array_api_compat/numpy/_aliases.py b/src/array_api_compat/numpy/_aliases.py similarity index 100% rename from array_api_compat/numpy/_aliases.py rename to src/array_api_compat/numpy/_aliases.py diff --git a/array_api_compat/numpy/_info.py b/src/array_api_compat/numpy/_info.py similarity index 100% rename from array_api_compat/numpy/_info.py rename to src/array_api_compat/numpy/_info.py diff --git a/array_api_compat/numpy/_typing.py b/src/array_api_compat/numpy/_typing.py similarity index 100% rename from array_api_compat/numpy/_typing.py rename to src/array_api_compat/numpy/_typing.py diff --git a/array_api_compat/numpy/fft.py b/src/array_api_compat/numpy/fft.py similarity index 100% rename from array_api_compat/numpy/fft.py rename to src/array_api_compat/numpy/fft.py diff --git a/array_api_compat/numpy/linalg.py b/src/array_api_compat/numpy/linalg.py similarity index 100% rename from array_api_compat/numpy/linalg.py rename to src/array_api_compat/numpy/linalg.py diff --git a/array_api_compat/py.typed b/src/array_api_compat/py.typed similarity index 100% rename from array_api_compat/py.typed rename to src/array_api_compat/py.typed diff --git a/array_api_compat/torch/__init__.py b/src/array_api_compat/torch/__init__.py similarity index 100% rename from array_api_compat/torch/__init__.py rename to src/array_api_compat/torch/__init__.py diff --git a/array_api_compat/torch/_aliases.py b/src/array_api_compat/torch/_aliases.py similarity index 100% rename from array_api_compat/torch/_aliases.py rename to src/array_api_compat/torch/_aliases.py diff --git a/array_api_compat/torch/_info.py b/src/array_api_compat/torch/_info.py similarity index 100% rename from array_api_compat/torch/_info.py rename to src/array_api_compat/torch/_info.py diff --git a/array_api_compat/torch/_typing.py b/src/array_api_compat/torch/_typing.py similarity index 100% rename from array_api_compat/torch/_typing.py rename to src/array_api_compat/torch/_typing.py diff --git a/array_api_compat/torch/fft.py b/src/array_api_compat/torch/fft.py similarity index 100% rename from array_api_compat/torch/fft.py rename to src/array_api_compat/torch/fft.py diff --git a/array_api_compat/torch/linalg.py b/src/array_api_compat/torch/linalg.py similarity index 100% rename from array_api_compat/torch/linalg.py rename to src/array_api_compat/torch/linalg.py diff --git a/tests/meson.build b/tests/meson.build new file mode 100644 index 00000000..0a660d9a --- /dev/null +++ b/tests/meson.build @@ -0,0 +1,17 @@ +py.install_sources([ + '__init__.py', + '_helpers.py', + 'test_all.py', + 'test_array_namespace.py', + 'test_common.py', + 'test_copies_or_views.py', + 'test_cupy.py', + 'test_dask.py', + 'test_isdtype.py', + 'test_jax.py', + 'test_no_dependencies.py', + 'test_torch.py', + ], + subdir: 'array_api_compat/tests', + install_tag: 'tests' +) diff --git a/vendor_test/vendored/__init__.py b/vendor_test/vendored/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/vendor_test/vendored/_compat b/vendor_test/vendored/_compat deleted file mode 120000 index ba484f91..00000000 --- a/vendor_test/vendored/_compat +++ /dev/null @@ -1 +0,0 @@ -../../array_api_compat/ \ No newline at end of file diff --git a/vendor_test/__init__.py b/vendor_tests/__init__.py similarity index 100% rename from vendor_test/__init__.py rename to vendor_tests/__init__.py diff --git a/vendor_tests/meson.build b/vendor_tests/meson.build new file mode 100644 index 00000000..72628c25 --- /dev/null +++ b/vendor_tests/meson.build @@ -0,0 +1,11 @@ +py.install_sources([ + '__init__.py', + 'test_vendoring.py', + 'uses_cupy.py', + 'uses_dask.py', + 'uses_numpy.py', + 'uses_torch.py', + ], + subdir: 'array_api_compat/vendor_tests', + install_tag: 'tests' +) diff --git a/tests/test_vendoring.py b/vendor_tests/test_vendoring.py similarity index 69% rename from tests/test_vendoring.py rename to vendor_tests/test_vendoring.py index 8b561551..08f6248e 100644 --- a/tests/test_vendoring.py +++ b/vendor_tests/test_vendoring.py @@ -2,7 +2,7 @@ def test_vendoring_numpy(): - from vendor_test import uses_numpy + from . import uses_numpy uses_numpy._test_numpy() @@ -10,19 +10,20 @@ def test_vendoring_numpy(): def test_vendoring_cupy(): pytest.importorskip("cupy") - from vendor_test import uses_cupy + from . import uses_cupy uses_cupy._test_cupy() def test_vendoring_torch(): pytest.importorskip("torch") - from vendor_test import uses_torch + from . import uses_torch uses_torch._test_torch() def test_vendoring_dask(): pytest.importorskip("dask") - from vendor_test import uses_dask + from . import uses_dask + uses_dask._test_dask() diff --git a/vendor_test/uses_cupy.py b/vendor_tests/uses_cupy.py similarity index 95% rename from vendor_test/uses_cupy.py rename to vendor_tests/uses_cupy.py index e3bbdebe..6be6e6d0 100644 --- a/vendor_test/uses_cupy.py +++ b/vendor_tests/uses_cupy.py @@ -1,6 +1,6 @@ # Basic test that vendoring works -from .vendored._compat import ( +from .array_api_compat import ( cupy as cp_compat, is_cupy_array, is_cupy_namespace, diff --git a/vendor_test/uses_dask.py b/vendor_tests/uses_dask.py similarity index 83% rename from vendor_test/uses_dask.py rename to vendor_tests/uses_dask.py index 44fa8f2f..87735bf3 100644 --- a/vendor_test/uses_dask.py +++ b/vendor_tests/uses_dask.py @@ -1,7 +1,7 @@ # Basic test that vendoring works -from .vendored._compat.dask import array as dask_compat -from .vendored._compat import is_dask_array, is_dask_namespace +from .array_api_compat.dask import array as dask_compat +from .array_api_compat import is_dask_array, is_dask_namespace import dask.array as da import numpy as np diff --git a/vendor_test/uses_numpy.py b/vendor_tests/uses_numpy.py similarity index 95% rename from vendor_test/uses_numpy.py rename to vendor_tests/uses_numpy.py index d7a68248..d7f4c8d5 100644 --- a/vendor_test/uses_numpy.py +++ b/vendor_tests/uses_numpy.py @@ -1,6 +1,6 @@ # Basic test that vendoring works -from .vendored._compat import ( +from .array_api_compat import ( is_numpy_array, is_numpy_namespace, numpy as np_compat, diff --git a/vendor_test/uses_torch.py b/vendor_tests/uses_torch.py similarity index 96% rename from vendor_test/uses_torch.py rename to vendor_tests/uses_torch.py index 747ecd51..9b6c0363 100644 --- a/vendor_test/uses_torch.py +++ b/vendor_tests/uses_torch.py @@ -1,6 +1,6 @@ # Basic test that vendoring works -from .vendored._compat import ( +from .array_api_compat import ( is_torch_array, is_torch_namespace, torch as torch_compat,