eric7/PipInterface/Pip.py

branch
eric7
changeset 9003
6bc210cd5726
parent 9002
31a7decd3393
child 9016
6f079c524e99
equal deleted inserted replaced
9002:31a7decd3393 9003:6bc210cd5726
973 973
974 ####################################################################### 974 #######################################################################
975 ## License handling methods below 975 ## License handling methods below
976 ####################################################################### 976 #######################################################################
977 977
978 def getLicenses(self, envName, summary=False): 978 def getLicenses(self, envName, localPackages=True, usersite=False,
979 summary=False):
979 """ 980 """
980 Public method to get the licenses per package for a given environment. 981 Public method to get the licenses per package for a given environment.
981 982
982 @param envName name of the environment to get the licenses for 983 @param envName name of the environment to get the licenses for
983 @type str 984 @type str
985 @param localPackages flag indicating to get the licenses for local
986 packages only
987 @type bool
988 @param usersite flag indicating to get the licenses for packages
989 installed in user-site directory only
990 @type bool
984 @param summary flag indicating to get a summary listing (defaults to 991 @param summary flag indicating to get a summary listing (defaults to
985 False) 992 False)
986 @type bool (optional) 993 @type bool (optional)
987 @return list of dictionaries containing the license and version per 994 @return list of dictionaries containing the license and version per
988 package 995 package
997 with open(piplicenses.__file__, "r") as f: 1004 with open(piplicenses.__file__, "r") as f:
998 content = f.read() 1005 content = f.read()
999 args = [ 1006 args = [
1000 "-c", 1007 "-c",
1001 content, 1008 content,
1002 "--format",
1003 "json",
1004 "--from", 1009 "--from",
1005 "mixed", 1010 "mixed",
1006 "--with-system", 1011 "--with-system",
1007 ] 1012 ]
1013 if localPackages:
1014 args.append("--local-only")
1015 if usersite:
1016 args.append("--user-only")
1008 if summary: 1017 if summary:
1009 args.append("--summary") 1018 args.append("--summary")
1010 1019
1011 proc = QProcess() 1020 proc = QProcess()
1012 proc.start(interpreter, args) 1021 proc.start(interpreter, args)
1017 with contextlib.suppress(json.JSONDecodeError): 1026 with contextlib.suppress(json.JSONDecodeError):
1018 licenses = json.loads(output) 1027 licenses = json.loads(output)
1019 1028
1020 return licenses 1029 return licenses
1021 1030
1022 def getLicensesSummary(self, envName): 1031 def getLicensesSummary(self, envName, localPackages=True, usersite=False):
1023 """ 1032 """
1024 Public method to get a summary of licenses found in a given 1033 Public method to get a summary of licenses found in a given
1025 environment. 1034 environment.
1026 1035
1027 @param envName name of the environment to get the licenses summary for 1036 @param envName name of the environment to get the licenses summary for
1028 @type str 1037 @type str
1038 @param localPackages flag indicating to get the licenses summary for
1039 local packages only
1040 @type bool
1041 @param usersite flag indicating to get the licenses summary for
1042 packages installed in user-site directory only
1043 @type bool
1029 @return list of dictionaries containing the license and the count of 1044 @return list of dictionaries containing the license and the count of
1030 packages 1045 packages
1031 @rtype dict 1046 @rtype dict
1032 """ 1047 """
1033 return self.getLicenses(envName, summary=True) 1048 return self.getLicenses(envName, localPackages=localPackages,
1049 usersite=usersite, summary=True)

eric ide

mercurial