8000 Don't import pkg_resources unless we need to parse dev version numbers. by anntzer · Pull Request #19102 · scikit-learn/scikit-learn · GitHub
[go: up one dir, main page]

Skip to content

Don't import pkg_resources unless we need to parse dev version numbers. #19102

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

Closed
wants to merge 1 commit into from
Closed
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
17 changes: 12 additions & 5 deletions sklearn/utils/fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,18 @@

from .deprecation import deprecated

try:
from pkg_resources import parse_version # type: ignore
except ImportError:
# setuptools not installed
parse_version = LooseVersion # type: ignore

def parse_version(v):
Copy link
Member

Choose a reason for hiding this comment

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

We can have a small test to make sure that parse_version works versions with dev version numbers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

if not set(v).issubset("0123456789."):
# Avoid importing pkg_resources (which is slow) unless we need to parse
# dev version numbers.
try:
import pkg_resources
except ImportError: # setuptools not installed.
pass
else:
return pkg_resources.parse_version(v)
return LooseVersion(v)


np_version = parse_version(np.__version__)
Expand Down
31C7
0