hpyproject / hpy

HPy: a better API for Python
https://hpyproject.org
MIT License
1.02k stars 52 forks source link

`python setup.py` and the use of `setup.py` as a command line tool are deprecated #473

Closed cclauss closed 5 months ago

cclauss commented 8 months ago

https://packaging.python.org/en/latest/discussions/setup-py-deprecated

However, python setup.py and the use of setup.py as a command line tool are deprecated.

From the test errors in #472 on macOS 12 and later.

Please avoid running setup.py directly. Instead, use pypa/build, pypa/installer or other standards-based tools. See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.

----------------------------- Captured stderr call ----------------------------- /Users/runner/work/hpy/hpy/.tmpdir/popen-gw0/test_hpymod_legacy_cpython_0/venv/lib/python3.10/site-packages/setuptools/_distutils/cmd.py:66: SetuptoolsDeprecationWarning: setup.py install is deprecated. !!

    ********************************************************************************
    Please avoid running ``setup.py`` directly.
    Instead, use pypa/build, pypa/installer or other
    standards-based tools.

    See https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html for details.
    ********************************************************************************

!! self.initialize_options() /Users/runner/work/hpy/hpy/.tmpdir/popen-gw0/test_hpymod_legacy_cpython_0/venv/lib/python3.10/site-packages/setuptools/_distutils/cmd.py:66: EasyInstallDeprecationWarning: easy_install command is deprecated. !!

    ********************************************************************************
    Please avoid running ``setup.py`` and ``easy_install``.
    Instead, use pypa/build, pypa/installer or other
    standards-based tools.

    See https://github.com/pypa/setuptools/issues/917 for details.
mattip commented 8 months ago

The pyroject.toml has a build section, so it should be a matter of pip install build; python -m build .; python -m pip install dist/*.whl, or something along those lines.

mattip commented 8 months ago

Or maybe just python -m pip install . (note the .)

cclauss commented 8 months ago

Agreed... I was worried about how to handle three of the failing tests that do: 'setup.py', f'--hpy-abi={hpy_abi}', 'install'

mattip commented 8 months ago

I think you should be able to use python -m pip install . --config-settings="--hpy-api={hpy_abi}"?

nulano commented 8 months ago

I think you need python -m pip install . --global-option="--hpy-abi={hpy_abi}" but that is also deprecated.

--config-settings does not seem to be passed through to the setup function currently: https://github.com/pypa/setuptools/issues/2491

To avoid this deprecation, Pillow uses a custom build backend wrapping setuptools (https://github.com/python-pillow/Pillow/pull/7171) and I've created https://github.com/python-pillow/Pillow/pull/7658 to fix some issues with that.

hodgestar commented 8 months ago

If there is no solution that isn't deprecated, I'm not sure we can do better than what we do now.

cclauss commented 8 months ago

A problem is that Mac users are quite diligent about updating macOS and #472 demonstrates that installation tests fails on macOS 12, 13, and 14.

hodgestar commented 8 months ago

@cclauss You're quoting documentation about what pip would like to have happen, but I don't see a solution being offered. We can't not pass the information about which ABI to build for.

f-cozzocrea commented 8 months ago

The pyroject.toml has a build section, so it should be a matter of pip install build; python -m build .; python -m pip install dist/*.whl, or something along those lines.

This doesn't work the last time I tried it. Build/setuptools will complain that the project script contains absolute paths (for the helper source files), and refuse to build. See my issue at #435 for related discussion.

mattip commented 8 months ago

Using python -m build worked locally for me

We can't not pass the information about which ABI to build for.

We could use an environment variable

mattip commented 8 months ago

Correction: using python -m build works for the hpy build itself, I did not try using hpy in a test package.

hodgestar commented 8 months ago

An environment variable might help. I tried that with pip awhile ago and the environment variable wasn't passed into the isolated build, but perhaps we can do the build with python -m build and then pip install the generated wheels.

hodgestar commented 8 months ago

If others agree and someone wants to do this, we could try rewrite the tests in test/hpy_devel/test_distutils.py to build with python -m build where python setup.py was used before.

cclauss commented 8 months ago

we could try rewrite the tests...

https://github.com/hpyproject/hpy/pull/472/files#diff-8ca48d70aa8abbf3dec9764a6d23dc3d0879df302dd383d795011b487be2b898 was an attempt to do that but I think I am in over my head.