Add "numpy" as a build requirement

Good day, @frank.

The problem

We're currently using sortednp in a package that has the following dependencies:

  • numpy>=1.26.1
  • sortednp==0.4.0

However, we run into (sporadic) issues when attempting to install our package within tox (locally) or within GitLab CI. More specifically, when the following command is called during the package installation to install dependencies:

python -I -m pip install 'numpy>=1.26.1' sortednp==0.4.0

There are times when numpy is still not yet installed when sortednp is being built, causing the following output:

ci_tests: install_package_deps> python -I -m pip install 'numpy>=1.26.1' sortednp==0.4.0
  error: subprocess-exited-with-error
  
  × python setup.py bdist_wheel did not run successfully.
  │ exit code: 1
  ╰─> [76 lines of output]
      running bdist_wheel

(...truncating for brevity...)

      copying src/sortednp/tests/test_kway_merge.py -> build/lib.linux-x86_64-cpython-310/sortednp/tests
      running build_ext
      building 'sortednp._internal' extension
      Traceback (most recent call last):
        File "/tmp/pip-install-0wh8ath1/sortednp_524dfe7cd95248f08d9f51481b8fa146/setup.py", line 27, in __getattribute__
          import numpy
      ModuleNotFoundError: No module named 'numpy'
      
      During handling of the above exception, another exception occurred:

(...truncating for brevity...)

      File "/tmp/pip-install-0wh8ath1/sortednp_524dfe7cd95248f08d9f51481b8fa146/setup.py", line 32, in __getattribute__
          raise Exception("Rerun the previous pip command or install "
      Exception: Rerun the previous pip command or install numpy manually before running this script.

We can still get this to work by using some hack to ensure numpy is installed before attempting to install sortednp, but it's probably easier to specify numpy as a build requirement in sortednp to begin with.

The fix

Originally, a possible fix would be specifying numpy in setup_requires within setup.py:

setup(name='sortednp',
      version='0.4.0',
      packages=["sortednp", "sortednp.tests"],
      package_dir={"": "src"},
      setup_requires=['numpy>=1.14'],  # <-- This line here
      install_requires=['numpy>=1.14'],
      test_suite='sortednp.tests',

But setup_requires has been deprecated in favour of directly listing build dependencies in build-system.requires of a pyproject.toml file.

It should be sufficient to create a simple pyproject.toml file that specifies "numpy" within build-system.requires like so:

# The entire contents of the pyproject.toml
[build-system]
requires = ["setuptools", "numpy>=1.14"]
build-backend = "setuptools.build_meta"

I'm able to install this package locally by doing pip install path/to/locally/cloned/sortednp.

Admittedly, I haven't looked through existing setup.py very deeply, so there may be things that I'm missing.


If it's all right with you, @frank, I can create a Merge Request that incorporates this fix.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information