Repository: cai4cai/torchsparsegradutils (language: python)

Issue:
Structure package to allow for running unit tests after `pip install`
If we want unit tests to be in the pip package, we may need to move them in the source folder:
https://stackoverflow.com/a/58621857/17261462

At the moment, the tests end up poluting a `tests` package as they are not explicitly exluded in
https://github.com/cai4cai/torchsparsegradutils/blob/015027c44d85153a69ab4339d2a1d1cd9b946fa5/setup.py#L25
but are also not within the `torchsparsegradutils` folder

If we just want to avoid this polution (and not have the tests after `pip install`), we could use:
```python
packages=setuptools.find_packages(exclude=['tests']),
```



Discussion / hints:

Fix patch:
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..9612e9d
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,1 @@
+recursive-include torchsparsegradutils/tests *.yaml
diff --git a/README.md b/README.md
index 02a48dc..c91f618 100644
--- a/README.md
+++ b/README.md
@@ -24,7 +24,7 @@ Things that are missing may be listed as [issues](https://github.com/cai4cai/tor
 ## Installation
 The provided package can be installed using:
 
-`pip install torchsparsegradutils` (TODO)
+`pip install torchsparsegradutils`
 
 or
 
diff --git a/setup.py b/setup.py
index 51b42ea..695a45a 100644
--- a/setup.py
+++ b/setup.py
@@ -8,15 +8,18 @@ def readme():
 
 setuptools.setup(
     name="torchsparsegradutils",
-    version="0.0.3",
+    version="0.1.0",
     description="A collection of utility functions to work with PyTorch sparse tensors",
     long_description=readme(),
     long_description_content_type="text/markdown",
     classifiers=[
         "Operating System :: OS Independent",
         "License :: OSI Approved :: Apache Software License",
-        "Programming Language :: Python :: 3",
+        "Programming Language :: Python :: 3.8",
+        "Programming Language :: Python :: 3.9",
+        "Programming Language :: Python :: 3.10",
     ],
+    python_requires=">=3.8, <3.11",
     keywords="sparse torch utility",
     url="https://github.com/cai4cai/torchsparsegradutils",
     author="CAI4CAI research group",
@@ -26,8 +29,12 @@ def readme():
     install_requires=[
         "torch>=1.13",
     ],
+    setup_requires=["pytest-runner"],
+    tests_require=["pytest"],
+    test_suite="tests",
     extras_require={
         "extras": ["jax", "cupy"],
     },
     zip_safe=False,
+    include_package_data=True,
 )


Test patch:
diff --git a/tests/__init__.py b/torchsparsegradutils/tests/__init__.py
similarity index 100%
rename from tests/__init__.py
rename to torchsparsegradutils/tests/__init__.py
diff --git a/tests/test_bicgstab.py b/torchsparsegradutils/tests/test_bicgstab.py
similarity index 100%
rename from tests/test_bicgstab.py
rename to torchsparsegradutils/tests/test_bicgstab.py
diff --git a/tests/test_cupy_bindings.py b/torchsparsegradutils/tests/test_cupy_bindings.py
similarity index 100%
rename from tests/test_cupy_bindings.py
rename to torchsparsegradutils/tests/test_cupy_bindings.py
diff --git a/tests/test_cupy_sparse_solve.py b/torchsparsegradutils/tests/test_cupy_sparse_solve.py
similarity index 100%
rename from tests/test_cupy_sparse_solve.py
rename to torchsparsegradutils/tests/test_cupy_sparse_solve.py
diff --git a/tests/test_distributions.py b/torchsparsegradutils/tests/test_distributions.py
similarity index 100%
rename from tests/test_distributions.py
rename to torchsparsegradutils/tests/test_distributions.py
diff --git a/tests/test_encoders.py b/torchsparsegradutils/tests/test_encoders.py
similarity index 97%
rename from tests/test_encoders.py
rename to torchsparsegradutils/tests/test_encoders.py
index 082e42c..7344f3f 100644
--- a/tests/test_encoders.py
+++ b/torchsparsegradutils/tests/test_encoders.py
@@ -3,6 +3,7 @@
 import json
 import yaml
 import os
+from pathlib import Path
 from ast import literal_eval
 
 from functools import reduce
@@ -152,7 +153,13 @@ def test_trim(tensor_nd, offsets, expected_output_slice):
 
 # Test neighbourgood coordinate generation:
 
-with open("tests/test_params/xyz_coords.yaml") as f:  # load test cases from file
+# Get the absolute path to the directory of the current module:
+current_dir = Path(os.path.abspath(os.path.dirname(__file__)))
+
+# Construct the path to the yaml file:
+yaml_file = current_dir / "test_params" / "xyz_coords.yaml"
+
+with open(yaml_file) as f:  # load test cases from file
     coord_test_cases = yaml.safe_load(f)
 
 params = [tuple(tc.values())[1:] for tc in coord_test_cases]  # Skip the first value, which is 'id'
@@ -172,7 +179,9 @@ def test_gen_coords(radius, expected_coords):
 
 # Test neighbourgood offset generation:
 
-with open("tests/test_params/czyx_shifts.yaml") as f:  # load test cases from file
+yaml_file = current_dir / "test_params" / "czyx_shifts.yaml"
+
+with open(yaml_file) as f:  # load test cases from file
     shift_test_cases = yaml.safe_load(f)
 
 params = [tuple(tc.values())[1:] for tc in shift_test_cases]  # Skip the first value, which is 'id'
@@ -252,7 +261,9 @@ def test_pairwise_coo_indices_unique(radius, volume_shape, diag, upper, channel_
 
 # Test the indices generated are as expected for a simple (3, 2, 2, 2) volume:
 
-with open("tests/test_params/pairwise_coo_indices.yaml") as f:  # load test cases from file to avoid a massive mess
+yaml_file = current_dir / "test_params" / "pairwise_coo_indices.yaml"
+
+with open(yaml_file) as f:  # load test cases from file to avoid a massive mess
     data = yaml.safe_load(f)
 
 test_cases = data["test_cases"]
diff --git a/tests/test_jax_bindings.py b/torchsparsegradutils/tests/test_jax_bindings.py
similarity index 100%
rename from tests/test_jax_bindings.py
rename to torchsparsegradutils/tests/test_jax_bindings.py
diff --git a/tests/test_jax_sparse_solve.py b/torchsparsegradutils/tests/test_jax_sparse_solve.py
similarity index 100%
rename from tests/test_jax_sparse_solve.py
rename to torchsparsegradutils/tests/test_jax_sparse_solve.py
diff --git a/tests/test_linear_cg.py b/torchsparsegradutils/tests/test_linear_cg.py
similarity index 100%
rename from tests/test_linear_cg.py
rename to torchsparsegradutils/tests/test_linear_cg.py
diff --git a/tests/test_lsmr.py b/torchsparsegradutils/tests/test_lsmr.py
similarity index 100%
rename from tests/test_lsmr.py
rename to torchsparsegradutils/tests/test_lsmr.py
diff --git a/tests/test_minres.py b/torchsparsegradutils/tests/test_minres.py
similarity index 100%
rename from tests/test_minres.py
rename to torchsparsegradutils/tests/test_minres.py
diff --git a/tests/test_params/czyx_shifts.yaml b/torchsparsegradutils/tests/test_params/czyx_shifts.yaml
similarity index 100%
rename from tests/test_params/czyx_shifts.yaml
rename to torchsparsegradutils/tests/test_params/czyx_shifts.yaml
diff --git a/tests/test_params/pairwise_coo_indices.yaml b/torchsparsegradutils/tests/test_params/pairwise_coo_indices.yaml
similarity index 100%
rename from tests/test_params/pairwise_coo_indices.yaml
rename to torchsparsegradutils/tests/test_params/pairwise_coo_indices.yaml
diff --git a/tests/test_params/xyz_coords.yaml b/torchsparsegradutils/tests/test_params/xyz_coords.yaml
similarity index 100%
rename from tests/test_params/xyz_coords.yaml
rename to torchsparsegradutils/tests/test_params/xyz_coords.yaml
diff --git a/tests/test_random.py b/torchsparsegradutils/tests/test_random.py
similarity index 100%
rename from tests/test_random.py
rename to torchsparsegradutils/tests/test_random.py
diff --git a/tests/test_sparse_lstsq.py b/torchsparsegradutils/tests/test_sparse_lstsq.py
similarity index 100%
rename from tests/test_sparse_lstsq.py
rename to torchsparsegradutils/tests/test_sparse_lstsq.py
diff --git a/tests/test_sparse_matmul.py b/torchsparsegradutils/tests/test_sparse_matmul.py
similarity index 100%
rename from tests/test_sparse_matmul.py
rename to torchsparsegradutils/tests/test_sparse_matmul.py
diff --git a/tests/test_sparse_solve.py b/torchsparsegradutils/tests/test_sparse_solve.py
similarity index 100%
rename from tests/test_sparse_solve.py
rename to torchsparsegradutils/tests/test_sparse_solve.py
diff --git a/tests/test_utils.py b/torchsparsegradutils/tests/test_utils.py
similarity index 100%
rename from tests/test_utils.py
rename to torchsparsegradutils/tests/test_utils.py