Sun, 04 Sep 2022 16:11:32 +0200
pip Interface
- changed the pip licenses dialog to show the count of each individual license
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | #!/usr/bin/env python |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | # -*- coding: utf-8 -*- |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
3 | # vim:fenc=utf-8 ff=unix ft=python ts=4 sw=4 sts=4 si et |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | """ |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | pip-licenses |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | MIT License |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | Copyright (c) 2018 raimon |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
10 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | Permission is hereby granted, free of charge, to any person obtaining a copy |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
12 | of this software and associated documentation files (the "Software"), to deal |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
13 | in the Software without restriction, including without limitation the rights |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | copies of the Software, and to permit persons to whom the Software is |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
16 | furnished to do so, subject to the following conditions: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | The above copyright notice and this permission notice shall be included in all |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | copies or substantial portions of the Software. |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
20 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
24 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
25 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
26 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | SOFTWARE. |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
28 | """ |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
29 | |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
30 | # |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
31 | # Modified to be used within the eric-ide project. |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
32 | # |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
33 | # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
34 | # |
9310 | 35 | # Modifications: |
36 | # - removed dependency to prettytable | |
37 | # - removed some not needed code | |
38 | # - changed 'create_licenses_table' to 'create_licenses_list' | |
39 | # - changed 'create_summary_table' to 'create_summary_list' | |
40 | # - added 'create_summary_by_license_list' together with the | |
41 | # '--summary-by-license' switch to count each individual | |
42 | # license used | |
43 | # - changed 'create_output_string' to return a JSON string | |
44 | # | |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
45 | |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | import argparse |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
47 | import codecs |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | import glob |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
49 | import json |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | import os |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
51 | import sys |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
52 | from collections import Counter |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
53 | from email import message_from_string |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
54 | from email.parser import FeedParser |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
55 | from enum import Enum, auto |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | from typing import List, Optional, Sequence, Text |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
57 | |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
58 | |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
59 | def get_installed_distributions(local_only=True, user_only=False): |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
60 | try: |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
61 | from pip._internal.metadata import get_environment |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
62 | except ImportError: |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
63 | # For backward compatibility with pip version 20.3.4 |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
64 | from pip._internal.utils import misc |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
65 | return misc.get_installed_distributions( |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
66 | local_only=local_only, |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
67 | user_only=user_only |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
68 | ) |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
69 | else: |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
70 | from pip._internal.utils.compat import stdlib_pkgs |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
71 | dists = get_environment(None).iter_installed_distributions( |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
72 | local_only=local_only, |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
73 | user_only=user_only, |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
74 | skip=stdlib_pkgs, |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
75 | include_editables=True, |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
76 | editables_only=False, |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
77 | ) |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
78 | return [d._dist for d in dists] |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
79 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
80 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
81 | __pkgname__ = 'pip-licenses' |
9098
fb9351497cea
Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9003
diff
changeset
|
82 | __version__ = '3.5.4' |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
83 | __author__ = 'raimon' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
84 | __license__ = 'MIT' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
85 | __summary__ = ('Dump the software license list of ' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
86 | 'Python packages installed with pip.') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
87 | __url__ = 'https://github.com/raimon49/pip-licenses' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
88 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
89 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
90 | FIELD_NAMES = ( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
91 | 'Name', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
92 | 'Version', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
93 | 'License', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
94 | 'LicenseFile', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
95 | 'LicenseText', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
96 | 'NoticeFile', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
97 | 'NoticeText', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
98 | 'Author', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
99 | 'Description', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
100 | 'URL', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
101 | ) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
102 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
103 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
104 | DEFAULT_OUTPUT_FIELDS = ( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
105 | 'Name', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
106 | 'Version', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
107 | ) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
108 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
109 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
110 | SUMMARY_OUTPUT_FIELDS = ( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
111 | 'Count', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
112 | 'License', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
113 | ) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
114 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
115 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
116 | METADATA_KEYS = ( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
117 | 'home-page', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
118 | 'author', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
119 | 'license', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
120 | 'summary', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
121 | 'license_classifier', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
122 | ) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
123 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
124 | # Mapping of FIELD_NAMES to METADATA_KEYS where they differ by more than case |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
125 | FIELDS_TO_METADATA_KEYS = { |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
126 | 'URL': 'home-page', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
127 | 'Description': 'summary', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
128 | 'License-Metadata': 'license', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
129 | 'License-Classifier': 'license_classifier', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
130 | } |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
131 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
132 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
133 | SYSTEM_PACKAGES = ( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
134 | __pkgname__, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
135 | 'pip', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
136 | 'setuptools', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
137 | 'wheel', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
138 | ) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
139 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
140 | LICENSE_UNKNOWN = 'UNKNOWN' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
141 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
142 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
143 | def get_packages(args: "CustomNamespace"): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
144 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
145 | def get_pkg_included_file(pkg, file_names): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
146 | """ |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
147 | Attempt to find the package's included file on disk and return the |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
148 | tuple (included_file_path, included_file_contents). |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
149 | """ |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
150 | included_file = LICENSE_UNKNOWN |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
151 | included_text = LICENSE_UNKNOWN |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
152 | pkg_dirname = "{}-{}.dist-info".format( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
153 | pkg.project_name.replace("-", "_"), pkg.version) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
154 | patterns = [] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
155 | [patterns.extend(sorted(glob.glob(os.path.join(pkg.location, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
156 | pkg_dirname, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
157 | f)))) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
158 | for f in file_names] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
159 | for test_file in patterns: |
9098
fb9351497cea
Third Party packages
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9003
diff
changeset
|
160 | if os.path.exists(test_file) and not os.path.isdir(test_file): |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
161 | included_file = test_file |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
162 | with open(test_file, encoding='utf-8', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
163 | errors='backslashreplace') as included_file_handle: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
164 | included_text = included_file_handle.read() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
165 | break |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
166 | return (included_file, included_text) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
167 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
168 | def get_pkg_info(pkg): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
169 | (license_file, license_text) = get_pkg_included_file( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
170 | pkg, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
171 | ('LICENSE*', 'LICENCE*', 'COPYING*') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
172 | ) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
173 | (notice_file, notice_text) = get_pkg_included_file( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
174 | pkg, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
175 | ('NOTICE*',) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
176 | ) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
177 | pkg_info = { |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
178 | 'name': pkg.project_name, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
179 | 'version': pkg.version, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
180 | 'namever': str(pkg), |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
181 | 'licensefile': license_file, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
182 | 'licensetext': license_text, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
183 | 'noticefile': notice_file, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
184 | 'noticetext': notice_text, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
185 | } |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
186 | metadata = None |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
187 | if pkg.has_metadata('METADATA'): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
188 | metadata = pkg.get_metadata('METADATA') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
189 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
190 | if pkg.has_metadata('PKG-INFO') and metadata is None: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
191 | metadata = pkg.get_metadata('PKG-INFO') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
192 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
193 | if metadata is None: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
194 | for key in METADATA_KEYS: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
195 | pkg_info[key] = LICENSE_UNKNOWN |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
196 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
197 | return pkg_info |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
198 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
199 | feed_parser = FeedParser() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
200 | feed_parser.feed(metadata) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
201 | parsed_metadata = feed_parser.close() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
202 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
203 | for key in METADATA_KEYS: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
204 | pkg_info[key] = parsed_metadata.get(key, LICENSE_UNKNOWN) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
205 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
206 | if metadata is not None: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
207 | message = message_from_string(metadata) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
208 | pkg_info['license_classifier'] = \ |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
209 | find_license_from_classifier(message) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
210 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
211 | if args.filter_strings: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
212 | for k in pkg_info: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
213 | if isinstance(pkg_info[k], list): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
214 | for i, item in enumerate(pkg_info[k]): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
215 | pkg_info[k][i] = item. \ |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
216 | encode(args.filter_code_page, errors="ignore"). \ |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
217 | decode(args.filter_code_page) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
218 | else: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
219 | pkg_info[k] = pkg_info[k]. \ |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
220 | encode(args.filter_code_page, errors="ignore"). \ |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
221 | decode(args.filter_code_page) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
222 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
223 | return pkg_info |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
224 | |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
225 | pkgs = get_installed_distributions( |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
226 | local_only=args.local_only, |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
227 | user_only=args.user_only, |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
228 | ) |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
229 | ignore_pkgs_as_lower = [pkg.lower() for pkg in args.ignore_packages] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
230 | pkgs_as_lower = [pkg.lower() for pkg in args.packages] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
231 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
232 | fail_on_licenses = set() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
233 | if args.fail_on: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
234 | fail_on_licenses = set(map(str.strip, args.fail_on.split(";"))) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
235 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
236 | allow_only_licenses = set() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
237 | if args.allow_only: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
238 | allow_only_licenses = set(map(str.strip, args.allow_only.split(";"))) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
239 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
240 | for pkg in pkgs: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
241 | pkg_name = pkg.project_name |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
242 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
243 | if pkg_name.lower() in ignore_pkgs_as_lower: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
244 | continue |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
245 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
246 | if pkgs_as_lower and pkg_name.lower() not in pkgs_as_lower: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
247 | continue |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
248 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
249 | if not args.with_system and pkg_name in SYSTEM_PACKAGES: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
250 | continue |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
251 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
252 | pkg_info = get_pkg_info(pkg) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
253 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
254 | license_names = select_license_by_source( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
255 | args.from_, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
256 | pkg_info['license_classifier'], |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
257 | pkg_info['license']) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
258 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
259 | if fail_on_licenses: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
260 | failed_licenses = license_names.intersection(fail_on_licenses) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
261 | if failed_licenses: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
262 | sys.stderr.write( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
263 | "fail-on license {} was found for package " |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
264 | "{}:{}".format( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
265 | '; '.join(sorted(failed_licenses)), |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
266 | pkg_info['name'], |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
267 | pkg_info['version']) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
268 | ) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
269 | sys.exit(1) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
270 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
271 | if allow_only_licenses: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
272 | uncommon_licenses = license_names.difference(allow_only_licenses) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
273 | if len(uncommon_licenses) == len(license_names): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
274 | sys.stderr.write( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
275 | "license {} not in allow-only licenses was found" |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
276 | " for package {}:{}".format( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
277 | '; '.join(sorted(uncommon_licenses)), |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
278 | pkg_info['name'], |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
279 | pkg_info['version']) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
280 | ) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
281 | sys.exit(1) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
282 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
283 | yield pkg_info |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
284 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
285 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
286 | def create_licenses_list( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
287 | args: "CustomNamespace", output_fields=DEFAULT_OUTPUT_FIELDS): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
288 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
289 | licenses = [] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
290 | for pkg in get_packages(args): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
291 | row = {} |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
292 | for field in output_fields: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
293 | if field == 'License': |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
294 | license_set = select_license_by_source( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
295 | args.from_, pkg['license_classifier'], pkg['license']) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
296 | license_str = '; '.join(sorted(license_set)) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
297 | row[field] = license_str |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
298 | elif field == 'License-Classifier': |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
299 | row[field] = ('; '.join(sorted(pkg['license_classifier'])) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
300 | or LICENSE_UNKNOWN) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
301 | elif field.lower() in pkg: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
302 | row[field] = pkg[field.lower()] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
303 | else: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
304 | row[field] = pkg[FIELDS_TO_METADATA_KEYS[field]] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
305 | licenses.append(row) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
306 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
307 | return licenses |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
308 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
309 | |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
310 | def create_summary_list(args: "CustomNamespace"): |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
311 | counts = Counter( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
312 | '; '.join(sorted(select_license_by_source( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
313 | args.from_, pkg['license_classifier'], pkg['license']))) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
314 | for pkg in get_packages(args)) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
315 | |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
316 | licenses = [] |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
317 | for license, count in counts.items(): |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
318 | licenses.append({ |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
319 | "Count": count, |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
320 | "License": license, |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
321 | }) |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
322 | |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
323 | return licenses |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
324 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
325 | |
9310 | 326 | def create_summary_by_license_list(args: "CustomNamespace"): |
327 | licenses_list = [] | |
328 | for pkg in get_packages(args): | |
329 | licenses_list.extend(select_license_by_source( | |
330 | args.from_, pkg['license_classifier'], pkg['license'])) | |
331 | counts = Counter(licenses_list) | |
332 | ||
333 | licenses = [] | |
334 | for license, count in counts.items(): | |
335 | licenses.append({ | |
336 | "Count": count, | |
337 | "License": license, | |
338 | }) | |
339 | ||
340 | return licenses | |
341 | ||
342 | ||
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
343 | def find_license_from_classifier(message): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
344 | licenses = [] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
345 | for k, v in message.items(): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
346 | if k == 'Classifier' and v.startswith('License'): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
347 | license = v.split(' :: ')[-1] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
348 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
349 | # Through the declaration of 'Classifier: License :: OSI Approved' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
350 | if license != 'OSI Approved': |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
351 | licenses.append(license) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
352 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
353 | return licenses |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
354 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
355 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
356 | def select_license_by_source(from_source, license_classifier, license_meta): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
357 | license_classifier_set = set(license_classifier) or {LICENSE_UNKNOWN} |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
358 | if (from_source == FromArg.CLASSIFIER or |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
359 | from_source == FromArg.MIXED and len(license_classifier) > 0): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
360 | return license_classifier_set |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
361 | else: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
362 | return {license_meta} |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
363 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
364 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
365 | def get_output_fields(args: "CustomNamespace"): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
366 | if args.summary: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
367 | return list(SUMMARY_OUTPUT_FIELDS) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
368 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
369 | output_fields = list(DEFAULT_OUTPUT_FIELDS) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
370 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
371 | if args.from_ == FromArg.ALL: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
372 | output_fields.append('License-Metadata') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
373 | output_fields.append('License-Classifier') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
374 | else: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
375 | output_fields.append('License') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
376 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
377 | if args.with_authors: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
378 | output_fields.append('Author') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
379 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
380 | if args.with_urls: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
381 | output_fields.append('URL') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
382 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
383 | if args.with_description: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
384 | output_fields.append('Description') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
385 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
386 | if args.with_license_file: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
387 | if not args.no_license_path: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
388 | output_fields.append('LicenseFile') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
389 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
390 | output_fields.append('LicenseText') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
391 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
392 | if args.with_notice_file: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
393 | output_fields.append('NoticeText') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
394 | if not args.no_license_path: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
395 | output_fields.append('NoticeFile') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
396 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
397 | return output_fields |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
398 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
399 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
400 | def create_output_string(args: "CustomNamespace"): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
401 | output_fields = get_output_fields(args) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
402 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
403 | if args.summary: |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
404 | licenses = create_summary_list(args) |
9310 | 405 | elif args.summary_by_license: |
406 | licenses = create_summary_by_license_list(args) | |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
407 | else: |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
408 | licenses = create_licenses_list(args, output_fields) |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
409 | |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
410 | return json.dumps(licenses) |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
411 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
412 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
413 | class CustomHelpFormatter(argparse.HelpFormatter): # pragma: no cover |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
414 | def __init__( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
415 | self, prog: Text, indent_increment: int = 2, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
416 | max_help_position: int = 24, width: Optional[int] = None |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
417 | ) -> None: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
418 | max_help_position = 30 |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
419 | super().__init__( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
420 | prog, indent_increment=indent_increment, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
421 | max_help_position=max_help_position, width=width) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
422 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
423 | def _format_action(self, action: argparse.Action) -> str: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
424 | flag_indent_argument: bool = False |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
425 | text = self._expand_help(action) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
426 | separator_pos = text[:3].find('|') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
427 | if separator_pos != -1 and 'I' in text[:separator_pos]: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
428 | self._indent() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
429 | flag_indent_argument = True |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
430 | help_str = super()._format_action(action) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
431 | if flag_indent_argument: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
432 | self._dedent() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
433 | return help_str |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
434 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
435 | def _expand_help(self, action: argparse.Action) -> str: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
436 | if isinstance(action.default, Enum): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
437 | default_value = enum_key_to_value(action.default) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
438 | return self._get_help_string(action) % {'default': default_value} |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
439 | return super()._expand_help(action) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
440 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
441 | def _split_lines(self, text: Text, width: int) -> List[str]: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
442 | separator_pos = text[:3].find('|') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
443 | if separator_pos != -1: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
444 | flag_splitlines: bool = 'R' in text[:separator_pos] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
445 | text = text[separator_pos + 1:] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
446 | if flag_splitlines: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
447 | return text.splitlines() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
448 | return super()._split_lines(text, width) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
449 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
450 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
451 | class CustomNamespace(argparse.Namespace): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
452 | from_: "FromArg" |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
453 | order: "OrderArg" |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
454 | summary: bool |
9310 | 455 | summary_by_license: bool |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
456 | local_only: bool |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
457 | user_only:bool |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
458 | output_file: str |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
459 | ignore_packages: List[str] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
460 | packages: List[str] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
461 | with_system: bool |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
462 | with_authors: bool |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
463 | with_urls: bool |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
464 | with_description: bool |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
465 | with_license_file: bool |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
466 | no_license_path: bool |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
467 | with_notice_file: bool |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
468 | filter_strings: bool |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
469 | filter_code_page: str |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
470 | fail_on: Optional[str] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
471 | allow_only: Optional[str] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
472 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
473 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
474 | class CompatibleArgumentParser(argparse.ArgumentParser): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
475 | def parse_args(self, args: Optional[Sequence[Text]] = None, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
476 | namespace: CustomNamespace = None) -> CustomNamespace: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
477 | args = super().parse_args(args, namespace) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
478 | self._verify_args(args) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
479 | return args |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
480 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
481 | def _verify_args(self, args: CustomNamespace): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
482 | if args.with_license_file is False and ( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
483 | args.no_license_path is True or |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
484 | args.with_notice_file is True): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
485 | self.error( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
486 | "'--no-license-path' and '--with-notice-file' require " |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
487 | "the '--with-license-file' option to be set") |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
488 | if args.filter_strings is False and \ |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
489 | args.filter_code_page != 'latin1': |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
490 | self.error( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
491 | "'--filter-code-page' requires the '--filter-strings' " |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
492 | "option to be set") |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
493 | try: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
494 | codecs.lookup(args.filter_code_page) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
495 | except LookupError: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
496 | self.error( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
497 | "invalid code page '%s' given for '--filter-code-page, " |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
498 | "check https://docs.python.org/3/library/codecs.html" |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
499 | "#standard-encodings for valid code pages" |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
500 | % args.filter_code_page) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
501 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
502 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
503 | class NoValueEnum(Enum): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
504 | def __repr__(self): # pragma: no cover |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
505 | return '<%s.%s>' % (self.__class__.__name__, self.name) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
506 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
507 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
508 | class FromArg(NoValueEnum): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
509 | META = M = auto() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
510 | CLASSIFIER = C = auto() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
511 | MIXED = MIX = auto() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
512 | ALL = auto() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
513 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
514 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
515 | class OrderArg(NoValueEnum): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
516 | COUNT = C = auto() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
517 | LICENSE = L = auto() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
518 | NAME = N = auto() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
519 | AUTHOR = A = auto() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
520 | URL = U = auto() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
521 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
522 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
523 | def value_to_enum_key(value: str) -> str: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
524 | return value.replace('-', '_').upper() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
525 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
526 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
527 | def enum_key_to_value(enum_key: Enum) -> str: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
528 | return enum_key.name.replace('_', '-').lower() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
529 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
530 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
531 | def choices_from_enum(enum_cls: NoValueEnum) -> List[str]: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
532 | return [key.replace('_', '-').lower() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
533 | for key in enum_cls.__members__.keys()] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
534 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
535 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
536 | MAP_DEST_TO_ENUM = { |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
537 | 'from_': FromArg, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
538 | 'order': OrderArg, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
539 | } |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
540 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
541 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
542 | class SelectAction(argparse.Action): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
543 | def __call__( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
544 | self, parser: argparse.ArgumentParser, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
545 | namespace: argparse.Namespace, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
546 | values: Text, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
547 | option_string: Optional[Text] = None, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
548 | ) -> None: |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
549 | enum_cls = MAP_DEST_TO_ENUM[self.dest] |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
550 | values = value_to_enum_key(values) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
551 | setattr(namespace, self.dest, getattr(enum_cls, values)) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
552 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
553 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
554 | def create_parser(): |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
555 | parser = CompatibleArgumentParser( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
556 | description=__summary__, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
557 | formatter_class=CustomHelpFormatter) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
558 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
559 | common_options = parser.add_argument_group('Common options') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
560 | format_options = parser.add_argument_group('Format options') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
561 | verify_options = parser.add_argument_group('Verify options') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
562 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
563 | parser.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
564 | '-v', '--version', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
565 | action='version', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
566 | version='%(prog)s ' + __version__) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
567 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
568 | common_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
569 | '--from', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
570 | dest='from_', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
571 | action=SelectAction, type=str, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
572 | default=FromArg.MIXED, metavar='SOURCE', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
573 | choices=choices_from_enum(FromArg), |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
574 | help='R|where to find license information\n' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
575 | '"meta", "classifier, "mixed", "all"\n' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
576 | '(default: %(default)s)') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
577 | common_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
578 | '-o', '--order', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
579 | action=SelectAction, type=str, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
580 | default=OrderArg.NAME, metavar='COL', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
581 | choices=choices_from_enum(OrderArg), |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
582 | help='R|order by column\n' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
583 | '"name", "license", "author", "url"\n' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
584 | '(default: %(default)s)') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
585 | common_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
586 | '--summary', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
587 | action='store_true', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
588 | default=False, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
589 | help='dump summary of each license') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
590 | common_options.add_argument( |
9310 | 591 | '--summary-by-license', |
592 | action='store_true', | |
593 | default=False, | |
594 | help='dump summary of each individual license') | |
595 | common_options.add_argument( | |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
596 | '--output-file', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
597 | action='store', type=str, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
598 | help='save license list to file') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
599 | common_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
600 | '-i', '--ignore-packages', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
601 | action='store', type=str, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
602 | nargs='+', metavar='PKG', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
603 | default=[], |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
604 | help='ignore package name in dumped list') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
605 | common_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
606 | '-p', '--packages', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
607 | action='store', type=str, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
608 | nargs='+', metavar='PKG', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
609 | default=[], |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
610 | help='only include selected packages in output') |
9003
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
611 | common_options.add_argument( |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
612 | '--local-only', |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
613 | action='store_true', |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
614 | default=False, |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
615 | help='include only local packages') |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
616 | common_options.add_argument( |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
617 | '--user-only', |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
618 | action='store_true', |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
619 | default=False, |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
620 | help='include only packages of the user site dir') |
6bc210cd5726
Finished implementing the basic functionality of a license lister for pip installed packages (based on pip-licenses).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9002
diff
changeset
|
621 | |
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
622 | format_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
623 | '-s', '--with-system', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
624 | action='store_true', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
625 | default=False, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
626 | help='dump with system packages') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
627 | format_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
628 | '-a', '--with-authors', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
629 | action='store_true', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
630 | default=False, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
631 | help='dump with package authors') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
632 | format_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
633 | '-u', '--with-urls', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
634 | action='store_true', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
635 | default=False, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
636 | help='dump with package urls') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
637 | format_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
638 | '-d', '--with-description', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
639 | action='store_true', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
640 | default=False, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
641 | help='dump with short package description') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
642 | format_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
643 | '-l', '--with-license-file', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
644 | action='store_true', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
645 | default=False, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
646 | help='dump with location of license file and ' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
647 | 'contents, most useful with JSON output') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
648 | format_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
649 | '--no-license-path', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
650 | action='store_true', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
651 | default=False, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
652 | help='I|when specified together with option -l, ' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
653 | 'suppress location of license file output') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
654 | format_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
655 | '--with-notice-file', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
656 | action='store_true', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
657 | default=False, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
658 | help='I|when specified together with option -l, ' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
659 | 'dump with location of license file and contents') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
660 | format_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
661 | '--filter-strings', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
662 | action="store_true", |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
663 | default=False, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
664 | help='filter input according to code page') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
665 | format_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
666 | '--filter-code-page', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
667 | action="store", type=str, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
668 | default="latin1", |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
669 | metavar="CODE", |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
670 | help='I|specify code page for filtering ' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
671 | '(default: %(default)s)') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
672 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
673 | verify_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
674 | '--fail-on', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
675 | action='store', type=str, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
676 | default=None, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
677 | help='fail (exit with code 1) on the first occurrence ' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
678 | 'of the licenses of the semicolon-separated list') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
679 | verify_options.add_argument( |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
680 | '--allow-only', |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
681 | action='store', type=str, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
682 | default=None, |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
683 | help='fail (exit with code 1) on the first occurrence ' |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
684 | 'of the licenses not in the semicolon-separated list') |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
685 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
686 | return parser |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
687 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
688 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
689 | def main(): # pragma: no cover |
9218 | 690 | os.environ["_PIP_USE_IMPORTLIB_METADATA"] = "False" |
691 | # patched for 3.11+ compatibility | |
692 | ||
9002
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
693 | parser = create_parser() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
694 | args = parser.parse_args() |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
695 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
696 | output_string = create_output_string(args) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
697 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
698 | print(output_string) |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
699 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
700 | |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
701 | if __name__ == '__main__': # pragma: no cover |
31a7decd3393
Started to implement a license lister for pip installed packages based on pip-licenses.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
702 | main() |