Skip to content
Snippets Groups Projects
Commit ab9b659c authored by Olivier Bertrand's avatar Olivier Bertrand
Browse files

Update blendnavipy to support non virtualenvironment

parent 2d40f7c5
No related branches found
No related tags found
No related merge requests found
......@@ -16,11 +16,18 @@ def activate_virtualenv(venv_path):
tell blender to use our virtualenv where the navigation toolbox \
is installed.
"""
if venv_path is None:
raise NameError('Python is not running within a virtualenv')
filepath = os.path.join(venv_path, 'bin', 'activate_this.py')
with open(filepath, 'r') as f:
exec(f.read(), dict(__file__=filepath))
with open(venv_path, 'r') as f:
exec(f.read(), dict(__file__=venv_path))
def append_path(path_navipy):
""" insert path
Blender comes with its own python installation. Thus, we need to \
tell blender where to look for navipy
"""
for cpath in path_navipy:
sys.path.insert(0, cpath)
def blender_version(pyversion):
......@@ -74,6 +81,14 @@ def main():
# Find the name of the virtualenv, so that we can activate
# it in blender
venv_path = sys.base_prefix
venv_path = os.path.join(venv_path, 'bin', 'activate_this.py')
if os.path.exists(venv_path):
# Runnin in virtualenv
syspath = None
else:
# Find path packages
syspath = sys.path
venv_path = None
# Find python version to be checked agains blender python version
pyver = sys.version_info[:3]
......@@ -94,16 +109,28 @@ def main():
tfile.write(header.encode(encoding))
tfile.write('# check blender version\n'.encode(encoding))
tfile.write('import sys \n'.encode(encoding))
tfile.write('import os \n'.encode(encoding))
for line in inspect.getsourcelines(blender_version)[0]:
tfile.write(line.encode(encoding))
line = 'blender_version({})\n'.format(pyver)
tfile.write(line.encode(encoding))
tfile.write('# activate virtualenv within blender\n'.encode(encoding))
tfile.write('import os \n'.encode(encoding))
for line in inspect.getsourcelines(activate_virtualenv)[0]:
tfile.write(line.encode(encoding))
line = 'activate_virtualenv(\"{}\")\n'.format(venv_path)
tfile.write(line.encode(encoding))
if venv_path is not None:
tfile.write(
'# activate virtualenv within blender\n'.encode(encoding))
for line in inspect.getsourcelines(activate_virtualenv)[0]:
tfile.write(line.encode(encoding))
line = 'activate_virtualenv(\"{}\")\n'.format(venv_path)
tfile.write(line.encode(encoding))
elif syspath is not None:
tfile.write(
'# add navipy path within blender\n'.encode(encoding))
for line in inspect.getsourcelines(append_path)[0]:
tfile.write(line.encode(encoding))
line = 'activate_virtualenv({})\n'.format(str(syspath))
tfile.write(line.encode(encoding))
else:
raise NameError('The path to navipy could not be found')
tfile.write('# run simulation\n'.encode(encoding))
with open(python_script) as infile:
for line in infile:
......
......@@ -43,7 +43,8 @@ setup_dict = {'name': 'navipy',
'package_data': {'navipy': ['resources/database.db',
'resources/forest_world.blend']},
'include_package_data': True,
'console_scripts': [
'blendnavipy = navipy.sensors.blendnavipy:main_func'], }
'entry_points': {
'console_scripts': [
'blendnavipy=navipy.sensors.blendnavipy:main']}, }
setup(**setup_dict)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment