Skip to content
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

reference using setuptools instead of pip internal #116

Closed
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
28 changes: 2 additions & 26 deletions piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,31 +37,7 @@
from enum import Enum, auto
from functools import partial
from typing import List, Optional, Sequence, Text

try:
from pip._internal.utils.misc import get_installed_distributions
except ImportError: # pragma: no cover
try:
from pip import get_installed_distributions
except ImportError:
def get_installed_distributions():
from pip._internal.metadata import (
get_default_environment, get_environment,
)
from pip._internal.metadata.pkg_resources import (
Distribution as _Dist,
)
from pip._internal.utils.compat import stdlib_pkgs

env = get_default_environment()
dists = env.iter_installed_distributions(
local_only=True,
skip=stdlib_pkgs,
include_editables=True,
editables_only=False,
user_only=False,
)
return [dist._dist for dist in dists]
import pkg_resources
Copy link
Owner

Choose a reason for hiding this comment

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

I understood that it is better not to import functions from pip._internal. However, this ported code seems to have the advantage of working in many user environments.

Will import pkg_resources succeed in all user environments? For example, it seems to exist in pip._vendor.pkg_resources.


from prettytable import PrettyTable

Expand Down Expand Up @@ -231,7 +207,7 @@ def get_pkg_info(pkg):

return pkg_info

pkgs = get_installed_distributions()
pkgs = pkg_resources.working_set
ignore_pkgs_as_lower = [pkg.lower() for pkg in args.ignore_packages]
pkgs_as_lower = [pkg.lower() for pkg in args.packages]

Expand Down