Skip to content

MNT Remove setuptools dependency in our test suite #27355

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sklearn/tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@ def test_import_all_consistency():
for modname in submods + ["sklearn"]:
if ".tests." in modname:
continue
# Avoid test suite depending on setuptools
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the act of using pkgutil.pkgutil.walk_packages to go through every submodule which includes _build_utils end up importing setuptools anyways?

XREF: #26992

Copy link
Member Author

@lesteve lesteve Sep 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding is that it will indeed try to import all the submodules (and hence try to import setuptools), but that ImportError is going to be ignored. By default (onerror=None), only ImportError is ignored. When specifying onerror, any kind of Exception is ignored:
https://github.com/python/cpython/blob/1f885df2a580360c5de69cc41191f3c6bfaaeb35/Lib/pkgutil.py#L76-L86

In other words, there is no hard dependency on setuptools by using pkgutil.walk_packages but this may still have side-effects as in #26992 if setuptools can be imported.

if modname == "sklearn._build_utils.pre_build_helpers":
continue
if IS_PYPY and (
"_svmlight_format_io" in modname
or "feature_extraction._hashing_fast" in modname
Expand Down
23 changes: 0 additions & 23 deletions sklearn/tests/test_docstring_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,29 +154,6 @@ def test_docstring_parameters():
raise AssertionError("Docstring Error:\n" + msg)


@ignore_warnings(category=FutureWarning)
def test_tabs():
# Test that there are no tabs in our source files
for importer, modname, ispkg in walk_packages(sklearn.__path__, prefix="sklearn."):
if IS_PYPY and (
"_svmlight_format_io" in modname
or "feature_extraction._hashing_fast" in modname
):
continue

# because we don't import
mod = importlib.import_module(modname)

try:
source = inspect.getsource(mod)
except IOError: # user probably should have run "make clean"
continue
assert "\t" not in source, (
'"%s" has tabs, please remove them ',
"or add it to the ignore list" % modname,
)


def _construct_searchcv_instance(SearchCV):
return SearchCV(LogisticRegression(), {"C": [0.1, 1]})

Expand Down