1# coding=utf-8 2# 3# Copyright (C) 2020 Martin Owens <doctormo@geek-2.com> 4# 5# This program is free software; you can redistribute it and/or modify 6# it under the terms of the GNU General Public License as published by 7# the Free Software Foundation; either version 2 of the License, or 8# (at your option) any later version. 9# 10# This program is distributed in the hope that it will be useful, 11# but WITHOUT ANY WARRANTY; without even the implied warranty of 12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13# GNU General Public License for more details. 14# 15# You should have received a copy of the GNU General Public License 16# along with this program; if not, write to the Free Software 17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18# 19""" 20Import this inkex module if you are using the extension manager 21and need virtualenv dependencies. Things like gobject, numpy etc 22 23Always import *before* anything else. 24""" 25 26import os 27import sys 28 29def get_bin(fname): 30 """Get a virtualenv binary for execution, returns full filename""" 31 for path in sys.path: 32 for script in [fname, os.path.join('bin', fname)]: 33 result = os.path.abspath(os.path.join(path, script)) 34 if os.path.isfile(result): 35 return result 36 return None 37 38def activate_virtualenv(): 39 """ 40 The python that inkscape uses and the python installed into the virtualenv 41 are different pythons with different libs. To give access to dependencies 42 that are installed within the virtualenv, we activate the available venv. 43 """ 44 activate_this = get_bin('activate_this.py') 45 if activate_this and os.path.isfile(activate_this): 46 with open(activate_this, 'r') as fhl: 47 exec(fhl.read(), dict(__file__=activate_this)) 48 return 49 50activate_virtualenv() 51