ix = z.find(' $#src_path#$codelet.data') if ix > 0: z = z.replace(' $#src_path#$codelet.data', ' \"$#src_path#$codelet.data\"') y['run_cmd_main'] = z dt = x.get('dataset_tags', []) dcu = x.get('dataset_classes_uoa', []) if len(dcu) > 0: for k in dcu: if k not in dtags: ck.out('') ra = ck.inp({'text': 'Enter dataset tag for ' + k + ': '}) kk = ra['string'].strip().lower() dtags[k] = kk kk = dtags[k] if kk not in dt: dt.append(kk) del (x['dataset_classes_uoa']) dt.append('dataset') x['dataset_tags'] = list(set(dt)) if 'codelet' in tags: del (x['dataset_tags']) r = ck.access({ 'action': 'update',
def setup(i): """ Input: { } Output: { return [int] - return code = 0 if success or >0 if error (error) [str] - error string if return>0 } """ # Get current configuration cfg={} ii={'action':'load', 'repo_uoa':config.CK_CFG_REPO_UOA, 'module_uoa':config.CK_CFG_MODULE_UID, 'data_uoa':config.CK_CFG_DATA_UOA} r=ck.access(ii) if (r['return']>0 and r['return']!=16): ck.err(r) if r['return']==0: cfg=r['dict'] # Check commands # Username ########################################################## username=cfg.get('username','') if i.get('username')!=None: username=i['username'] if username=='' or username==None: r=ck.inp({'text':'Enter cK username: '******'return']>0: ck.err(r) username=r['string'].strip() if username==None: username='' cfg['username']=username # API key ########################################################### api_key=cfg.get('api_key','') if i.get('api_key')!=None: api_key=i['api_key'] if api_key=='' or api_key==None: r=ck.inp({'text':'Enter your cK API key: '}) if r['return']>0: ck.err(r) api_key=r['string'].strip() if api_key==None: api_key='' cfg['api_key']=api_key # Server URL ########################################################### server_url=cfg.get('server_url','') if i.get('server_url')!=None and i.get('server_url')!='': server_url=i['server_url'] if server_url==None or server_url=='': server_url=config.CR_DEFAULT_SERVER_URL cfg['server_url']=server_url # Server User ########################################################### server_user=cfg.get('server_user','') if i.get('server_user')!=None and i.get('server_user')!='': server_user=i['server_user'] if server_user!=None and server_user!='': cfg['server_user']=server_user # Server Pass ########################################################### server_pass=cfg.get('server_pass','') if i.get('server_pass')!=None and i.get('server_pass')!='': server_pass=i['server_pass'] if server_pass!=None and server_pass!='': cfg['server_pass']=server_pass # Server Skip Certificate Validation ########################################################### server_skip_validation=cfg.get('server_skip_validation','') if i.get('server_skip_validation')!=None and i.get('server_skip_validation')!='': server_skip_validation=i['server_skip_validation'] if server_skip_validation=='yes': cfg['server_skip_validation']=server_skip_validation # Save configuration r=ck.access({'action':'update', 'repo_uyoa':config.CK_CFG_REPO_UOA, 'module_uoa':config.CK_CFG_MODULE_UID, 'data_uoa':config.CK_CFG_DATA_UOA, 'dict':cfg, 'sort_keys':'yes'}) if r['return']>0: ck.err(r) # Print (new/updated) configuration ck.out('') ck.out('Current cBench configuration:') ck.out('') ck.out(json.dumps(cfg, indent=2, sort_keys=True)) return 0
def publish(i): """ Input: { cid [str] - CK CID of format (repo UOA:)module UOA:data UOA (can use wildcards) (tags) [str] - search multiple CK components by these tags separated by comma (version) [str] - assign version } Output: { return [int] - return code = 0 if success or >0 if error (error) [str] - error string if return>0 } """ # Get current directory (since will be changing it to get info about Git repo) cur_dir = os.getcwd() # Get current configuration r = config.load({}) if r['return'] > 0: return r cfg = r['dict'] # Check commands # Username ########################################################## username = cfg.get('username', '') if i.get('username') != None: username = i['username'] if username == '' or username == None: return {'return': 1, 'error': 'Username is not defined'} cfg['username'] = username # API key ########################################################### api_key = cfg.get('api_key', '') if i.get('api_key') != None: api_key = i['api_key'] if api_key == '' or api_key == None: return {'return': 1, 'error': 'API key is not defined'} cfg['api_key'] = api_key # CID ########################################################### cid = i.get('cid') if cid == '' or cid == None: return {'return': 1, 'error': 'CK entry (CID) is not defined'} tags = i.get('tags', '') # Check if no module and use "cr-solution" by default if cid.find(':') < 0: cid = 'cr-solution:' + cid # Version ########################################################### version = i.get('version') if version == '' or version == None: return {'return': 1, 'error': 'Version is not defined'} # Extra info about authors author = i.get('author', '') if author == None: author = '' author_codereef_id = i.get('author_codereef_id', '') if author_codereef_id == None: author_codereef_id = '' copyright = i.get('copyright', '') if copyright == None: copyright = '' license = i.get('license', '') if license == None: license = '' source = i.get('source', '') if source == None: source = '' quiet = i.get('quiet', False) force = i.get('force', False) # List CK components r = ck.access({ 'action': 'search', 'cid': cid, 'tags': tags, 'add_info': 'yes', 'add_meta': 'yes', 'common_func': 'yes' }) if r['return'] > 0: return r lst = r['lst'] llst = len(lst) if llst == 0: ck.out('No CK objects found') num = 0 # Sort lst by modules and then data lst1 = sorted(lst, key=lambda x: (x.get('repo_uoa', ''), x.get( 'module_uoa', ''), x.get('data_uoa', ''))) for obj in lst1: num += 1 # Basic info about CK object repo_uoa = obj['repo_uoa'] repo_uid = obj['repo_uid'] module_uoa = obj['module_uoa'] module_uid = obj['module_uid'] data_uoa = obj['data_uoa'] data_uid = obj['data_uid'] # Print info ck.out( str(num) + ' out of ' + str(llst) + ') ' + repo_uoa + ':' + module_uoa + ':' + data_uoa) # Check name and date data_name = obj.get('info', {}).get('data_name', '') if data_name == data_uoa: data_name = '' data_meta = obj['meta'] if data_name == '': if data_meta.get('misc', {}).get('title', '') != '': data_name = data_meta['misc']['title'] data_date = '' if data_meta.get('misc', {}).get('date', '') != '': data_date = data_meta['misc']['date'] source2 = data_meta.get('source', '') if source2 == '': source2 = source license2 = data_meta.get('license', '') if license2 == '': license2 = license copyright2 = data_meta.get('copyright', '') if copyright2 == '': copyright2 = copyright # Specialize per specific modules not_digital_component = False extra_dict = {} extra_tags = {} if module_uoa == 'module': extra_dict['last_module_actions'] = [] actions = data_meta.get('actions', {}) for a in actions: extra_dict['last_module_actions'].append(a + ' ' + data_uoa) elif module_uoa == 'cr-lib': not_digital_component = True extra_tags = ['codereef-library'] if 'reproduced-papers' in data_meta.get('tags', []): extra_tags.append('reproduced-papers') data_meta2 = data_meta.get('meta', {}) if data_name == '': data_name = data_meta2.get('title', '') all_authors = data_meta2.get('authors', '') if all_authors != '': extra_dict['all_authors'] = [] for aa in all_authors.split(','): if aa != '': aa = aa.strip() if aa != '': extra_dict['all_authors'].append(aa) for k in [ 'badge_acm_artifact_available', 'badge_acm_artifact_functional', 'badge_acm_artifact_reusable', 'badge_acm_results_replicated', 'badge_acm_results_reproduced' ]: if data_meta2.get(k, '') == 'yes': extra_tags.append(k) elif module_uoa == 'cr-event' or module_uoa == 'repo': not_digital_component = True # Get info of the first creation first_creation = obj['info'].get('control', {}) # Load info about repo repo_dict = {} if not force and repo_uoa == 'local' and module_uoa != 'repo': # Normally skip everything from local unless we publish repos themselves ck.out(' SKIPPED') continue if module_uoa == 'repo': if not force and data_uoa == 'local': ck.out(' SKIPPED') continue repo_dict = obj['meta'] elif repo_uoa != 'default' and repo_uoa != 'local': r = ck.access({ 'action': 'load', 'repo_uoa': config.CK_CFG_REPO_UOA, 'module_uoa': config.CK_CFG_MODULE_REPO_UOA, 'data_uoa': repo_uid, 'common_func': 'yes' }) if r['return'] > 0: return r repo_dict = r['dict'] if 'path' in repo_dict: del (repo_dict['path']) # Generate temp file to pack r = ck.gen_tmp_file({'prefix': 'cr-obj-', 'suffix': '.zip'}) if r['return'] > 0: return r fn = r['file_name'] # Pack component p = obj['path'] zip_method = zipfile.ZIP_DEFLATED ii = {'path': p, 'all': 'yes'} # Prune files for cr-solution if module_uoa == 'cr-solution': ii['ignore_names'] = ['CK', 'venv'] r = ck.list_all_files(ii) if r['return'] > 0: return r fl = r['list'] # Write archive try: f = open(fn, 'wb') z = zipfile.ZipFile(f, 'w', zip_method) for fx in fl: add = True for k in skip_words_in_files: if k in fx: add = False break if add: p1 = os.path.join(p, fx) z.write(p1, fx, zip_method) z.close() f.close() except Exception as e: return { 'return': 1, 'error': 'failed to prepare archive (' + format(e) + ')' } # Check size statinfo = os.stat(fn) pack_size = statinfo.st_size # Check problems with repository or components x = '' if repo_dict.get('remote', '') == 'yes': x += 'remote repo;' if repo_dict.get('private', '') == 'yes': x += 'private repo;' if repo_dict.get('url', '') == '' and repo_uoa != 'default': x += 'repo not shared;' if pack_size > config.PACK_SIZE_WARNING: x += 'pack size (' + str(pack_size) + ') > ' + str( config.PACK_SIZE_WARNING) + ';' skip_component = False if not force and x != '': if quiet: skip_component = True else: r = ck.inp({ 'text': ' This component has potential issues (' + x + '). Skip processing (Y/n)? ' }) if r['return'] > 0: return r s = r['string'].strip() if s == '' or s == 'Y' or s == 'y': skip_component = True if skip_component: ck.out(' SKIPPED (' + x + ')') if os.path.isfile(fn): os.remove(fn) continue # Convert to MIME to send over internet r = ck.convert_file_to_upload_string({'filename': fn}) if r['return'] > 0: return r pack64 = r['file_content_base64'] if os.path.isfile(fn): os.remove(fn) # Check workspaces lworkspaces = [] workspaces = i.get('workspaces', '') if workspaces != None: lworkspaces = workspaces.strip().split(',') # Get extra info about repo os.chdir(p) repo_info = { 'publish_repo_uoa': repo_uoa, 'publish_repo_uid': repo_uid } # Get current Git URL r = ck.run_and_get_stdout( {'cmd': ['git', 'config', '--get', 'remote.origin.url']}) if r['return'] == 0 and r['return_code'] == 0: x = r['stdout'].strip() if x != '': repo_info['remote_git_url'] = x # Get current Git branch r = ck.run_and_get_stdout( {'cmd': ['git', 'rev-parse', '--abbrev-ref', 'HEAD']}) if r['return'] == 0 and r['return_code'] == 0: x = r['stdout'].strip() if x != '': repo_info['remote_git_branch'] = x # Get current Git checkout r = ck.run_and_get_stdout( {'cmd': ['git', 'rev-parse', '--short', 'HEAD']}) if r['return'] == 0 and r['return_code'] == 0: x = r['stdout'].strip() if x != '': repo_info['remote_git_checkout'] = x repo_info['dict'] = repo_dict #TBD: owner, version, info about repo # Sending request r = comm.send({ 'config': cfg, 'action': 'publish', 'ownership': { 'private': i.get('private', False), 'workspaces': lworkspaces }, 'dict': { 'publish_module_uoa': module_uoa, 'publish_module_uid': module_uid, 'publish_data_uoa': data_uoa, 'publish_data_uid': data_uid, 'publish_data_name': data_name, 'publish_data_date': data_date, 'publish_pack': pack64, 'publish_pack_size': pack_size, 'repo_info': repo_info, 'first_creation': first_creation, 'version': version, 'author': author, 'author_codereef_id': author_codereef_id, 'copyright': copyright2, 'license': license2, 'source': source2, 'not_digital_component': not_digital_component, 'extra_dict': extra_dict, 'extra_tags': extra_tags, } }) if r['return'] > 0: ck.out(' WARNING: CodeReef API returned error: ' + r['error']) else: data_uid = r['data_uid'] ck.out(' CodeReef component ID: ' + data_uid) os.chdir(cur_dir) return {'return': 0}
def init(i): """ Input: { uid [str] - graph identifyer (version) [str] - graph version (desc_file) [str] - file with graph description (tags) [str] - tags separated by comma } Output: { return [int] - return code = 0 if success or >0 if error (error) [str] - error string if return>0 dict [dict] - configuration dictionary path [str] - path to CK cfg entry } """ # Get main configuration r=config.load({}) if r['return']>0: return r cfg=r.get('dict',{}) pcfg=r.get('path','') # CID ########################################################### uid=i['uid'] if uid==None: uid='' version=i.get('version') if version==None: version='' desc_file=i.get('desc_file','') if desc_file==None: desc_file='' # If UID!='', check if already exists ... found=False meta=meta_template path='' data_name='' tags=[] meta_info='' source='' extra_info={} if uid!='': r=ck.access({'action':'load', 'module_uoa':'result', 'data_uoa':uid}) if r['return']>0: if r['return']!=16: return r else: found=True meta=r['dict'] path=r['path'] data_name=r['data_name'] tags=meta.get('tags',[]) source=meta.get('source','') meta_info=meta.get('meta',{}).get('info','') extra_info=r['info'].get('control',{}) # Check if init from scratch and no title if i.get('name')!=None and i.get('name','')!='': data_name=i['name'].strip() elif not found or data_name=='': r=ck.inp({'text':'Select a title for your graph: '}) if r['return']>0: return r data_name=r['string'].strip() meta['meta']['title']=data_name # Check if init from scratch and no title if not found or meta_info=='': r=ck.inp({'text':'Enter general info about your graph: '}) if r['return']>0: return r x=r['string'].strip() if x=='': x=' ' meta['meta']['info']=x # Adding tags if i.get('tags')!=None and i.get('tags','')!='': xtags=i['tags'].strip().split(',') for t in xtags: t1=t.strip() if t1!='' and t1 not in tags: tags.append(t1) meta['tags']=tags elif not found or (len(tags)==1 and 'result' in tags): r=ck.inp({'text':'Enter tags for your graph separated by commas: '}) if r['return']>0: return r xtags=r['string'].strip().split(',') for t in xtags: t1=t.strip() if t1!='' and t1 not in tags: tags.append(t1) meta['tags']=tags # Checking source if not found or source=='': r=ck.inp({'text':'Enter source of results for your graph (can be URL): '}) if r['return']>0: return r source=r['string'].strip() meta['source']=source # Checking authors for x in extra_info_desc: k=x['key'] n=x['name'] if not found or extra_info.get(k,'')=='': r=ck.inp({'text':'Enter '+n+': '}) if r['return']>0: return r s=r['string'].strip() extra_info[k]=s # Creating/updating graph a='add' if found: a='update' ii={'action':a, 'module_uoa':'result', 'data_uoa':uid, 'dict':meta, 'sort_keys':'yes', 'data_name':data_name, 'substitute':'yes', 'extra_info':extra_info} r=ck.access(ii) if r['return']>0: return r data_uoa=r['data_uoa'] data_uid=r['data_uid'] path=r['path'] x='initialized' if found: x='updated' ck.out('Graph was successfully '+x+':') ck.out('') ck.out(' CK UID: '+data_uid) ck.out(' CK name: '+data_uoa) ck.out(' CK path: '+path) # Add desc p1=os.path.join(path, 'desc.json') dt=copy.deepcopy(desc_template) if desc_file!='': rx=ck.load_json_file({'json_file':desc_file}) if rx['return']>0: return rx dx=rx['dict'] dt['data_config'].update(dx) if desc_file!='' or not os.path.isfile(p1): rx=ck.save_json_to_file({'json_file':p1, 'dict':dt, 'sort_keys':'yes'}) if rx['return']>0: return rx p2=os.path.join(path, '.cm', 'meta.json') ck.out('') ck.out('You can continue updating graph using following files: ') ck.out('') ck.out(' Graph general meta info: '+p1) ck.out(' See example at '+config.CR_DEFAULT_SERVER+'/result/sota-mlperf-inference-results-v0.5-open-available/?action=download&filename=.cm/meta.json') ck.out('') ck.out(' Graph axes info: '+p2) ck.out(' See example at '+config.CR_DEFAULT_SERVER+'/result/sota-mlperf-inference-results-v0.5-open-available/?action=download&filename=desc.json') # Need to publish ck.out('') rx=ck.inp({'text':'Publish graph on the portal (Y/n)?'}) if rx['return']>0: return rx s=rx['string'].strip().lower() if s=='' or s=='y': ck.out('') r=obj.publish({'cid':'result:'+data_uoa, 'version':version, 'force':True}) else: ck.out('') ck.out('You can publish your graph on the portal using the following commands when ready: ') ck.out('') ck.out(' cb publish result:'+data_uoa+' --version=1.0.0 --force (--private)') return r