def test_project_manager(init_project): ProjectManager.set_path('tests/sample_project') assert ProjectManager.RACKET_DIR == 'tests/sample_project' ProjectManager.set_path('tests/sample_project-2') ProjectManager.create_subdirs() assert os.path.exists('tests/sample_project-2') is True shutil.rmtree('tests/sample_project-2') ProjectManager.set_path('tests/sample_project') ProjectManager.create_template() for file in TEMPLATE_PROJECT_FILES: file_path = file.replace('template/', '') assert os.path.isfile(os.path.join(ProjectManager.RACKET_DIR, file_path))
def create_app(cls, env: str, clean: bool) -> Flask: app = Flask(__name__, static_folder=cls.static_files_dir() if not env == 'test' else None, template_folder=cls.template_files_dir() if not env == 'test' else None) @app.route('/', defaults={'path': ''}) @app.route('/<path:path>') def index(path): return send_from_directory(cls.template_files_dir(), "index.html") app.config.from_object(config_by_name[env]) CORS(app, resources={r"/*": {"origins": "*"}}, allow_headers="*") app.config['SQLALCHEMY_DATABASE_URI'] = ProjectManager.db_path() from racket.api import api_bp from racket.models import db with app.app_context(): db.app = app db.init_app(app) cls.create_db(db, clean) app.register_blueprint(api_bp, url_prefix='/api/v1') return app
def historic_scores_(model_id: int = None, name: str = None, version: str = None) -> Dict: """ Get the historic scores for a model, in the form of:: { val_loss: [...], val_acc: [..], acc: [...], loss: [...] } Where the arrays are the respective measures at the end of each epoch Parameters ---------- version : str Model version in the format: "major.minor.patch". Ignored if model_id is passed name : str Name of the model. Must be provided if version is provided. Ignored if model_id is passed model_id : int Unique ID of the model Returns ------- scores: dict Dictionary of key: score name, value: score array """ model = _model_from_name_ver_id(model_id, name, version) base_path = ProjectManager.get_value('saved-models') hs_path = os.path.join( base_path, model.model_name + '_' + 'history' + '_' + model.version_dir + '.json') with open(hs_path, 'r') as scores: return json.load(scores)
def create_app(cls, env: str, clean: bool) -> Flask: app = Flask(__name__, static_folder=cls.static_files_dir(), template_folder=cls.react_dist_dir()) app.config.from_object(config_by_name[env]) app.config['SQLALCHEMY_DATABASE_URI'] = ProjectManager.db_path() from racket.api import api_bp from racket.models import db with app.app_context(): db.app = app db.init_app(app) cls.create_db(db, clean) app.register_blueprint(api_bp, url_prefix='/api/v1') @app.route('/') def index(): return send_from_directory(cls.react_dist_dir(), "index.html") return app
def wrapper(*args, **kwargs): if ProjectManager.get_config() is None: raise CLIError( 'No configuration found. Are you sure you have a racket.yaml file in your current directory?' 'Run racket init to start a new project') return fn(*args, **kwargs)
def test_project(): ProjectManager.set_path(None) with pytest.raises(NotInitializedError): ProjectManager.get_models()
def get_path(cls, name: str) -> str: return os.path.join(ProjectManager.get_value('saved-models'), name)
def init(path: str, name: str) -> None: """ Creates a new project """ ProjectManager.init_project(path, name) p.print_success(f'Successfully initiated project: {name}!')
def test_project(): # noinspection PyTypeChecker ProjectManager.set_path(None) with pytest.raises(NotInitializedError): ProjectManager.get_models()
def create_proj(): ProjectManager.init('.', 'sample_project') yield shutil.rmtree('sample_project')
def init_project(): ProjectManager.init('tests', 'sample_project') yield os.chdir('../') shutil.rmtree('sample_project')