@@ -80,7 +80,9 @@ def select_most_restrictive(l: str) -> str:
8080 "Mozilla Public License 2.0 (MPL 2.0)" : "MPLv2" ,
8181 "GNU Lesser General Public License v2 (LGPLv2)" : "LGPLv2" ,
8282 "GNU General Public License v2 (GPLv2)" : "GPLv2" ,
83+ "GNU General Public License v2 or later(GPLv2+)" : "GPLv2+" ,
8384 "GNU General Public License v3 (GPLv3)" : "GPLv3" ,
85+ "Apache Software License" : "Apache" ,
8486 }
8587
8688 if is_multi_license (_license ):
@@ -95,34 +97,48 @@ def select_most_restrictive(l: str) -> str:
9597def _packages_from_json (json : str ) -> list [Package ]:
9698 packages = loads (json )
9799 packages_list = []
100+ mapping = {
101+ "GPLv1" : "https://www.gnu.org/licenses/old-licenses/gpl-1.0.html" ,
102+ "GPLv2" : "https://www.gnu.org/licenses/old-licenses/gpl-2.0.html" ,
103+ "LGPLv2" : "https://www.gnu.org/licenses/old-licenses/lgpl-2.0.html" ,
104+ "GPLv3" : "https://www.gnu.org/licenses/gpl-3.0.html" ,
105+ "LGPLv3" : "https://www.gnu.org/licenses/lgpl-3.0.html" ,
106+ "Apache" : "https://www.apache.org/licenses/LICENSE-2.0" ,
107+ "MIT" : "https://mit-license.org/" ,
108+ "BSD" : "https://opensource.org/license/bsd-3-clause" ,
109+ }
98110 for package in packages :
111+ package_license = _normalize (package ["License" ])
99112 packages_list .append (
100113 Package (
101114 name = package ["Name" ],
102- package_link = package ["URL" ],
115+ package_link = "" if package [ "URL" ] == "UNKNOWN" else package ["URL" ],
103116 version = package ["Version" ],
104- license = _normalize (package ["License" ]),
105- license_link = "" ,
117+ license = package_license ,
118+ license_link = (
119+ "" if package_license not in mapping else mapping [package_license ]
120+ ),
106121 )
107122 )
108123 return packages_list
109124
110125
111126def _licenses () -> list [Package ]:
112- file = tempfile .NamedTemporaryFile ()
113- subprocess .run (
114- [
115- "poetry" ,
116- "run" ,
117- "pip-licenses" ,
118- "--format=json" ,
119- "--output-file=" + file .name ,
120- "--with-system" ,
121- "--with-urls" ,
122- ],
123- capture_output = True ,
124- )
125- return _packages_from_json (file .read ().decode ())
127+ with tempfile .NamedTemporaryFile () as file :
128+ subprocess .run (
129+ [
130+ "poetry" ,
131+ "run" ,
132+ "pip-licenses" ,
133+ "--format=json" ,
134+ "--output-file=" + file .name ,
135+ "--with-system" ,
136+ "--with-urls" ,
137+ ],
138+ capture_output = True ,
139+ )
140+ result = _packages_from_json (file .read ().decode ())
141+ return result
126142
127143
128144def _packages_to_markdown (
@@ -154,7 +170,10 @@ def _normalize_package_name(name: str) -> str:
154170 _packages ,
155171 )
156172 for content in consistent :
157- text += f"|[{ content .name } ]({ content .package_link } )"
173+ if content .package_link :
174+ text += f"|[{ content .name } ]({ content .package_link } )"
175+ else :
176+ text += f"|{ content .name } "
158177 text += f"|{ content .version } "
159178 if content .license_link :
160179 text += f"|[{ content .license } ]({ content .license_link } )|\n "
0 commit comments