968 'replace').strip() |
968 'replace').strip() |
969 with contextlib.suppress(json.JSONDecodeError): |
969 with contextlib.suppress(json.JSONDecodeError): |
970 dependencies = json.loads(output) |
970 dependencies = json.loads(output) |
971 |
971 |
972 return dependencies |
972 return dependencies |
|
973 |
|
974 ####################################################################### |
|
975 ## License handling methods below |
|
976 ####################################################################### |
|
977 |
|
978 def getLicenses(self, envName, summary=False): |
|
979 """ |
|
980 Public method to get the licenses per package for a given environment. |
|
981 |
|
982 @param envName name of the environment to get the licenses for |
|
983 @type str |
|
984 @param summary flag indicating to get a summary listing (defaults to |
|
985 False) |
|
986 @type bool (optional) |
|
987 @return list of dictionaries containing the license and version per |
|
988 package |
|
989 @rtype dict |
|
990 """ |
|
991 licenses = [] |
|
992 |
|
993 if envName: |
|
994 interpreter = self.getVirtualenvInterpreter(envName) |
|
995 if interpreter: |
|
996 from . import piplicenses |
|
997 with open(piplicenses.__file__, "r") as f: |
|
998 content = f.read() |
|
999 args = [ |
|
1000 "-c", |
|
1001 content, |
|
1002 "--format", |
|
1003 "json", |
|
1004 "--from", |
|
1005 "mixed", |
|
1006 "--with-system", |
|
1007 ] |
|
1008 if summary: |
|
1009 args.append("--summary") |
|
1010 |
|
1011 proc = QProcess() |
|
1012 proc.start(interpreter, args) |
|
1013 if proc.waitForStarted(15000) and proc.waitForFinished(30000): |
|
1014 output = str(proc.readAllStandardOutput(), |
|
1015 Preferences.getSystem("IOEncoding"), |
|
1016 'replace').strip() |
|
1017 with contextlib.suppress(json.JSONDecodeError): |
|
1018 licenses = json.loads(output) |
|
1019 |
|
1020 return licenses |
|
1021 |
|
1022 def getLicensesSummary(self, envName): |
|
1023 """ |
|
1024 Public method to get a summary of licenses found in a given |
|
1025 environment. |
|
1026 |
|
1027 @param envName name of the environment to get the licenses summary for |
|
1028 @type str |
|
1029 @return list of dictionaries containing the license and the count of |
|
1030 packages |
|
1031 @rtype dict |
|
1032 """ |
|
1033 return self.getLicenses(envName, summary=True) |