Beispiel #1
0
def get_default_repository():
    default_repository_type = config.get('repository', 'default')

    if default_repository_type == 'local':
        return get_local_repository()
    elif default_repository_type == 's3':
        raise NotImplementedError("S3 repository is not yet implemented")
    else:
        raise ValueError("Unknown default repository type: {}".format(
            default_repository_type))
Beispiel #2
0
def init_db(db_config=None):
    # Use default config if not provided
    db_config = db_config or config.get('db', 'engine')

    engine = create_engine(db_config,
                           echo=False,
                           connect_args={'check_same_thread': False})
    Base.metadata.create_all(engine)

    return sessionmaker(bind=engine)
Beispiel #3
0
def get_local_repository(base_path=None):
    base_path = base_path or config.get('repository', 'base_path')
    return LocalRepository(base_path)
Beispiel #4
0
# http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from bentoml import config

DEFAULT_LOCAL_REPO_PATH = config.get('repository', 'base_path')


# Bento, is a file format representing a saved BentoService
class BaseRepository(object):
    def add(self, bento_service_instance, version=None):
        pass

    def delete(self, bento_name, bento_version=None):
        pass

    def get(self, bento_name, bento_version):
        pass

    def list(self, bento_name):
        pass
Beispiel #5
0
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

from contextlib import contextmanager

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

from bentoml import config
from bentoml.exceptions import BentoMLException

# sql alchemy config
engine = create_engine(config.get('db', 'engine'),
                       echo=False,
                       connect_args={'check_same_thread': False})
Base = declarative_base()
Session = sessionmaker(bind=engine)


@contextmanager
def create_session():
    session = Session()
    try:
        yield session
        session.commit()
    except Exception as e:
        session.rollback()
        raise BentoMLException(message=e)