Skip to content
This repository has been archived by the owner on Nov 17, 2020. It is now read-only.

Commit

Permalink
Clean up the libtool importer a bit. Add a context so we can use it
Browse files Browse the repository at this point in the history
2008-10-29  Johan Dahlin  <jdahlin@async.com.br>

    * giscanner/libtoolimporter.py:
    * giscanner/sourcescanner.py:
    Clean up the libtool importer a bit. Add a context so we
    can use it through a with statement.
    Don't just look in the current directory, look in the whole
    sys.path.


svn path=/trunk/; revision=830
  • Loading branch information
Johan Dahlin authored and Johan Dahlin committed Oct 29, 2008
1 parent 13e99bc commit 8a16eeb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
9 changes: 9 additions & 0 deletions ChangeLog
@@ -1,3 +1,12 @@
2008-10-29 Johan Dahlin <jdahlin@async.com.br>

* giscanner/libtoolimporter.py:
* giscanner/sourcescanner.py:
Clean up the libtool importer a bit. Add a context so we
can use it through a with statement.
Don't just look in the current directory, look in the whole
sys.path.

2008-10-29 Tommi Komulainen <tommi.komulainen@iki.fi>

Bug 558065 – gitesttypes should be installed
Expand Down
20 changes: 10 additions & 10 deletions giscanner/libtoolimporter.py
Expand Up @@ -25,30 +25,30 @@
from .utils import extract_libtool


class LibToolImporter(object):
class LibtoolImporter(object):

def __init__(self, name, path):
self.name = name
self.path = path

@staticmethod
def find_module(name, path=None):
@classmethod
def find_module(cls, name, path=None):
modname = name.split('.')[-1]
for part in path or sys.path:
full = os.path.join(part, '.libs', modname + '.la')
if os.path.exists(full):
return LibToolImporter(name, full)
return cls(name, full)

def load_module(self, name):
realpath = extract_libtool(self.path)
mod = imp.load_module(name, open(realpath), realpath,
('.so', 'rb', 3))
return mod

@classmethod
def __enter__(cls):
sys.meta_path.append(cls)

def install_libtoolimporter():
sys.meta_path.append(LibToolImporter)


def uninstall_libtoolimporter():
sys.meta_path.remove(LibToolImporter)
@classmethod
def __exit__(cls, type, value, traceback):
sys.meta_path.remove(cls)
11 changes: 6 additions & 5 deletions giscanner/sourcescanner.py
Expand Up @@ -18,14 +18,13 @@
# 02110-1301, USA.
#

from __future__ import with_statement
import os
import subprocess
import tempfile

from .libtoolimporter import install_libtoolimporter, uninstall_libtoolimporter
install_libtoolimporter()
from . import _giscanner
uninstall_libtoolimporter()
from .libtoolimporter import LibtoolImporter


(CSYMBOL_TYPE_INVALID,
CSYMBOL_TYPE_ELLIPSIS,
Expand Down Expand Up @@ -186,7 +185,9 @@ def base_type(self):
class SourceScanner(object):

def __init__(self):
self._scanner = _giscanner.SourceScanner()
with LibtoolImporter:
from _giscanner import SourceScanner
self._scanner = SourceScanner()
self._filenames = []
self._cpp_options = []

Expand Down

0 comments on commit 8a16eeb

Please sign in to comment.