pip Interface eric7

Sun, 04 Sep 2022 16:11:32 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 04 Sep 2022 16:11:32 +0200
branch
eric7
changeset 9310
8ab45a4a6d96
parent 9309
60ee3f038f52
child 9311
8e588f403fd9

pip Interface
- changed the pip licenses dialog to show the count of each individual license

docs/changelog file | annotate | diff | comparison | revisions
src/eric7/PipInterface/Pip.py file | annotate | diff | comparison | revisions
src/eric7/PipInterface/piplicenses.py file | annotate | diff | comparison | revisions
--- a/docs/changelog	Sat Sep 03 17:16:33 2022 +0200
+++ b/docs/changelog	Sun Sep 04 16:11:32 2022 +0200
@@ -2,6 +2,8 @@
 ----------
 Version 22.10:
 - bug fixes
+- pip Interface
+  -- changed the pip licenses dialog to show the count of each individual license
 
 Version 22.9:
 - bug fixes
--- a/src/eric7/PipInterface/Pip.py	Sat Sep 03 17:16:33 2022 +0200
+++ b/src/eric7/PipInterface/Pip.py	Sun Sep 04 16:11:32 2022 +0200
@@ -1058,7 +1058,7 @@
                 if usersite:
                     args.append("--user-only")
                 if summary:
-                    args.append("--summary")
+                    args.append("--summary-by-license")
 
                 proc = QProcess()
                 proc.start(interpreter, args)
--- a/src/eric7/PipInterface/piplicenses.py	Sat Sep 03 17:16:33 2022 +0200
+++ b/src/eric7/PipInterface/piplicenses.py	Sun Sep 04 16:11:32 2022 +0200
@@ -32,6 +32,16 @@
 #
 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de>
 #
+# Modifications:
+#   - removed dependency to prettytable
+#   - 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
+#
 
 import argparse
 import codecs
@@ -313,6 +323,23 @@
     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 find_license_from_classifier(message):
     licenses = []
     for k, v in message.items():
@@ -375,6 +402,8 @@
 
     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)
     
@@ -423,6 +452,7 @@
     from_: "FromArg"
     order: "OrderArg"
     summary: bool
+    summary_by_license: bool
     local_only: bool
     user_only:bool
     output_file: str
@@ -558,6 +588,11 @@
         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')

eric ide

mercurial