Example #1
0
# accomplished by temporarily altering the PATH and then restoring it after
# cairocffi has initialized.
if os.name == 'nt':
    _save_path = os.environ.get('PATH')
    _cairo_path = os.environ.get('CAIRO')
    if not _cairo_path:
        _cairo_path = op.abspath(op.dirname(wx.__file__))
    os.environ['PATH'] = _cairo_path + os.pathsep + _save_path

import cairocffi
from cairocffi import cairo as cairo_c
from cairocffi import ffi

# Make it so subsequent `import cairo` statements still work as if it
# was really PyCairo
cairocffi.install_as_pycairo()

# Now restore the original PATH
if os.name == 'nt':
    os.environ['PATH'] = _save_path

#----------------------------------------------------------------------------


# convenience functions, just to save a bit of typing below
def voidp(ptr):
    """Convert a SIP void* type to a ffi cdata"""
    if isinstance(ptr, ffi.CData):
        return ptr
    return ffi.cast('void *', int(ptr))
Example #2
0
__author__ = 'mnowotka'

# ----------------------------------------------------------------------------------------------------------------------

try:
    import cairo
    cffi = False
except ImportError:
    import cairocffi
    cairocffi.install_as_pycairo()
    cffi = True
    import io
    import cairo
    if not hasattr(cairo, 'HAS_PDF_SURFACE'):
        cairo.HAS_PDF_SURFACE = False
    if not hasattr(cairo, 'HAS_SVG_SURFACE'):
        cairo.HAS_SVG_SURFACE = True


from itertools import cycle, islice
from rdkit import Chem
from chembl_beaker.beaker.utils.functional import _apply, _call
from chembl_beaker.beaker.utils.io import _parseMolData, _parseSMILESData
from chembl_beaker.beaker.utils.chemical_transformation import _computeCoords, _atomMapNumber, _kekulize
from chembl_beaker.beaker.utils.io import _getMatches
from rdkit.Chem.Draw import rdMolDraw2D, MolDrawOptions

# ----------------------------------------------------------------------------------------------------------------------


def _mols2svg(mols, size, legend, kekulize=True, wedgeBonds=True, fitImage=True, atomMapNumber=False,
Example #3
0
def test(load_gi, backend=None, strict=False, filter_=None, failfast=False):
    """Run the test suite.

    load_gi -- run all tests in the pygobject suite with PyGObject
    backend -- "ctypes" or "cffi"
    strict  -- fail on glib warnings
    filter_ -- filter for test names (class names)
    """

    global _is_gi, _is_pypy, _has_cairo, _gi_version, GIOverflowError

    _is_gi = load_gi
    _is_pypy = platform.python_implementation() == "PyPy"
    _has_cairo = True

    if not load_gi:
        try:
            import cairocffi
            cairocffi.install_as_pycairo()
        except (ImportError, OSError):
            _has_cairo = False
        import pgi
        pgi.install_as_gi()
        try:
            pgi.set_backend(backend)
        except LookupError:
            print("Couldn't load backend: %r" % backend)
            return

    def headline(text):
        return (("### %s " % text) + "#" * 80)[:80]

    import gi

    TYPELIBS = {
        "Gtk": "3.0",
        "Gdk": "3.0",
        "Clutter": "1.0",
        "Regress": "1.0",
        "GIMarshallingTests": "1.0",
        "PangoCairo": "1.0"
    }

    for name, version in TYPELIBS.items():
        try:
            gi.require_version(name, version)
        except ValueError:
            pass

    if load_gi:
        assert gi.__name__ == "gi"
        try:
            _gi_version = gi.version_info
        except AttributeError:
            _gi_version = gi._gobject.pygobject_version

        if _gi_version < (3, 10):
            GIOverflowError = ValueError
        else:
            GIOverflowError = OverflowError

        hl = headline("GI")
    else:
        assert gi.__name__ == "pgi"
        if backend:
            hl = headline("PGI (%s)" % backend)
        else:
            hl = headline("PGI")

        GIOverflowError = OverflowError
    print(hl[:80])

    # gi uses logging
    logging.disable(logging.ERROR)

    if strict:
        # make glib warnings fatal
        from gi.repository import GLib
        GLib.log_set_always_fatal(
            GLib.LogLevelFlags.LEVEL_CRITICAL |
            GLib.LogLevelFlags.LEVEL_ERROR |
            GLib.LogLevelFlags.LEVEL_WARNING)

    current_dir = os.path.join(os.path.dirname(__file__))
    tests = []
    tests = discover(current_dir, "tests_pygobject")
    tests += discover(current_dir, "tests_mixed")
    if not load_gi:
        tests.extend(discover(current_dir, "tests_pgi"))

    if filter_ is not None:
        tests = filter(lambda t: filter_(t.__name__), tests)

    tests = [unittest.makeSuite(t) for t in tests]

    # only in case all get run, so filtered results don't get spammed
    if filter_ is None:
        # collected by the FIXME decorator
        print(headline("FIXME"))
        for item, desc in sorted(_fixme.items(), key=lambda x: repr(x)):
            print(" -> %s.%s" % (item.__module__, item.__name__), end="")
            if desc:
                print("(%s)" % desc)
            else:
                print()

    run = unittest.TextTestRunner(
        verbosity=2, failfast=failfast).run(unittest.TestSuite(tests))

    return len(run.failures) + len(run.errors)
Example #4
0
    -----------------

    Fetch and decode images in various formats.

    :copyright: Copyright 2011-2014 Simon Sapin and contributors, see AUTHORS.
    :license: BSD, see LICENSE for details.

"""

from __future__ import division, unicode_literals

from io import BytesIO
import math

import cairocffi
cairocffi.install_as_pycairo()  # for CairoSVG
CAIRO_HAS_MIME_DATA = cairocffi.cairo_version() >= 11000

import cairosvg.parser
import cairosvg.surface
assert cairosvg.surface.cairo is cairocffi, (
    'CairoSVG is using pycairo instead of cairocffi. '
    'Make sure it is not imported before WeasyPrint.')

try:
    from cairocffi import pixbuf
except OSError:
    pixbuf = None

from .urls import fetch, URLFetchingError
from .logger import LOGGER
Example #5
0
def test_install_as_pycairo():
    cairocffi.install_as_pycairo()
    import cairo
    assert cairo is cairocffi
Example #6
0
def test_install_as_pycairo():
    cairocffi.install_as_pycairo()
    import cairo
    assert cairo is cairocffi
Example #7
0
    -----------------

    Fetch and decode images in various formats.

    :copyright: Copyright 2011-2014 Simon Sapin and contributors, see AUTHORS.
    :license: BSD, see LICENSE for details.

"""

from __future__ import division, unicode_literals

from io import BytesIO
import math

import cairocffi
cairocffi.install_as_pycairo()  # for CairoSVG
CAIRO_HAS_MIME_DATA = cairocffi.cairo_version() >= 11000

import cairosvg.parser
import cairosvg.surface
assert cairosvg.surface.cairo is cairocffi, (
    'CairoSVG is using pycairo instead of cairocffi. '
    'Make sure it is not imported before WeasyPrint.')

try:
    from cairocffi import pixbuf
except OSError:
    pixbuf = None

from .urls import fetch, URLFetchingError
from .logger import LOGGER
Example #8
0
def test(load_gi, backend=None, strict=False, filter_=None, failfast=False):
    """Run the test suite.

    load_gi -- run all tests in the pygobject suite with PyGObject
    backend -- "ctypes" or "cffi"
    strict  -- fail on glib warnings
    filter_ -- filter for test names (class names)
    """

    global _is_gi, _is_pypy, _has_cairo, _gi_version, GIOverflowError

    _is_gi = load_gi
    _is_pypy = platform.python_implementation() == "PyPy"
    _has_cairo = True

    if not load_gi:
        try:
            import cairocffi
            cairocffi.install_as_pycairo()
        except (ImportError, OSError):
            _has_cairo = False
        import pgi
        pgi.install_as_gi()
        try:
            pgi.set_backend(backend)
        except LookupError:
            print("Couldn't load backend: %r" % backend)
            return

    def headline(text):
        return (("### %s " % text) + "#" * 80)[:80]

    import gi

    TYPELIBS = {
        "Gtk": "3.0",
        "Gdk": "3.0",
        "Clutter": "1.0",
        "Regress": "1.0",
        "GIMarshallingTests": "1.0",
        "PangoCairo": "1.0"
    }

    for name, version in TYPELIBS.items():
        try:
            gi.require_version(name, version)
        except ValueError:
            pass

    if load_gi:
        assert gi.__name__ == "gi"
        try:
            _gi_version = gi.version_info
        except AttributeError:
            _gi_version = gi._gobject.pygobject_version

        if _gi_version < (3, 10):
            GIOverflowError = ValueError
        else:
            GIOverflowError = OverflowError

        hl = headline("GI")
    else:
        assert gi.__name__ == "pgi"
        if backend:
            hl = headline("PGI (%s)" % backend)
        else:
            hl = headline("PGI")

        GIOverflowError = OverflowError
    print(hl[:80])

    # gi uses logging
    logging.disable(logging.ERROR)

    if strict:
        # make glib warnings fatal
        from gi.repository import GLib
        GLib.log_set_always_fatal(GLib.LogLevelFlags.LEVEL_CRITICAL
                                  | GLib.LogLevelFlags.LEVEL_ERROR
                                  | GLib.LogLevelFlags.LEVEL_WARNING)

    current_dir = os.path.join(os.path.dirname(__file__))
    tests = []
    tests = discover(current_dir, "tests_pygobject")
    tests += discover(current_dir, "tests_mixed")
    if not load_gi:
        tests.extend(discover(current_dir, "tests_pgi"))

    if filter_ is not None:
        tests = filter(lambda t: filter_(t.__name__), tests)

    tests = [unittest.makeSuite(t) for t in tests]

    # only in case all get run, so filtered results don't get spammed
    if filter_ is None:
        # collected by the FIXME decorator
        print(headline("FIXME"))
        for item, desc in sorted(_fixme.items(), key=lambda x: repr(x)):
            print(" -> %s.%s" % (item.__module__, item.__name__), end="")
            if desc:
                print("(%s)" % desc)
            else:
                print()

    run = unittest.TextTestRunner(verbosity=2, failfast=failfast).run(
        unittest.TestSuite(tests))

    return len(run.failures) + len(run.errors)