nwb-extensions / ndx-template

A template for creating Neurodata Extensions for the NWB neurophysiology data standard
https://nwb.org/
Other
5 stars 8 forks source link

[Feature request] Migration to `pyproject.toml` due to future deprecation of `setup.py install` #70

Closed tuanpham96 closed 1 year ago

tuanpham96 commented 1 year ago

When I do pip install ., I see this warning of deprecation of setup.py. While I can use --use-pep517 to silence the warning, since many packages are switching to pyproject.toml anyway, I think it would be nice to start slowly migrating to it.

DEPRECATION: ndx-test is being installed using the legacy 'setup.py install' method, 
because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. 
pip 23.1 will enforce this behaviour change. 
A possible replacement is to enable the '--use-pep517' option.
Discussion can be found at https://github.com/pypa/pip/issues/8559
rly commented 1 year ago

This is a good idea. Thanks @tuanpham96. It should be a relatively easy change. I'll give it a try this week. We will have to do this in all of the NWB python packages too.

For reference, pip 23.1 is targeted for release in April 2023.

tuanpham96 commented 1 year ago

Great, thank you!

I tried somewhat on an extension I'm developing. While most fields are straightforward, the _copy_spec_files was a bit tricky. I had to customize setuptools.build_meta a bit.

#./pyproject.toml 
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "backend"
backend-path = ["_custom_build"]

And this is the content of backend.py inside a _custom_build folder.

# ./_custom_build/backend.py
import os
from setuptools import build_meta as _orig
from shutil import copy2

prepare_metadata_for_build_wheel = _orig.prepare_metadata_for_build_wheel
build_wheel = _orig.build_wheel
build_sdist = _orig.build_sdist
get_requires_for_build_sdist = _orig.get_requires_for_build_sdist

def _copy_spec_files(project_dir):
    # copy from original `setup.py`

def get_requires_for_build_wheel(self, config_settings=None):
    # hijacking this function to copy necessary spec files
    # unclear of potential side effects
    _copy_spec_files(os.path.join(os.path.dirname(__file__), '..'))
    return _orig.get_requires_for_build_wheel(config_settings)

It works but may not be optimized? Do you know whether pyproject.toml has a field for pre-install/pre-build custom script?