Ejemplo n.º 1
0
    def write_and_import(self, code, modulename='mymodule'):
        self.assertTrue('.py' not in modulename)
        filename = modulename + '.py'
        if isinstance(code, bytes):
            code = code.decode('utf-8')
        # Be explicit about encoding the temp file as UTF-8 (issue #63):
        with io.open(self.tempdir + filename, 'w', encoding='utf-8') as f:
            f.write(textwrap.dedent(code).strip() + '\n')

        # meta_path_len = len(sys.meta_path)
        install_hooks(modulename)
        # print('Hooks installed')
        # assert len(sys.meta_path) == 1 + meta_path_len
        # print('sys.meta_path is: {0}'.format(sys.meta_path))
        module = None

        sys.path.insert(0, self.tempdir)
        try:
            module = __import__(modulename)
        except SyntaxError:
            print('Bombed!')
        else:
            print('Succeeded!')
        finally:
            remove_hooks()
            # print('Hooks removed')
            sys.path.remove(self.tempdir)
        return module
Ejemplo n.º 2
0
    def write_and_import(self, code, modulename='mymodule'):
        self.assertTrue('.py' not in modulename)
        filename = modulename + '.py'
        if isinstance(code, bytes):
            code = code.decode('utf-8')
        # Be explicit about encoding the temp file as UTF-8 (issue #63):
        with io.open(self.tempdir + filename, 'w', encoding='utf-8') as f:
            f.write(textwrap.dedent(code).strip() + '\n')

        # meta_path_len = len(sys.meta_path)
        install_hooks(modulename)
        # print('Hooks installed')
        # assert len(sys.meta_path) == 1 + meta_path_len
        # print('sys.meta_path is: {0}'.format(sys.meta_path))
        module = None

        sys.path.insert(0, self.tempdir)
        try:
            module = __import__(modulename)
        except SyntaxError:
            print('Bombed!')
        else:
            print('Succeeded!')
        finally:
            remove_hooks()
            # print('Hooks removed')
            sys.path.remove(self.tempdir)
        return module
Ejemplo n.º 3
0
    def write_and_import(self, code, modulename='mymodule'):
        self.assertTrue('.py' not in modulename)
        filename = modulename + '.py'
        with open(self.tempdir + filename, 'w') as f:
            f.write(textwrap.dedent(code).strip() + '\n')

        # meta_path_len = len(sys.meta_path)
        install_hooks(modulename)
        # print('Hooks installed')
        # assert len(sys.meta_path) == 1 + meta_path_len
        # print('sys.meta_path is: {}'.format(sys.meta_path))
        module = None

        sys.path.insert(0, self.tempdir)
        try:
            module = __import__(modulename)
        except SyntaxError:
            print('Bombed!')
        else:
            print('Succeeded!')
        finally:
            remove_hooks()
            # print('Hooks removed')
            sys.path.remove(self.tempdir)
        return module
Ejemplo n.º 4
0
_logger = logging.getLogger("salad")
_logger.addHandler(logging.StreamHandler())
_logger.setLevel(logging.INFO)

__TMPDIR_LOCK = threading.Lock()

if six.PY3:

    if onWindows():
        # create '/tmp' folder if not present
        # required by autotranslate module
        # TODO: remove when https://github.com/PythonCharmers/python-future/issues/295
        # is fixed
        if not os.path.exists("/tmp"):
            with __TMPDIR_LOCK:
                try:
                    os.makedirs("/tmp")
                except OSError as exception:
                    _logger.error(
                        u"Cannot create '\\tmp' folder in root needed for"
                        "'cwltool' Python 3 installation.")
                    exit(1)
    with __TMPDIR_LOCK:
        from past import autotranslate  # type: ignore
        from past.translation import remove_hooks  # type: ignore
        autotranslate(['avro', 'avro.schema'])
        import avro
        import avro.schema  # pylint: disable=no-name-in-module,import-error
        remove_hooks()
Ejemplo n.º 5
0
#!/usr/bin/env python
"""Tool to extract instrument stems from medleydb"""

import logging
#logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
import os
from collections import defaultdict
import subprocess
import tempfile
import shutil
import argparse

from past.translation import install_hooks, remove_hooks
install_hooks(['medleydb'])
import medleydb as mdb
remove_hooks()


def get_instance(name):
    for cls in TrackParser.__subclasses__():
        if cls.__name__.lower().startswith(name.lower()):
            return cls()
    return TrackParser()


class TrackParser(object):
    track_attributes = [
        'file_path',
        'label',
    ]