-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
license.clj
321 lines (237 loc) · 8.2 KB
/
license.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
;; Copyright © 2020-2022 Vitaly Samigullin
;;
;; This program and the accompanying materials are made available under the
;; terms of the Eclipse Public License 2.0 which is available at
;; http://www.eclipse.org/legal/epl-2.0.
;;
;; This Source Code may also be made available under the following Secondary
;; Licenses when the conditions for such availability set forth in the Eclipse
;; Public License, v. 2.0 are satisfied: GNU General Public License as published by
;; the Free Software Foundation, either version 2 of the License, or (at your
;; option) any later version, with the GNU Classpath Exception which is available
;; at https://www.gnu.org/software/classpath/license.html.
;;
;; SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
(ns pip-license-checker.license
"Licenses constants"
(:gen-class)
(:require
[clojure.string :as str]
[pip-license-checker.data :as d]))
;; Lincense regex
;;
;; When discriminating between permissive and copyleft licenses here,
;; we are mostly concerned with the dynamic *linking*, because this is
;; the most used aspect of the dependency libraries for a Python program.
;; See more details here (be careful though, as not all the details
;; are acurate enough):
;; https://en.wikipedia.org/wiki/Comparison_of_free_and_open-source_software_licences
;;
;; Another useful links to learn about licenses
;;
;; GNU licenses (GPL, LGPL, AGPL)
;; https://www.gnu.org/licenses/
;; https://www.gnu.org/licenses/gpl-3.0.txt
;; https://www.gnu.org/licenses/gpl-faq.html
;; Free Software Movement license list
;; https://www.gnu.org/licenses/license-list.html
;; OSI license list
;; https://opensource.org/licenses
;; European Union Public Licence (EUPL)
;; https://joinup.ec.europa.eu/collection/eupl/eupl-text-eupl-12
;; https://joinup.ec.europa.eu/collection/eupl/matrix-eupl-compatible-open-source-licences#section-3
;; Mozilla Public License (MPL)
;; https://www.mozilla.org/en-US/MPL/
;; https://www.mozilla.org/en-US/MPL/2.0/FAQ/
;; CeCILL
;; https://cecill.info/licences.en.html
;; https://cecill.info/faq.en.html
;; Eclipse Public License
;; https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.txt
;; https://www.eclipse.org/legal/epl-2.0/faq.php
;; ODC-BY, ODBl
;; https://opendatacommons.org/licenses/by/1-0/
;; https://opendatacommons.org/licenses/odbl/1-0/
;; Misc
;; https://opensource.stackexchange.com/
(def regex-ignore-case #"(?i)")
(def regex-list-copyleft-network
"Copyleft licenses that consider access over the network as distribution"
[#"\bAffero"
#"\bAGPL"
#"GNU Affero General Public License"
#"\bOSL"
#"Open Software License"
#"\bRPSL"
#"RealNetworks Public Source License"
#"\bWatcom"
#"Sybase Open Watcom Public License"])
(def regex-list-copyleft-strong
"Copyleft licenses with wide range of activities considered as derivation"
[#"GNU General Public License(?!.*classpath|.*linking|.*exception)"
#"\bGPL(?!.*classpath|.*linking|.*exception)"
#"IBM Public License"
#"\bRPL"
#"Reciprocal Public License"
#"Sleepycat License"])
(def regex-list-copyleft-weak
"Weak or partial copyleft that usually not triggered for static and/or dynamic linking"
[#"GNU Lesser General Public License"
#"GNU Library or Lesser General Public License"
#"\bLGPL"
#"GNU General Public License.*(?:classpath|linking|exception)"
#"\bGPL.*(?:classpath|linking|exception)"
#"\bMPL"
#"Mozilla Public License"
#"\bMotosoto"
#"Nokia Open Source License"
#"\bNPL"
#"Netscape Public License"
#"\bNOSL"
#"Netizen Open Source License"
#"\bODbL"
#"Open Database License"
#"BitTorrent Open Source License"
#"\bSPL"
#"Sun Public License"
#"\bEPL"
#"Eclipse Public License"
;; Linking as producing a derivative work is not confirmed by case law yet,
;; but probably contradicts the EU laws, that's why weak copyleft
;; If proved otherwise, may be moved to a strong copyleft list
;; See https://joinup.ec.europa.eu/collection/eupl/matrix-eupl-compatible-open-source-licences#section-3
#"\bEUPL"
#"European Union Public Licence"
#"Eurosym License"
#"\bCPL"
#"Common Public License"
#"\bCDDL"
#"Common Development and Distribution License"
#"CeCILL-C"
#"CEA CNRS Inria Logiciel Libre License"
#"CeCILL-2.1"
#"\bAPSL"
#"Apple Public Source License"
#"Ms-RL"
#"Microsoft Reciprocal License"
#"\bOFL"
#"SIL Open Font License"])
(def regex-list-copyleft-all
"All copyleft licenses"
(into
[]
(concat
regex-list-copyleft-network
regex-list-copyleft-strong
regex-list-copyleft-weak)))
(def regex-list-permissive
"Permissive licenses"
[#"\bAFL"
#"Academic Free License"
#"\bApache"
#"Apache Software License"
#"\bAAL"
#"Attribution Assurance License"
#"Artistic"
#"BSD"
#"CC0"
#"CC(-?|\s*)BY(-?|\s*)(?!.*SA|.*share|.*ND|.*derivative|.*NC|.*commercial)"
#"CeCILL-B Free Software License Agreement"
#"CeCILL-B"
#"Eiffel Forum License"
#"Historical Permission Notice and Disclaimer"
#"\bHPND"
#"MIT License"
#"\bMIT"
#"MirOS"
#"Intel Open Source License"
#"\bISC\b"
#"\bISCL"
#"ISC License"
#"Ms-PL"
#"Microsoft Public License"
#"\bODC(-?|\s*)BY"
#"Open Data Commons Attribution License"
#"PostgreSQL License"
#"Python Software Foundation License"
#"Python License"
#"Public Domain"
#"\bQPL"
#"Q Public License"
#"Repoze Public License"
#"Unlicense"
#"\bUPL"
#"Universal Permissive License"
#"\bUIUC"
#"University of Illinois"
#"NCSA Open Source License"
#"University of Illinois/NCSA Open Source License"
#"Vovida Software License"
#"W3C"
#"X.Net License"
#"Zope Public License"
#"\bzlib(?!-|\/)\b"
;; Like zlib license above but requires that an acknowledgement be made in the "product documentation"
#"\bzlib(.*acknowledgement|\/libpng)\b"
#"WTFPL"
#"Do What the Fuck You Want To Public License"])
;; Const
(def name-error "Error")
(def type-error "Error")
(def type-copyleft-all "Copyleft")
(def type-copyleft-weak "WeakCopyleft")
(def type-copyleft-strong "StrongCopyleft")
(def type-copyleft-network "NetworkCopyleft")
(def type-permissive "Permissive")
(def type-other "Other")
(def types-copyleft
(sorted-set type-copyleft-network
type-copyleft-strong
type-copyleft-weak))
(def types
(sorted-set type-error
type-copyleft-all
type-copyleft-weak
type-copyleft-strong
type-copyleft-network
type-permissive
type-other))
(def invalid-type
(format "Invalid license type. Use one of: %s"
(str/join ", " types)))
(def license-error (d/->License name-error type-error nil))
;; Functions
(defn get-license-error
"Get license object of error type"
[ex]
(d/->License name-error type-error ex))
(defn is-type-valid?
"Return true if license-type string is valid, false otherwise"
[license-type]
(contains? types license-type))
(defn strings->pattern
"Get regex pattern from sequence of strings"
[patterns]
(re-pattern
(str regex-ignore-case
(apply str (interpose "|" (map #(str "(?:" % ")") patterns))))))
(defn license-with-type
"Get license type by its name"
[name]
(try
(let [regex-copyleft-network (strings->pattern regex-list-copyleft-network)
regex-copyleft-strong (strings->pattern regex-list-copyleft-strong)
regex-copyleft-weak (strings->pattern regex-list-copyleft-weak)
match-copyleft-network (some? (re-find regex-copyleft-network name))
match-copyleft-strong (some? (re-find regex-copyleft-strong name))
match-copyleft-weak (some? (re-find regex-copyleft-weak name))
regex-permissive (strings->pattern regex-list-permissive)
match-permissive (some? (re-find regex-permissive name))]
(cond
match-copyleft-network (d/->License name type-copyleft-network nil)
match-copyleft-strong (d/->License name type-copyleft-strong nil)
match-copyleft-weak (d/->License name type-copyleft-weak nil)
match-permissive (d/->License name type-permissive nil)
:else (d/->License name type-other nil)))
(catch NullPointerException _
license-error)))