CondaInterface/__init__.py

Sun, 03 Feb 2019 16:59:36 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 03 Feb 2019 16:59:36 +0100
branch
conda
changeset 6697
2f5c951bdf14
parent 6681
9c1513b488ef
child 6724
ca89c7d94c94
permissions
-rw-r--r--

Conda interface: added capability to remove conda environments the conda way.

6677
6299d69a218a Continued implementing environment creation with conda.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
6299d69a218a Continued implementing environment creation with conda.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6299d69a218a Continued implementing environment creation with conda.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2019 Detlev Offenbach <detlev@die-offenbachs.de>
6299d69a218a Continued implementing environment creation with conda.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
6299d69a218a Continued implementing environment creation with conda.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
6299d69a218a Continued implementing environment creation with conda.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
6299d69a218a Continued implementing environment creation with conda.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Package implementing the various conda related modules.
6299d69a218a Continued implementing environment creation with conda.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
6681
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
9
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
10 from __future__ import unicode_literals
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
11 try:
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
12 str = unicode
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
13 except NameError:
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
14 pass
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
15
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
16 import json
6681
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
17
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
18 from PyQt5.QtCore import QCoreApplication, QProcess
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
19
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
20 import Preferences
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
21
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
22 __CondaVersion = tuple()
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
23 __CondaVersionStr = ""
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
24 __CondaRootPrefix = ""
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
25
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
26 __initialized = False
6681
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
27
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
28
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
29 def __initializeCondaInterface():
6681
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
30 """
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
31 Private module function to (re-)initialize the conda interface.
6681
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
32 """
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
33 global __CondaVersionStr, __CondaVersion, __CondaRootPrefix, __initialized
6681
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
34
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
35 if not __initialized:
6681
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
36 exe = Preferences.getConda("CondaExecutable")
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
37 if not exe:
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
38 exe = "conda"
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
39
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
40 proc = QProcess()
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
41 proc.start(exe, ["info", "--json"])
6681
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
42 if not proc.waitForStarted(15000):
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
43 __CondaVersionStr = QCoreApplication.translate(
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
44 "CondaInterface",
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
45 '<conda not found or not configured.>')
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
46 else:
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
47 proc.waitForFinished(15000)
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
48 output = str(proc.readAllStandardOutput(),
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
49 Preferences.getSystem("IOEncoding"),
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
50 'replace').strip()
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
51 try:
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
52 jsonDict = json.loads(output)
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
53 except Exception:
6681
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
54 __CondaVersionStr = QCoreApplication.translate(
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
55 "CondaInterface",
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
56 '<conda returned invalid data.')
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
57 return
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
58
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
59 __CondaVersionStr = jsonDict["conda_version"]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
60 __CondaVersion = tuple(
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
61 int(i) for i in __CondaVersionStr.split(".")
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
62 )
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
63 __CondaRootPrefix = jsonDict["root_prefix"]
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
64
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
65 __initialized = True
6681
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
66
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
67
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
68 def condaVersion():
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
69 """
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
70 Module function to get the conda version.
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
71
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
72 @return tuple containing the conda version
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
73 @rtype tuple of (int, int, int)
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
74 """
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
75 __initializeCondaInterface()
6681
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
76 return __CondaVersion
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
77
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
78
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
79 def condaVersionStr():
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
80 """
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
81 Module function to get the conda version as a string.
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
82
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
83 @return conda version as a string
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
84 @rtype str
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
85 """
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
86 __initializeCondaInterface()
6681
9c1513b488ef CondaInterface, VirtualenvConfigurationDialog: moved the version related functions to the CondaInterface package.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6677
diff changeset
87 return __CondaVersionStr
6697
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
88
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
89
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
90 def rootPrefix():
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
91 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
92 Module function to get the root prefix.
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
93
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
94 @return root prefix
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
95 @rtype str
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
96 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
97 __initializeCondaInterface()
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
98 return __CondaRootPrefix
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
99
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
100
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
101 def resetInterface():
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
102 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
103 Module function to reset the conda interface.
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
104 """
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
105 global __initialized
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
106
2f5c951bdf14 Conda interface: added capability to remove conda environments the conda way.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6681
diff changeset
107 __initialized = False

eric ide

mercurial