Skip to content

[RFC] [python] 'setup.py install' is deprecated #5061

@jameslamb

Description

@jameslamb

Description

Running python setup.py install for the Python package raises the following deprecation warning:

/Users/jlamb/mambaforge/lib/python3.9/site-packages/setuptools/command/install.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(

I found a very detailed write-up explaining this issue: "Why you shouldn't invoke setup.py directly" (October 2021).

Here are some of the main things we need to know:

...as of the last few years all direct invocations of setup.py are effectively deprecated in favor of invocations via purpose-built and/or standards-based CLI tools like pip, build and tox.

As mentioned in this issue, direct setup.py invocations have effectively been unmaintained for several years now. Whenever someone raises an issue with a reproducer that involves invoking setup.py, the maintainers ask for a reproducer that doesn't hit this code path, and if one can't be found the issue is closed. Put another way, direct invocations of setup.py that currently work for you do so essentially by chance — if something breaks, you are on your own.

Reproducible example

I observed this warning building from source on macOS 12.2.1, with Python v3.9.7 and setuptools==59.8.0.

git clone --recursive https://github.com/microsoft/LightGBM.git
cd LightGBM/python-package

This warning is raised with python setup.py install.

python setup.py install

It is also raised with pip.

pip install -v .

You can also see this warning on LightGBM's CI builds that use python setup.py {command}. For example, the most recent Linux regular job running on Azure DevOps (build link).

Screen Shot 2022-03-08 at 10 59 33 PM

References

This warning was added in setuptools=v58.3.0 (October 22, 2021), pypa/setuptools#2824.

That PR mentions https://www.python.org/dev/peps/pep-0517/ as a description of the standard packages should meet to continue to be compliant with the main Python package management tools.

The warning comes from setuptools.command.install.initialize_options(): https://github.com/pypa/setuptools/blob/391bb5d4d09c9eb8d6b2b98968e623455ae0a384/setuptools/command/install.py#L32-L38.

lightgbm currently sub-classes setuptools.command.install to customize the behavior of setup.py install.

class CustomInstall(install):
user_options = install.user_options + LIGHTGBM_OPTIONS
def initialize_options(self) -> None:
install.initialize_options(self)

It also does that to customize setup.py {install_lib, bdist_wheel, sdist}.

cmdclass={
'install': CustomInstall,
'install_lib': CustomInstallLib,
'bdist_wheel': CustomBdistWheel,
'sdist': CustomSdist,
},

Why does this matter?

If nothing is changed, the LightGBM Python package might eventually not be installable with some future versions of Python / setuptools.

What should be done?

I don't have a recommendation yet.

https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html, https://www.python.org/dev/peps/pep-0517/, and the other things they link to are very detailed and I'm not deeply familiar with the details of how setuptools works.

Just opening this up to track discussion about this issue.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions