def __init__(self, path=None, repo_branch=None, repo_commit=None, repo_full_path=None, mode=WRITING_MODE): self._config = {} path = clean_repo_path(path) self.path = repo_full_path or os.path.join(path, AIM_REPO_NAME) self.config_path = os.path.join(self.path, AIM_CONFIG_FILE_NAME) self.hash = hashlib.md5(self.path.encode('utf-8')).hexdigest() self.active_commit = repo_commit or AIM_COMMIT_INDEX_DIR_NAME self.root_path = repo_full_path or path self.name = self.root_path.split(os.sep)[-1] self.branch_path = None self.index_path = None self.objects_dir_path = None self.media_dir_path = None self.records_storage = None self.mode = mode if not repo_branch: if self.config: self.branch = self.config.get('active_branch') else: self.branch = repo_branch
def __init__(self, path=None, repo_branch=None, repo_commit=None, repo_full_path=None, mode=WRITING_MODE): self._config = {} path = clean_repo_path(path) self.path = repo_full_path or os.path.join(path, AIM_REPO_NAME) self.config_path = os.path.join(self.path, AIM_CONFIG_FILE_NAME) self.hash = hashlib.md5(self.path.encode('utf-8')).hexdigest() self.active_commit = repo_commit or AIM_COMMIT_INDEX_DIR_NAME if re.match(r'^[A-Za-z0-9_\-]{2,}$', self.active_commit) is None: raise ValueError('run name must be at least 2 characters ' + 'and contain only latin letters, numbers, ' + 'dash and underscore') self.root_path = repo_full_path or path self.name = self.root_path.split(os.sep)[-1] self.branch_path = None self.index_path = None self.objects_dir_path = None self.media_dir_path = None self.records_storage = None self.mode = mode active_exp = self.config.get('active_branch') if repo_branch is not None: experiment = repo_branch elif active_exp is not None: experiment = active_exp else: experiment = None if experiment is not None: run_full_path = get_experiment_run_path(self.path, experiment, self.active_commit) else: run_full_path = None if self.active_commit != AIM_COMMIT_INDEX_DIR_NAME and run_full_path \ and os.path.exists(run_full_path): raise ValueError( ('run `{}` already exists' + '').format(self.active_commit)) if experiment is not None: self.branch = experiment
def down(repo_inst, repo): check_docker_dependency() repo_path = clean_repo_path(repo) if repo_path: repo_inst = AimRepo(repo_path) if repo_inst is None or not repo_inst.exists(): repo_init_alert() return # Kill all identical running containers cont = AimContainer(repo_inst) if cont.get_container() is not None: click.echo('Shutting down Aim UI at `{}`'.format(repo_inst.path)) cont.kill() click.echo('Done') else: click.echo('No running Aim UI at `{}`'.format(repo_inst.path))
def up(repo_inst, dev, host, port, version, repo, tf_logs, detach): check_docker_dependency() repo_path = clean_repo_path(repo) if repo_path: repo_inst = AimRepo(repo_path) if repo_inst is None or not repo_inst.exists(): repo_init_alert() return # Dev param # 0 => pull and run official image of container # 1 => run production build from local environment # 2 => run in development mode cont = AimContainer(repo_inst, dev=bool(dev)) if tf_logs: cont.mount_volume(tf_logs, AIM_TF_LOGS_PATH) if os.getenv(AIM_CONTAINER_TELEMETRY_FLAG) is not None \ and os.getenv(AIM_CONTAINER_TELEMETRY_FLAG) == '0': cont.turn_telemetry_off() else: cont.turn_telemetry_on() alert_msg = 'Aim UI collects anonymous usage analytics.' opt_out_msg = 'Read how to opt-out here: ' opt_out_url = 'https://github.com/aimhubio/aim#anonymized-telemetry' line_width = max(len(opt_out_msg), len(alert_msg)) + 16 click.echo('┌{}┐'.format('-' * (line_width - 2))) click.echo('{}{}{}'.format(' ' * ((line_width - len(alert_msg)) // 2), alert_msg, ' ' * ((line_width - len(alert_msg)) // 2))) click.echo('{}{}{}'.format( ' ' * ((line_width - len(opt_out_msg)) // 2), opt_out_msg, ' ' * ((line_width - len(opt_out_msg)) // 2))) click.echo('{}{}{}'.format( ' ' * ((line_width - len(opt_out_url)) // 2), opt_out_url, ' ' * ((line_width - len(opt_out_url)) // 2))) click.echo('└{}┘'.format('-' * (line_width - 2))) click.echo( click.style('Running Aim UI on repo `{}`'.format(repo_inst), fg='yellow')) # Check if image exist if dev == 0 and not cont.image_exist(version): click.echo('Pulling Aim UI docker image, please wait...') if not cont.pull(version): docker_image_pull_fail_alert() return else: click.echo('Successfully pulled Aim UI image') if cont.get_container(running_only=True): kill = click.confirm('Aim UI is already running. ' + 'Do you want to restart it?') if not kill: return # Kill all identical running containers cont.kill() # if dev < 2 # cont.bind(port + 1, AIM_CONTAINER_CMD_PORT) cont_id = cont.up(port, host, version) if not cont_id: click.echo('Failed to run Aim UI. Please try again.') return # cont_cmd = AimContainerCommandManager((port + 1) if dev < 2 # else AIM_CONTAINER_CMD_PORT) # cont_cmd.listen() # Kill container after keyboard interruption def graceful_shutdown(): # cont_cmd.kill() click.echo('') click.echo('Shutting down...') try: cont.kill() except Exception: pass click.echo('Done') sys.exit(0) # Add keyboard signal interruption listener # signal.signal(signal.SIGINT, graceful_shutdown) # signal.pause() try: sleep(4) click.echo('Open http://{}:{}'.format(host, port)) if not detach: click.echo('Press Ctrl+C to exit') while True: if cont.get_container() is not None: sleep(0.3) else: click.echo('Exited') return except KeyboardInterrupt: graceful_shutdown() sys.exit(0)
def up(repo_inst, dev, host, port, version, repo, tf_logs, detach): check_docker_dependency() repo_path = clean_repo_path(repo) if repo_path: repo_inst = AimRepo(repo_path) if repo_inst is None or not repo_inst.exists(): repo_init_alert() return # Dev param # 0 => pull and run official image of container # 1 => run production build from local environment # 2 => run in development mode cont = AimContainer(repo_inst, dev=bool(dev)) if tf_logs: cont.mount_volume(tf_logs, AIM_TF_LOGS_PATH) click.echo( click.style('Running Aim UI on repo `{}`'.format(repo_inst), fg='yellow')) # Check if image exist if dev == 0 and not cont.image_exist(version): click.echo('Pulling Aim UI docker image, please wait...') if not cont.pull(version): docker_image_pull_fail_alert() return else: click.echo('Successfully pulled Aim UI image') if cont.get_container(running_only=True): kill = click.confirm('Aim UI is already running. ' + 'Do you want to restart it?') if not kill: return # Kill all identical running containers cont.kill() # if dev < 2 # cont.bind(port + 1, AIM_CONTAINER_CMD_PORT) cont_id = cont.up(port, host, version) if not cont_id: click.echo('Failed to run Aim UI. Please try again.') return # cont_cmd = AimContainerCommandManager((port + 1) if dev < 2 # else AIM_CONTAINER_CMD_PORT) # cont_cmd.listen() # Kill container after keyboard interruption def graceful_shutdown(): # cont_cmd.kill() click.echo('') click.echo('Shutting down...') try: cont.kill() except Exception: pass click.echo('Done') sys.exit(0) # Add keyboard signal interruption listener # signal.signal(signal.SIGINT, graceful_shutdown) # signal.pause() try: sleep(4) click.echo('Open http://{}:{}'.format(host, port)) if not detach: click.echo('Press Ctrl+C to exit') while True: if cont.get_container() is not None: sleep(0.3) else: click.echo('Exited') return except KeyboardInterrupt: graceful_shutdown() sys.exit(0)