src/eric7/CondaInterface/__init__.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
25 """ 25 """
26 Private module function to (re-)initialize the conda interface. 26 Private module function to (re-)initialize the conda interface.
27 """ 27 """
28 global __CondaVersionStr, __CondaVersion, __CondaRootPrefix 28 global __CondaVersionStr, __CondaVersion, __CondaRootPrefix
29 global __CondaUserConfig, __initialized 29 global __CondaUserConfig, __initialized
30 30
31 if not __initialized: 31 if not __initialized:
32 exe = Preferences.getConda("CondaExecutable") 32 exe = Preferences.getConda("CondaExecutable")
33 if not exe: 33 if not exe:
34 exe = "conda" 34 exe = "conda"
35 35
36 proc = QProcess() 36 proc = QProcess()
37 proc.start(exe, ["info", "--json"]) 37 proc.start(exe, ["info", "--json"])
38 if not proc.waitForStarted(msecs=15000): 38 if not proc.waitForStarted(msecs=15000):
39 __CondaVersionStr = QCoreApplication.translate( 39 __CondaVersionStr = QCoreApplication.translate(
40 "CondaInterface", 40 "CondaInterface", "<conda not found or not configured.>"
41 '<conda not found or not configured.>') 41 )
42 else: 42 else:
43 proc.waitForFinished(msecs=15000) 43 proc.waitForFinished(msecs=15000)
44 output = str(proc.readAllStandardOutput(), 44 output = str(
45 Preferences.getSystem("IOEncoding"), 45 proc.readAllStandardOutput(),
46 'replace').strip() 46 Preferences.getSystem("IOEncoding"),
47 "replace",
48 ).strip()
47 try: 49 try:
48 jsonDict = json.loads(output) 50 jsonDict = json.loads(output)
49 except Exception: 51 except Exception:
50 __CondaVersionStr = QCoreApplication.translate( 52 __CondaVersionStr = QCoreApplication.translate(
51 "CondaInterface", 53 "CondaInterface", "<conda returned invalid data.>"
52 '<conda returned invalid data.>') 54 )
53 return 55 return
54 56
55 if "error" in jsonDict: 57 if "error" in jsonDict:
56 __CondaVersionStr = QCoreApplication.translate( 58 __CondaVersionStr = QCoreApplication.translate(
57 "CondaInterface", 59 "CondaInterface", "<conda returned an error: {0}.>"
58 '<conda returned an error: {0}.>').format( 60 ).format(jsonDict["error"])
59 jsonDict["error"])
60 else: 61 else:
61 __CondaVersionStr = jsonDict["conda_version"] 62 __CondaVersionStr = jsonDict["conda_version"]
62 __CondaVersion = tuple( 63 __CondaVersion = tuple(int(i) for i in __CondaVersionStr.split("."))
63 int(i) for i in __CondaVersionStr.split(".")
64 )
65 __CondaRootPrefix = jsonDict["root_prefix"] 64 __CondaRootPrefix = jsonDict["root_prefix"]
66 __CondaUserConfig = jsonDict.get("user_rc_path") 65 __CondaUserConfig = jsonDict.get("user_rc_path")
67 if __CondaUserConfig is None: 66 if __CondaUserConfig is None:
68 __CondaUserConfig = jsonDict.get("rc_path") 67 __CondaUserConfig = jsonDict.get("rc_path")
69 68
70 __initialized = True 69 __initialized = True
71 70
72 71
73 def condaVersion(): 72 def condaVersion():
74 """ 73 """
75 Module function to get the conda version. 74 Module function to get the conda version.
76 75
77 @return tuple containing the conda version 76 @return tuple containing the conda version
78 @rtype tuple of (int, int, int) 77 @rtype tuple of (int, int, int)
79 """ 78 """
80 __initializeCondaInterface() 79 __initializeCondaInterface()
81 return __CondaVersion 80 return __CondaVersion
82 81
83 82
84 def condaVersionStr(): 83 def condaVersionStr():
85 """ 84 """
86 Module function to get the conda version as a string. 85 Module function to get the conda version as a string.
87 86
88 @return conda version as a string 87 @return conda version as a string
89 @rtype str 88 @rtype str
90 """ 89 """
91 __initializeCondaInterface() 90 __initializeCondaInterface()
92 return __CondaVersionStr 91 return __CondaVersionStr
93 92
94 93
95 def rootPrefix(): 94 def rootPrefix():
96 """ 95 """
97 Module function to get the root prefix. 96 Module function to get the root prefix.
98 97
99 @return root prefix 98 @return root prefix
100 @rtype str 99 @rtype str
101 """ 100 """
102 __initializeCondaInterface() 101 __initializeCondaInterface()
103 return __CondaRootPrefix 102 return __CondaRootPrefix
104 103
105 104
106 def userConfiguration(): 105 def userConfiguration():
107 """ 106 """
108 Module function to get the path of the user configuration file. 107 Module function to get the path of the user configuration file.
109 108
110 @return path of the user configuration file 109 @return path of the user configuration file
111 @rtype str 110 @rtype str
112 """ 111 """
113 __initializeCondaInterface() 112 __initializeCondaInterface()
114 return __CondaUserConfig 113 return __CondaUserConfig
115 114
116 115
117 def isCondaAvailable(): 116 def isCondaAvailable():
118 """ 117 """
119 Module function to check the availability of conda. 118 Module function to check the availability of conda.
120 119
121 @return flag indicating conda availability 120 @return flag indicating conda availability
122 @rtype bool 121 @rtype bool
123 """ 122 """
124 __initializeCondaInterface() 123 __initializeCondaInterface()
125 return bool(__CondaVersion) 124 return bool(__CondaVersion)
128 def resetInterface(): 127 def resetInterface():
129 """ 128 """
130 Module function to reset the conda interface. 129 Module function to reset the conda interface.
131 """ 130 """
132 global __initialized 131 global __initialized
133 132
134 __initialized = False 133 __initialized = False

eric ide

mercurial