Example #1
0
def find_packages(setup_py):
    packages = []
    # All this horrid hackery to recover the install_requires parameter from
    # a setup() call in setup.py.
    #
    # https://stackoverflow.com/questions/24236266/how-to-extract-dependencies-information-from-a-setup-py
    try:
        # Patch setuptools to intercept the setup() call
        with mock.patch.object(setuptools, 'setup') as setup_mock:
            # Get an open file handle and a description of the
            # setup file.
            setup_file, setup_filename, setup_description = imp.find_module('setup', [os.path.dirname(setup_py)])
            # Load setup.py as the module setup. We have to
            # intercept calls to find_packages as well since
            # find_packages will run a 'find'-like operation from
            # the current working directory - which is Bad if the
            # CWD is the root directory...
            with mock.patch.object(setuptools, 'find_packages'):
                imp.load_module('setup', setup_file, setup_filename, setup_description)
        # Grab the call args to setup
        _, setup_kwargs = setup_mock.call_args
        # ...and recover the install_requires parameter. Fun, eh?
        # Don't forget to remove trailing version specifiers that
        # lack version numbers.
        packages = ['{}'.format(p.rstrip('<>=')) for p in setup_kwargs['install_requires']]
    finally:
        # As warned in the docs, we have to close the setup file
        # ourselves.
        if setup_file is not None:
            setup_file.close()
    return packages
Example #2
0
def cmd(args):
    if hasattr(args,"modules") and args.modules is not None:
        for m in args.modules:
            try:
                importlib.load_module(m)

            print("m: " + str(m))
    pass
Example #3
0
    def _load_path(self, module_path):
        module_name = path.basename(path.splitext(module_path)[0])
        pkg_name = '.'.join(parent_package_names(module_path) or '')
        defined_name = ('%s.%s' %
                        (pkg_name, module_name) if pkg_name else module_name)
        if module_name == '__init__':
            defined_name = pkg_name

        search_paths = [parent_path(module_path)]
        f = None
        try:
            if defined_name in sys.modules:
                del sys.modules[defined_name]
            f, p, d = imp.find_module(module_name, search_paths)
            module = importlib.load_module(defined_name, f, p, d)
            if defined_name == '__init__':
                setattr(module, '__path__', search_paths)
            return module
        except Exception as e:
            sys.stderr.write("Failed to load module '%s' due to: %s" %
                             (module_path, e))
            if self.abort_on_load_failure:
                raise e
        finally:
            if f:
                f.close()
Example #4
0
 def import_module(name):
     # attempt to fix #326 - load modules dot by dot
     path = sys.path
     for part in name.split('.'):
         fp, pathname, description = importlib.find_module(part, path)
         module = importlib.load_module(name, fp, pathname, description)
         path = module.__path__
     return module
Example #5
0
 def import_module(name):
     # attempt to fix #326 - load modules dot by dot
     path = sys.path
     for part in name.split('.'):
         fp, pathname, description = importlib.find_module(part, path)
         module = importlib.load_module(name, fp, pathname, description)
         path = module.__path__
     return module
Example #6
0
 def _runPlugin(self, filepath):
     log.debug("RUN plugin from %s" % filepath)
     module_name = os.path.splitext(os.path.basename(filepath))[0]
     f, filename, description = importlib.find_module(
         module_name, [os.path.dirname(filepath)])
     print(f, filename, description)
     mod = importlib.load_module(module_name, f, filename, description)
     mod.PluginEntry(self.session)
Example #7
0
 def _runPlugin(self, filepath):
     androconf.debug("RUN plugin from %s" % filepath)
     module_name = os.path.splitext(os.path.basename(filepath))[0]
     f, filename, description = importlib.find_module(
         module_name,
         [os.path.dirname(filepath)])
     print(f, filename, description)
     mod = importlib.load_module(module_name, f, filename, description)
     mod.PluginEntry(self.session)
Example #8
0
def make_python2_module(path_to_python):
    try:
        return sys.modules[name]
    except KeyError:
        try:
            fp, pathname, description = importlib.find_module(
                name, [path_to_python.parent])
        except ImportError:
            try:
                fp, pathname, description = (
                    open(name), path_to_python, ('', 'r', importlib.PY_SOURCE))
            except IOError:
                raise ImportError('Could not find a module for %r' %
                                  str(path_to_python))
        # If any of the following calls raises an exception,
        # there's a problem we can't handle -- let the caller handle it.
        try:
            return importlib.load_module(name, fp, pathname, description)
        finally:
            if fp:
                fp.close()
Example #9
0
def make_python2_module(path_to_python):
    try:
        return sys.modules[name]
    except KeyError:
        try:
            fp, pathname, description = importlib.find_module(
                name, [path_to_python.parent])
        except ImportError:
            try:
                fp, pathname, description = (open(name), path_to_python,
                                             ('', 'r', importlib.PY_SOURCE))
            except IOError:
                raise ImportError('Could not find a module for %r' %
                                  str(path_to_python))
        # If any of the following calls raises an exception,
        # there's a problem we can't handle -- let the caller handle it.
        try:
            return importlib.load_module(name, fp, pathname, description)
        finally:
            if fp:
                fp.close()
Example #10
0
 def import_module(name):
     fp, pathname, description = importlib.find_module(name.replace('.', '/'))
     return importlib.load_module(name, fp, pathname, description)
Example #11
0
 def import_module(name):
     fp, pathname, description = importlib.find_module(name)
     return importlib.load_module(name, fp, pathname, description)
Example #12
0
 def import_module(name):
     fp, pathname, description = importlib.find_module(name)
     return importlib.load_module(name, fp, pathname, description)
Example #13
0
 def load_plugin(plugin):
     return importlib.load_module(main_module, *plugin["info"])
Example #14
0
 def import_module(name):
     fp, pathname, description = importlib.find_module(
         name.replace('.', '/'))
     return importlib.load_module(name, fp, pathname, description)
import json
import unittest
from unittest import TestCase
from flask import session
import os

import importlib
crud  = importlib.load_module('../crud.py')
model = importlib.load_module('../model.py')
server = importlib.load_module('../server.py')

from server import app
#import crud
from model import db, User, Book, connect_to_db, Bookshelf, ShelvedBook, OwnedStatus, ReadingStatus
from datetime import datetime

def make_book_info(num):
    with open('data/seeding_jsons/better_book_data.json') as f:
        book_data = json.loads(f.read())

    book_data_seeding = []
  
    count = 0
    for item in book_data:
            title = book_data[item]['title']
            author = book_data[item]['author']
            publisher = book_data[item]['publisher']
            published_date = book_data[item]['year_published']
            isbn = book_data[item]['isbn']
            description = book_data[item]['description']
            cover_img_source = book_data[item]['cover_img_source']['thumbnail']
def loadModuleFile(moduleName, filePath):
    with open(filePath, 'r') as f:
        return importlib.load_module(moduleName, f, "%s.py" % moduleName,
                                     (".py", "r", importlib.PY_SOURCE))