On sab, 2009-02-07 at 00:17 +0100, Lorenzo Mancini wrote:

> plain text document attachment (ctypes_basic_support2.patch)
> Index: deploy/tools/PyInstaller/bindepend.py
> ===================================================================
> --- deploy/tools/PyInstaller/bindepend.py     (revision 21414)
> +++ deploy/tools/PyInstaller/bindepend.py     (working copy)
> @@ -354,7 +354,12 @@
>          m = re.search(r"\s+(.*?)\s+\(.*\)", line)
>          if m:
>              lib = m.group(1)
> -            if os.path.exists(lib):
> +            # If a dylib lists itself as dependency (?), using its bare 
> filename
> +            # instead of full path, it won't probably be found as is on the
> +            # filesystem; we skip the check.
> +            if lib == os.path.basename(pth):
> +                continue
> +            elif os.path.exists(lib):
>                  rslt.append(lib)
>              else:
>                  print 'E: cannot find path %s (needed by %s)' % \

The comment needs rewording because I can't understand what the problem
is.

> Index: deploy/tools/PyInstaller/Build.py
> ===================================================================
> --- deploy/tools/PyInstaller/Build.py (revision 21414)
> +++ deploy/tools/PyInstaller/Build.py (working copy)
> @@ -318,8 +318,12 @@
>                          zipfiles.append((os.path.basename(str(mod.owner)),
>                                           str(mod.owner), 'ZIPFILE'))
>                      elif modnm == '__main__':
> -                        pass
> +                        # This and the next case are about mf.PyModule
> +                        # instances. Take care of their required shared
> +                        # libraries via ctypes.
> +                        binaries.extend(mod.binaries)
>                      else:
> +                        binaries.extend(mod.binaries)
>                          pure.append((modnm, fnm, 'PYMODULE'))
>          binaries.extend(bindepend.Dependencies(binaries,
>                                                 platform=target_platform))

The comment needs rewording because I can't understand what that code is
about.

> Index: deploy/tools/PyInstaller/mf.py
> ===================================================================
> --- deploy/tools/PyInstaller/mf.py    (revision 21414)
> +++ deploy/tools/PyInstaller/mf.py    (working copy)
> @@ -25,6 +25,12 @@
>  except ImportError:
>      zipimport = None
>  
> +try:
> +    # ctypes is supported starting with python 2.5
> +    import ctypes
> +except ImportError:
> +    ctypes = None
> +
>  import suffixes
>  
>  try:

I would say "if ctypes is present, we can enable specific dependency
discovery". Python 2.5 is when it shipped through the standard library,
but it's been available before as a 3rd-party extension and your code
would work in that case just as well.


> @@ -508,6 +514,45 @@
>      def ispackage(self, nm):
>          return self.modules[nm].ispackage()
>  
> +    def _resolveCtypesImports(self, mod):
> +        """Completes ctypes BINARY entries intended in module with their
> +        full path.
> +        """
> +
> +        if sys.platform.startswith("linux"):
> +            envvar = "LD_LIBRARY_PATH"
> +        elif sys.platform.startswith("darwin"):
> +            envvar = "DYLD_LIBRARY_PATH"
> +        else:
> +            envvar = "PATH"
> +
> +        def _savePaths():
> +            old = os.environ.get(envvar, None)
> +            os.environ[envvar] = os.pathsep.join(self.path)
> +            return old
> +

I wouldn't fully replace it: just prepend the user-specified paths.

> +        def _restorePaths(old):
> +            del os.environ[envvar]
> +            if old:
> +                os.environ[envvar] = old
> +
> +        cbinaries = list(mod.binaries)
> +        mod.binaries = []
> +        for cbin in cbinaries:
> +
> +            # Executes find_library using the local paths of ImportTracker as
> +            # library search paths, then replaces original values.
> +
> +            old = _savePaths()
> +            from ctypes.util import find_library
> +            cpath = find_library(os.path.splitext(cbin)[0])
> +            _restorePaths(old)
> +
> +            if cpath is None:
> +                print "W: library %s required via ctypes not found" % (cbin,)
> +            else:
> +                mod.binaries.append((cbin, cpath, "BINARY"))
> +

Given that you're doing nothing here but calling find_library, I think
it's safe to call savePaths() / restorePaths() just once (before and
after the for loop).

> @@ -536,6 +581,10 @@
>          # or
>          #   mod = director.getmod(nm)
>          if mod:
> +
> +            if ctypes and isinstance(mod, PyModule):
> +                self._resolveCtypesImports(mod)
> +
>              mod.__name__ = fqname
>              self.modules[fqname] = mod
>              # now look for hooks

Please remove those extra newlines.

Amazing work, thanks! The only thing missing is some tests, and
documentation. Can you please fill in the empty wiki page linked from
here?

http://pyinstaller.python-hosting.com/wiki/SupportedPackages

Thanks!
-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/PyInstaller?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to