--- a/src/eric7/PipInterface/piplicenses.py Sun Mar 05 17:07:49 2023 +0100 +++ b/src/eric7/PipInterface/piplicenses.py Mon Mar 06 09:50:18 2023 +0100 @@ -37,12 +37,7 @@ # - removed some not needed code # - changed 'create_licenses_table' to 'create_licenses_list' # - changed 'create_summary_table' to 'create_summary_list' -# - added 'create_summary_by_license_list' together with the -# '--summary-by-license' switch to count each individual -# license used # - changed 'create_output_string' to return a JSON string -# - added 'get_installed_distributions' to get the distributions -# via pip in order to filter for 'local only' and/or 'user only' # from __future__ import annotations @@ -57,42 +52,16 @@ from pathlib import Path from typing import TYPE_CHECKING, List, Type, cast +# modified for 'eric-ide' for Python < 3.8 +try: + from importlib import metadata as importlib_metadata +except ImportError: + importlib_metadata = None + if TYPE_CHECKING: from typing import Iterator, Optional, Sequence -def get_installed_distributions(): - """ - Function to get the installed packages via pip. - - @return list of installed distributions - @rtype list - """ - try: - from importlib import metadata as importlib_metadata - return importlib_metadata.distributions() - except ImportError: - try: - from pip._internal.metadata import get_environment - except ImportError: - # For backward compatibility with pip version 20.3.4 - from pip._internal.utils import misc - return misc.get_installed_distributions( - local_only=True, - user_only=False - ) - else: - from pip._internal.utils.compat import stdlib_pkgs - dists = get_environment(None).iter_installed_distributions( - local_only=True, - user_only=False, - skip=stdlib_pkgs, - include_editables=True, - editables_only=False, - ) - return [d._dist for d in dists] - - __pkgname__ = "pip-licenses" __version__ = "4.1.0" __author__ = "raimon" @@ -230,7 +199,11 @@ return pkg_info - pkgs = get_installed_distributions() + # modified for 'eric-ide' for Python < 3.8 + if importlib_metadata is None: + return [] + else: + pkgs = importlib_metadata.distributions() ignore_pkgs_as_lower = [pkg.lower() for pkg in args.ignore_packages] pkgs_as_lower = [pkg.lower() for pkg in args.packages] @@ -295,6 +268,7 @@ yield pkg_info +# modified for 'eric-ide' def create_licenses_list( args: "CustomNamespace", output_fields=DEFAULT_OUTPUT_FIELDS): @@ -324,6 +298,7 @@ return licenses +# modified for 'eric-ide' def create_summary_list(args: "CustomNamespace"): counts = Counter( "; ".join( @@ -348,23 +323,6 @@ return licenses -def create_summary_by_license_list(args: "CustomNamespace"): - licenses_list = [] - for pkg in get_packages(args): - licenses_list.extend(select_license_by_source( - args.from_, pkg['license_classifier'], pkg['license'])) - counts = Counter(licenses_list) - - licenses = [] - for license, count in counts.items(): - licenses.append({ - "Count": count, - "License": license, - }) - - return licenses - - def case_insensitive_set_intersect(set_a, set_b): """Same as set.intersection() but case-insensitive""" common_items = set() @@ -446,13 +404,12 @@ return output_fields +# modified for 'eric-ide' def create_output_string(args: "CustomNamespace"): output_fields = get_output_fields(args) if args.summary: licenses = create_summary_list(args) - elif args.summary_by_license: - licenses = create_summary_by_license_list(args) else: licenses = create_licenses_list(args, output_fields) @@ -509,9 +466,6 @@ from_: "FromArg" order: "OrderArg" summary: bool - summary_by_license: bool - local_only: bool - user_only:bool output_file: str ignore_packages: List[str] packages: List[str] @@ -658,11 +612,6 @@ default=False, help='dump summary of each license') common_options.add_argument( - '--summary-by-license', - action='store_true', - default=False, - help='dump summary of each individual license') - common_options.add_argument( '--output-file', action='store', type=str, help='save license list to file') @@ -686,16 +635,6 @@ default=[], help="only include selected packages in output", ) - common_options.add_argument( - '--local-only', - action='store_true', - default=False, - help='include only local packages') - common_options.add_argument( - '--user-only', - action='store_true', - default=False, - help='include only packages of the user site dir') format_options.add_argument( "-s",