Skip to content

Avoid pkg_resources import at the top-level. #4768

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 1 commit into from
Mar 5, 2019
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
1 change: 1 addition & 0 deletions changelog/4768.trivial.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid pkg_resources import at the top-level.
2 changes: 1 addition & 1 deletion src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import py
import six
from pkg_resources import parse_version
Copy link
Member

@asottile asottile Feb 12, 2019

Choose a reason for hiding this comment

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

I'm -0

  • this won't actually help at all as the plugin system in the critical path imports setuptools / pkg_resources
  • I'd rather keep imports at the top

Copy link
Member

Choose a reason for hiding this comment

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

Are there other alternatives for parsing versions that don't require pkg_resources?

I remember distutils has functionality for that, but @RonnyPfannschmidt was strictly against using it. Wouldn't make sense to use disutils just for this bit of functionality? I understand it should be avoided in general, but we are talking about a small utility function of something which is already in the stdlib, not about plugging into distutils in a big way or something.

I believe another point was that we require pkg_resources anyway because of the plugin system, but given pytest-dev/pluggy#190 it seems doable for us to move away from pkg_resources entirely.

Copy link
Member

Choose a reason for hiding this comment

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

pkg_resources itself uses packaging (vendored)

Copy link
Member

Choose a reason for hiding this comment

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

Interesting... perhaps we can consider adding it as dependency if that would mean we can drop pkg_resources from pytest and pluggy?

from pluggy import HookimplMarker
from pluggy import HookspecMarker
from pluggy import PluginManager
Expand Down Expand Up @@ -815,6 +814,7 @@ def _preparse(self, args, addopts=True):

def _checkversion(self):
import pytest
from pkg_resources import parse_version

minver = self.inicfg.get("minversion", None)
if minver:
Expand Down