Skip to content

Commit c571138

Browse files
committed
Merge branch 'master' of https://github.com/compas-dev/compas
2 parents 338522d + aa33f5a commit c571138

File tree

4 files changed

+41
-12
lines changed

4 files changed

+41
-12
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
### Changed
1313

14+
- Fix `XFunc` and `RPC` environment activation.
1415
- Fix exception on Rhino Mac.
1516
- Fix missing import on `compas_rhino.geometry`.
1617
- Fix `compas.geometry.offset_polygon`.

src/compas/_os.py

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66
import os
77
import sys
88

9+
try:
10+
NotADirectoryError
11+
except NameError:
12+
class NotADirectoryError(Exception):
13+
pass
914

1015
PY3 = sys.version_info[0] == 3
1116
system = sys.platform
@@ -14,6 +19,16 @@
1419
if 'ironpython' in sys.version.lower() and os.name == 'nt':
1520
system = 'win32'
1621

22+
try:
23+
from compas_bootstrapper import PYTHON_DIRECTORY
24+
except:
25+
# We re-map CONDA_PREFIX for backwards compatibility reasons
26+
# In a few releases down the line, we can get rid of this bit
27+
try:
28+
from compas_bootstrapper import CONDA_PREFIX as PYTHON_DIRECTORY
29+
except:
30+
PYTHON_DIRECTORY = None
31+
1732

1833
def select_python(python_executable):
1934
"""Selects the most likely python interpreter to run.
@@ -29,16 +44,6 @@ def select_python(python_executable):
2944
"""
3045
python_executable = python_executable or 'pythonw'
3146

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-
4247
if PYTHON_DIRECTORY and os.path.exists(PYTHON_DIRECTORY):
4348
python = os.path.join(PYTHON_DIRECTORY, python_executable)
4449
if os.path.exists(python):
@@ -63,6 +68,26 @@ def select_python(python_executable):
6368
return python_executable
6469

6570

71+
def prepare_environment():
72+
"""Prepares an environment context to run Python on.
73+
74+
If Python is being used from a conda environment, this is roughly equivalent
75+
to activating the conda environment by setting up the correct environment
76+
variables.
77+
"""
78+
env = os.environ.copy()
79+
80+
if PYTHON_DIRECTORY:
81+
lib_bin = os.path.join(PYTHON_DIRECTORY, 'Library', 'bin')
82+
if os.path.exists(lib_bin):
83+
env['PATH'] += os.pathsep + lib_bin
84+
85+
lib_bin = os.path.join(PYTHON_DIRECTORY, 'lib')
86+
if os.path.exists(lib_bin):
87+
env['PATH'] += os.pathsep + lib_bin
88+
89+
return env
90+
6691
def absjoin(*parts):
6792
return os.path.abspath(os.path.join(*parts))
6893

src/compas/rpc/proxy.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,13 @@ def start_server(self):
223223
224224
"""
225225
python = self.python
226+
env = compas._os.prepare_environment()
226227

227228
try:
228229
Popen
229230
except NameError:
230231
self._process = Process()
232+
self._process.StartInfo.EnvironmentVariables = env
231233
self._process.StartInfo.UseShellExecute = False
232234
self._process.StartInfo.RedirectStandardOutput = True
233235
self._process.StartInfo.RedirectStandardError = True
@@ -236,7 +238,7 @@ def start_server(self):
236238
self._process.Start()
237239
else:
238240
args = [python, '-m', self.service, str(self._port)]
239-
self._process = Popen(args, stdout=PIPE, stderr=STDOUT)
241+
self._process = Popen(args, stdout=PIPE, stderr=STDOUT, env=env)
240242

241243
server = ServerProxy(self.address)
242244

src/compas/utilities/xfunc.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,8 @@ def __call__(self, *args, **kwargs):
376376
self.opath,
377377
self.serializer]
378378

379-
process = Popen(process_args, stderr=PIPE, stdout=PIPE)
379+
env = compas._os.prepare_environment()
380+
process = Popen(process_args, stderr=PIPE, stdout=PIPE, env=env)
380381

381382
while process.poll() is None:
382383
line = process.stdout.readline().strip()

0 commit comments

Comments
 (0)