1414if 'ironpython' in sys .version .lower () and os .name == 'nt' :
1515 system = 'win32'
1616
17+ try :
18+ from compas_bootstrapper import PYTHON_DIRECTORY
19+ except :
20+ # We re-map CONDA_PREFIX for backwards compatibility reasons
21+ # In a few releases down the line, we can get rid of this bit
22+ try :
23+ from compas_bootstrapper import CONDA_PREFIX as PYTHON_DIRECTORY
24+ except :
25+ PYTHON_DIRECTORY = None
26+
1727
1828def select_python (python_executable ):
1929 """Selects the most likely python interpreter to run.
@@ -29,16 +39,6 @@ def select_python(python_executable):
2939 """
3040 python_executable = python_executable or 'pythonw'
3141
32- try :
33- from compas_bootstrapper import PYTHON_DIRECTORY
34- except :
35- # We re-map CONDA_PREFIX for backwards compatibility reasons
36- # In a few releases down the line, we can get rid of this bit
37- try :
38- from compas_bootstrapper import CONDA_PREFIX as PYTHON_DIRECTORY
39- except :
40- PYTHON_DIRECTORY = None
41-
4242 if PYTHON_DIRECTORY and os .path .exists (PYTHON_DIRECTORY ):
4343 python = os .path .join (PYTHON_DIRECTORY , python_executable )
4444 if os .path .exists (python ):
@@ -63,6 +63,22 @@ def select_python(python_executable):
6363 return python_executable
6464
6565
66+ def prepare_environment ():
67+ """Prepares an environment context to run Python on.
68+
69+ If Python is being used from a conda environment, this is roughly equivalent
70+ to activating the conda environment by setting up the correct environment
71+ variables.
72+ """
73+ env = os .environ .copy ()
74+
75+ if PYTHON_DIRECTORY :
76+ lib_bin = os .path .join (PYTHON_DIRECTORY , 'Library' , 'bin' )
77+ if os .path .exists (lib_bin ):
78+ env ['PATH' ] += ';' + lib_bin
79+
80+ return env
81+
6682def absjoin (* parts ):
6783 return os .path .abspath (os .path .join (* parts ))
6884
0 commit comments