code
string
signature
string
docstring
string
loss_without_docstring
float64
loss_with_docstring
float64
factor
float64
# Prevent duplication of "AppError" in places that print "AppError" # and then this formatted string if isinstance(e, dxpy.AppError): return _safe_unicode(e) if USING_PYTHON2: return unicode(e.__class__.__name__, 'utf-8') + ": " + _safe_unicode(e) else: return e.__class_...
def _format_exception_message(e)
Formats the specified exception.
5.372414
5.359707
1.002371
global RUN_COUNT RUN_COUNT += 1 dx_working_dir = os.getcwd() if dxpy.JOB_ID is not None: logging.basicConfig() try: logging.getLogger().addHandler(dxpy.DXLogHandler()) except dxpy.exceptions.DXError: print("TODO: FIXME: the EE client should die if...
def run(function_name=None, function_input=None)
Triggers the execution environment entry point processor. Use this function in the program entry point code: .. code-block:: python import dxpy @dxpy.entry_point('main') def hello(i): pass dxpy.run() This method may be used to invoke the program either in a produ...
3.551889
3.414732
1.040166
def wrap(f): ENTRY_POINT_TABLE[entry_point_name] = f @wraps(f) def wrapped_f(*args, **kwargs): return f(*args, **kwargs) return wrapped_f return wrap
def entry_point(entry_point_name)
Use this to decorate a DNAnexus execution environment entry point. Example: .. code-block:: python @dxpy.entry_point('main') def hello(i): pass
2.369514
3.251192
0.728814
''' :param path: a path or ID to a workflow object :type path: string :returns: tuple of (workflow ID, project ID) Returns the workflow and project IDs from the given path if available; otherwise, exits with an appropriate error message. ''' project, _folderpath, entity_result = try_cal...
def get_workflow_id_and_project(path)
:param path: a path or ID to a workflow object :type path: string :returns: tuple of (workflow ID, project ID) Returns the workflow and project IDs from the given path if available; otherwise, exits with an appropriate error message.
6.620606
3.866107
1.712473
authserver = get_auth_server_name(authserver_host, authserver_port) return DXHTTPRequest(authserver + "/system/getUserInfo", {}, prepend_srv=False)
def user_info(authserver_host=None, authserver_port=None)
Returns the result of the user_info call against the specified auth server. .. deprecated:: 0.108.0 Use :func:`whoami` instead where possible.
7.835588
10.447039
0.75003
''' :param job_homedir: explicit value for home directory, used for testing purposes :rtype: string :returns: path to input directory Returns the input directory, where all inputs are downloaded ''' if job_homedir is not None: home_dir = job_homedir else: home_dir = envi...
def get_input_dir(job_homedir=None)
:param job_homedir: explicit value for home directory, used for testing purposes :rtype: string :returns: path to input directory Returns the input directory, where all inputs are downloaded
3.903677
2.034384
1.91885
''' :param job_homedir: explicit value for home directory, used for testing purposes :rtype: string :returns: path to output directory Returns the output directory, where all outputs are created, and uploaded from ''' if job_homedir is not None: home_dir = job_homedir else: ...
def get_output_dir(job_homedir=None)
:param job_homedir: explicit value for home directory, used for testing purposes :rtype: string :returns: path to output directory Returns the output directory, where all outputs are created, and uploaded from
4.331969
1.963668
2.20606
path = get_output_json_file() try: os.remove(path) except OSError as e: if e.errno == errno.ENOENT: pass else: raise
def rm_output_json_file()
Warning: this is not for casual use. It erases the output json file, and should be used for testing purposes only.
2.327709
2.226411
1.045499
if not os.path.exists(path): # path does not exist, create the directory os.mkdir(path) else: # The path exists, check that it is not a file if os.path.isfile(path): raise Exception("Path %s already exists, and it is a file, not a directory" % path)
def ensure_dir(path)
:param path: path to directory to be created Create a directory if it does not already exist.
2.789753
2.873112
0.970987
# sanity check for filenames bad_filenames = [".", ".."] if fname in bad_filenames: raise DXError("Invalid filename {}".format(fname)) return fname.replace('/', '%2F')
def make_unix_filename(fname)
:param fname: the basename of a file (e.g., xxx in /zzz/yyy/xxx). :returns: a valid unix filename :rtype: string :raises: DXError if the filename is invalid on a Unix system The problem being solved here is that *fname* is a python string, it may contain characters that are invalid for a file name....
6.133373
4.530398
1.353826
def get_input_hash(): with open(job_input_file) as fh: job_input = json.load(fh) return job_input job_input = get_input_hash() files = collections.defaultdict(list) # dictionary, with empty lists as default elements dirs = [] # directories to create under <idir> ...
def get_job_input_filenames(job_input_file)
Extract list of files, returns a set of directories to create, and a set of files, with sources and destinations. The paths created are relative to the input directory. Note: we go through file names inside arrays, and create a separate subdirectory for each. This avoids clobbering files when dupli...
4.519178
4.47313
1.010294
''' Extract the inputSpec patterns, if they exist -- modifed from dx-upload-all-outputs Returns a dict of all patterns, with keys equal to the respective input parameter names. ''' input_spec = None if 'DX_JOB_ID' in environ: # works in the cloud, not locally job_desc = dxpy.des...
def get_input_spec_patterns()
Extract the inputSpec patterns, if they exist -- modifed from dx-upload-all-outputs Returns a dict of all patterns, with keys equal to the respective input parameter names.
4.737505
3.43455
1.379367
file_key_descs, rest_hash = analyze_bash_vars(job_input_file, job_homedir) def string_of_elem(elem): result = None if isinstance(elem, basestring): result = elem elif isinstance(elem, dxpy.DXFile): result = json.dumps(dxpy.dxlink(elem)) else: ...
def gen_bash_vars(job_input_file, job_homedir=None, check_name_collision=True)
:param job_input_file: path to a JSON file describing the job inputs :param job_homedir: path to home directory, used for testing purposes :param check_name_collision: should we check for name collisions? :return: list of lines :rtype: list of strings Calculates a line for each shell variable to in...
3.199697
3.27967
0.975615
while True: try: future = next(concurrent.futures.as_completed(futures, timeout=THREAD_TIMEOUT_MAX)) break except concurrent.futures.TimeoutError: pass except KeyboardInterrupt: if print_traceback: traceback.print_stack() ...
def wait_for_a_future(futures, print_traceback=False)
Return the next future that completes. If a KeyboardInterrupt is received, then the entire process is exited immediately. See wait_for_all_futures for more notes.
3.325901
3.062651
1.085955
try: while True: waited_futures = concurrent.futures.wait(futures, timeout=60) if len(waited_futures.not_done) == 0: break except KeyboardInterrupt: if print_traceback: traceback.print_stack() else: print('') os...
def wait_for_all_futures(futures, print_traceback=False)
Wait indefinitely for all futures in the input iterable to complete. Use a timeout to enable interrupt handling. Call os._exit() in case of KeyboardInterrupt. Otherwise, the atexit registered handler in concurrent.futures.thread will run, and issue blocking join() on all worker threads, requiring us to list...
2.84518
2.726153
1.043661
tasks_in_progress = collections.deque() if max_active_tasks is None: max_active_tasks = cpu_count() # The following two functions facilitate GC by not adding extra variables to the enclosing scope. def submit_task(task_iterator, executor, futures_queue): retval = next(task_iterato...
def response_iterator(request_iterator, thread_pool, max_active_tasks=None, do_first_task_sequentially=True)
:param request_iterator: An iterator producing inputs for consumption by the worker pool. :type request_iterator: iterator of callable, args, kwargs :param thread_pool: thread pool to submit the requests to :type thread_pool: concurrent.futures.thread.ThreadPoolExecutor :param max_active_tasks: ...
2.577589
2.579559
0.999236
error_msg = 'Error: Expected an int timestamp, a date format (e.g. YYYY-MM-DD), or an int with a single-letter suffix (s=seconds, m=minutes, h=hours, d=days, w=weeks, M=months, y=years; e.g. "-10d" indicates 10 days ago); but got {t}' if isinstance(t, basestring) and t.isdigit(): t = int(t) if...
def normalize_time_input(t, future=False, default_unit='ms')
:param default_unit: units of the input time *t*; must be one of "s" or "ms". This param is only respected if *t* looks like an int (e.g. "12345", 12345). :type default_unit: string Converts inputs such as: "2012-05-01" "-5d" 1352863174 "1352863174" to millisecon...
2.819301
2.680958
1.051602
try: return int(timedelta) * 1000 except ValueError as e: t, suffix = timedelta[:-1], timedelta[-1:] suffix_multipliers = {'s': 1000, 'm': 1000*60, 'h': 1000*60*60, 'd': 1000*60*60*24, 'w': 1000*60*60*24*7, 'M': 1000*60*60*24*30, 'y': 1000*60*60*24*365}...
def normalize_timedelta(timedelta)
Given a string like "1w" or "-5d", convert it to an integer in milliseconds. Integers without a suffix are interpreted as seconds. Note: not related to the datetime timedelta class.
1.779959
1.687229
1.05496
d = {} for k, v in ordered_pairs: if k in d: raise ValueError("duplicate key: %r" % (k,)) else: d[k] = v return d
def _dict_raise_on_duplicates(ordered_pairs)
Reject duplicate keys.
2.349304
2.193688
1.070938
''' Static method to return a copy of the input dictionary with an additional unique nonce :param input: an input dictionary that may be empty :type input: dict :returns an extended copy of the input with an additional nonce field The input dictionary is updated ...
def update_nonce(input_params)
Static method to return a copy of the input dictionary with an additional unique nonce :param input: an input dictionary that may be empty :type input: dict :returns an extended copy of the input with an additional nonce field The input dictionary is updated with a nonce only if...
6.165174
1.950893
3.16018
# Inline description from a readme file if 'description' not in json_spec: readme_filename = None for filename in 'README.md', 'Readme.md', 'readme.md': if os.path.exists(os.path.join(src_dir, filename)): readme_filename = filename break i...
def inline_documentation_files(json_spec, src_dir)
Modifies the provided json_spec dict (which may be an app, applet, workflow spec) to inline the contents of the readme file into "description" and the developer readme into "developerNotes".
1.878602
1.668696
1.125791
assert(prefixed_name.startswith('app-') or prefixed_name.startswith('globalworkflow-')) if prefixed_name.partition('-')[0] == 'app': exception_type = dxpy.app_builder.AppBuilderException describe_method = dxpy.api.app_describe exception_msg = \ 'An app with the given na...
def verify_developer_rights(prefixed_name)
Checks if the current user is a developer of the app or global workflow with the given name. If the app/global workflow exists and the user has developer rights to it, the function returns a named tuple representing the executable that was queried.
2.920305
2.674053
1.092089
if from_spec is None or from_command_line is None: return if set(from_spec) != set(from_command_line): raise builder_exception("--region and the 'regionalOptions' key in the JSON file do not agree")
def assert_consistent_regions(from_spec, from_command_line, builder_exception)
Verifies the regions passed with --region CLI argument and the ones specified in regionalOptions are the same (if both CLI and spec were used)
5.433126
3.936424
1.380219
reg_options_spec = json_spec.get('regionalOptions') json_fn = 'dxapp.json' if exec_type == 'app' else 'dxworkflow.json' if not isinstance(reg_options_spec, dict): raise executable_builder_exeception("The field 'regionalOptions' in must be a mapping") if not reg_options_spec: raise...
def assert_consistent_reg_options(exec_type, json_spec, executable_builder_exeception)
Validates the "regionalOptions" field and verifies all the regions used in "regionalOptions" have the same options.
2.298343
2.208712
1.040581
from_spec = json_spec.get('regionalOptions') if from_spec is not None: assert_consistent_reg_options(exec_type, json_spec, executable_builder_exeception) assert_consistent_regions(from_spec, from_command_line, executable_builder_exeception) enabled_regions = None if from_spec is not...
def get_enabled_regions(exec_type, json_spec, from_command_line, executable_builder_exeception)
Return a list of regions in which the global executable (app or global workflow) will be enabled, based on the "regionalOption" in their JSON specification and/or --region CLI argument used with "dx build". :param exec_type: 'app' or 'globalworkflow' :type json_spec: str. :param json_spec: The cont...
2.799703
2.742345
1.020916
describe_input = {} if fields is not None: describe_input['fields'] = fields self._desc = dxpy.api.analysis_describe(self._dxid, describe_input, **kwargs) return self._desc
def describe(self, fields=None, **kwargs)
:param fields: dict where the keys are field names that should be returned, and values should be set to True (by default, all fields are returned) :type fields: dict :returns: Description of the analysis :rtype: dict Returns a hash with key-value pairs containing...
4.047696
5.218455
0.77565
dxpy.api.analysis_add_tags(self._dxid, {"tags": tags}, **kwargs)
def add_tags(self, tags, **kwargs)
:param tags: Tags to add to the analysis :type tags: list of strings Adds each of the specified tags to the analysis. Takes no action for tags that are already listed for the analysis.
7.307796
5.738739
1.273415
dxpy.api.analysis_remove_tags(self._dxid, {"tags": tags}, **kwargs)
def remove_tags(self, tags, **kwargs)
:param tags: Tags to remove from the analysis :type tags: list of strings Removes each of the specified tags from the analysis. Takes no action for tags that the analysis does not currently have.
7.772914
6.090889
1.276154
dxpy.api.analysis_set_properties(self._dxid, {"properties": properties}, **kwargs)
def set_properties(self, properties, **kwargs)
:param properties: Property names and values given as key-value pairs of strings :type properties: dict Given key-value pairs in *properties* for property names and values, the properties are set on the analysis for the given property names. Any property with a value of :const:`None` ...
7.874678
8.254933
0.953936
''' :param field: Output field name of this analysis :type field: string :param index: If the referenced field is an array, optionally specify an index (starting from 0) to indicate a particular member of the array :type index: int :param metadata: If the referenced field...
def get_output_ref(self, field, index=None, metadata=None)
:param field: Output field name of this analysis :type field: string :param index: If the referenced field is an array, optionally specify an index (starting from 0) to indicate a particular member of the array :type index: int :param metadata: If the referenced field is of a data object...
4.659899
1.550601
3.00522
for input_field in app_json.get('inputSpec', []): for suggestion in input_field.get('suggestions', []): if 'project' in suggestion: try: project = dxpy.api.project_describe(suggestion['project'], {"permissions": True}) if 'PUBLIC' not ...
def _check_suggestions(app_json, publish=False)
Examines the specified dxapp.json file and warns about any violations of suggestions guidelines. :raises: AppBuilderException for data objects that could not be found
2.031843
1.994905
1.018517
# This function needs the language to be explicitly set, so we can # generate an appropriate temp filename. if lang == 'python2.7': temp_basename = 'inlined_code_from_dxapp_json.py' elif lang == 'bash': temp_basename = 'inlined_code_from_dxapp_json.sh' else: raise ValueE...
def _check_syntax(code, lang, temp_dir, enforce=True)
Checks that the code whose text is in CODE parses as LANG. Raises DXSyntaxError if there is a problem and "enforce" is True.
3.605463
3.558195
1.013284
def check_python(filename): # Generate a semi-recognizable name to write the pyc to. Of # course it's possible that different files being scanned could # have the same basename, so this path won't be unique, but the # checks don't run concurrently so this shouldn't cause any ...
def _check_file_syntax(filename, temp_dir, override_lang=None, enforce=True)
Checks that the code in FILENAME parses, attempting to autodetect the language if necessary. Raises IOError if the file cannot be read. Raises DXSyntaxError if there is a problem and "enforce" is True.
3.343191
3.266884
1.023358
temp_dir = tempfile.mkdtemp(prefix='dx-build_tmp') try: _verify_app_source_dir_impl(src_dir, temp_dir, mode, enforce=enforce) finally: shutil.rmtree(temp_dir)
def _verify_app_source_dir(src_dir, mode, enforce=True)
Performs syntax and lint checks on the app source. Precondition: the dxapp.json file exists and can be parsed.
3.117031
3.131088
0.99551
if not os.path.isdir(src_dir): parser.error("%s is not a directory" % src_dir) if not os.path.exists(os.path.join(src_dir, "dxapp.json")): raise dxpy.app_builder.AppBuilderException("Directory %s does not contain dxapp.json: not a valid DNAnexus app source directory" % src_dir) with ope...
def _parse_app_spec(src_dir)
Returns the parsed contents of dxapp.json. Raises either AppBuilderException or a parser error (exit codes 3 or 2 respectively) if this cannot be done.
2.49126
2.255058
1.104744
if len(sys.argv) > 0: if sys.argv[0].endswith('dx-build-app'): logging.warn('Warning: dx-build-app has been replaced with "dx build --create-app". Please update your scripts.') elif sys.argv[0].endswith('dx-build-applet'): logging.warn('Warning: dx-build-applet has been...
def main(**kwargs)
Entry point for dx-build-app(let). Don't call this function as a subroutine in your program! It is liable to sys.exit your program when it detects certain error conditions, so you can't recover from those as you could if it raised exceptions. Instead, call dx_build_app.build_and_upload_locally which pr...
3.80626
3.354165
1.134786
''' :param dxid: App ID :type dxid: string :param name: App name :type name: string :param alias: App version or tag :type alias: string :raises: :exc:`~dxpy.exceptions.DXError` if *dxid* and some other input are both given or if neither *dxid* nor *name* ...
def set_id(self, dxid=None, name=None, alias=None)
:param dxid: App ID :type dxid: string :param name: App name :type name: string :param alias: App version or tag :type alias: string :raises: :exc:`~dxpy.exceptions.DXError` if *dxid* and some other input are both given or if neither *dxid* nor *name* are given D...
3.041626
1.585347
1.918587
''' :returns: Object ID of associated app :rtype: string Returns the object ID of the app that the handler is currently associated with. ''' if self._dxid is not None: return self._dxid else: return 'app-' + self._name + '/' + self...
def get_id(self)
:returns: Object ID of associated app :rtype: string Returns the object ID of the app that the handler is currently associated with.
8.78933
3.441399
2.553999
''' :param fields: Hash where the keys are field names that should be returned, and values should be set to True (default is that all fields are returned) :type fields: dict :returns: Description of the remote app object :rtype: dict Returns a dict with a description of ...
def describe(self, fields=None, **kwargs)
:param fields: Hash where the keys are field names that should be returned, and values should be set to True (default is that all fields are returned) :type fields: dict :returns: Description of the remote app object :rtype: dict Returns a dict with a description of the app. The result ...
4.013118
1.657451
2.421259
''' :param applet: ID of the applet to replace the app's contents with :type applet: string :param details: Metadata to store with the app (optional) :type details: dict or list :param access: Access specification (optional) :type access: dict :param resou...
def update(self, **kwargs)
:param applet: ID of the applet to replace the app's contents with :type applet: string :param details: Metadata to store with the app (optional) :type details: dict or list :param access: Access specification (optional) :type access: dict :param resources: Specifies what...
4.683519
1.637148
2.86078
if self._dxid is not None: return dxpy.api.app_add_tags(self._dxid, input_params={"tags": tags}, **kwargs) else: return dxpy.api.app_add_tags('app-' + self._name, alias=self._alias, input_params={"tags": tags}, **kwargs)
def add_tags(self, tags, **kwargs)
:param tags: Tags to add to the app :type tags: array Adds the specified application name tags (aliases) to this app. The current user must be a developer of the app.
3.787174
3.60871
1.049454
if self._dxid is not None: return dxpy.api.app_remove_tags(self._dxid, input_params={"tags": tags}, **kwargs) else: return dxpy.api.app_remove_tags('app-' + self._name, alias=self._alias, input_params={"tags": tags}, **kwargs)
def remove_tags(self, tags, **kwargs)
:param tags: Tags to remove from the app :type tags: array Removes the specified application name tags (aliases) from this app, so that it is no longer addressable by those aliases. The current user must be a developer of the app.
3.737496
3.512062
1.064188
if self._dxid is not None: return dxpy.api.app_install(self._dxid, **kwargs) else: return dxpy.api.app_install('app-' + self._name, alias=self._alias, **kwargs)
def install(self, **kwargs)
Installs the app in the current user's account.
4.270914
3.568181
1.196944
if self._dxid is not None: return dxpy.api.app_uninstall(self._dxid, **kwargs) else: return dxpy.api.app_uninstall('app-' + self._name, alias=self._alias, **kwargs)
def uninstall(self, **kwargs)
Uninstalls the app from the current user's account.
3.937091
3.532838
1.114427
if self._dxid is not None: return dxpy.api.app_get(self._dxid, **kwargs) else: return dxpy.api.app_get('app-' + self._name, alias=self._alias, **kwargs)
def get(self, **kwargs)
:returns: Full specification of the remote app object :rtype: dict Returns the contents of the app. The result includes the key-value pairs as specified in the API documentation for the `/app-xxxx/get <https://wiki.dnanexus.com/API-Specification-v1.0.0/Apps#API-method%253A-%252F...
4.841805
3.794583
1.275978
if self._dxid is not None: return dxpy.api.app_delete(self._dxid, **kwargs) else: return dxpy.api.app_delete('app-' + self._name, alias=self._alias, **kwargs)
def delete(self, **kwargs)
Removes this app object from the platform. The current user must be a developer of the app.
4.061911
3.651905
1.112272
# Rename app_input to preserve API compatibility when calling # DXApp.run(app_input=...). return super(DXApp, self).run(app_input, *args, **kwargs)
def run(self, app_input, *args, **kwargs)
Creates a new job that executes the function "main" of this app with the given input *app_input*. See :meth:`dxpy.bindings.dxapplet.DXExecutable.run` for the available args.
7.535227
7.486384
1.006524
if not os.path.isdir(src_dir): parser.error("{} is not a directory".format(src_dir)) if not os.path.exists(os.path.join(src_dir, json_file_name)): raise WorkflowBuilderException( "Directory {} does not contain dxworkflow.json: not a valid DNAnexus workflow source directory" ...
def _parse_executable_spec(src_dir, json_file_name, parser)
Returns the parsed contents of a json specification. Raises WorkflowBuilderException (exit code 3) if this cannot be done.
3.0929
2.80221
1.103736
if build_project_id: return build_project_id if 'project' in json_spec: return json_spec['project'] if dxpy.WORKSPACE_ID: return dxpy.WORKSPACE_ID error_msg = "Can't create a workflow without specifying a destination project; " error_msg += "please use the -d/--destinati...
def _get_destination_project(json_spec, args, build_project_id=None)
Returns destination project in which the workflow should be created. In can be set in multiple ways whose order of precedence is: 1. --destination, -d option supplied with `dx build`, 2. 'project' specified in the json file, 3. project set in the dxpy.WORKSPACE_ID environment variable.
3.350486
2.604517
1.286413
dest_folder = folder_name or json_spec.get('folder') or '/' if not dest_folder.endswith('/'): dest_folder = dest_folder + '/' return dest_folder
def _get_destination_folder(json_spec, folder_name=None)
Returns destination project in which the workflow should be created. It can be set in the json specification or by --destination option supplied with `dx build`. The order of precedence is: 1. --destination, -d option, 2. 'folder' specified in the json file.
2.747652
3.197948
0.859192
assert(isinstance(categories_to_set, list)) existing_categories = dxpy.api.global_workflow_list_categories(global_workflow_id)['categories'] categories_to_add = set(categories_to_set).difference(set(existing_categories)) categories_to_remove = set(existing_categories).difference(set(categories_to_...
def _set_categories_on_workflow(global_workflow_id, categories_to_set)
Note: Categories are set on the workflow series level, i.e. the same set applies to all versions.
1.7035
1.70477
0.999255
requested_name = json_spec['name'] requested_version = json_spec['version'] if requested_name == name and requested_version == version: return True else: try: desc_output = dxpy.api.global_workflow_describe('globalworkflow-' + json_spec['name'], ...
def _version_exists(json_spec, name=None, version=None)
Returns True if a global workflow with the given name and version already exists in the platform and the user has developer rights to the workflow. "name" and "version" can be passed if we already made a "describe" API call on the global workflow and so know the requested name and version already exists...
3.280507
2.913586
1.125935
if not isinstance(ignore_reuse_stages, list): raise WorkflowBuilderException('"IgnoreReuse must be a list of strings - stage IDs or "*"') ignore_reuse_set = set(ignore_reuse_stages) if '*' in ignore_reuse_set and ignore_reuse_set == 1: return stage_ids = set([stage.get('id') for ...
def validate_ignore_reuse(stages, ignore_reuse_stages)
Checks if each stage ID specified in ignore_reuse_stages exists in the workflow definition. If ignore_reuse_stages contains only '*', the field is valid.
4.718874
4.304155
1.096353
if not isinstance(stages, list): raise WorkflowBuilderException("Stages must be specified as a list of dictionaries") validated_stages = [] for index, stage in enumerate(stages): validated_stages.append(_get_validated_stage(stage, index)) return validated_stages
def _get_validated_stages(stages)
Validates stages of the workflow as a list of dictionaries.
2.72323
2.228382
1.222066
validated = {} override_project_id, override_folder, override_workflow_name = \ dxpy.executable_builder.get_parsed_destination(args.destination) validated['project'] = _get_destination_project(json_spec, args, override_project_id) validated['folder'] = _get_destination_folder(json_spec, ove...
def _validate_json_for_regular_workflow(json_spec, args)
Validates fields used only for building a regular, project-based workflow.
3.572081
3.519372
1.014977
# TODO: verify the billTo can build the workflow # TODO: if the global workflow build fails add an option to interactively change billto # TODO: (or other simple fields) instead of failing altogether # TODO: get a confirmation before building a workflow that may be costly if 'name' not in json_...
def _validate_json_for_global_workflow(json_spec, args)
Validates fields used for building a global workflow. Since building a global workflow is done after all the underlying workflows are built, which may be time-consuming, we validate as much as possible here.
3.260141
3.169051
1.028744
if not json_spec: return if not args: return validated_spec = copy.deepcopy(json_spec) # print ignored keys if present in json_spec unsupported_keys = _get_unsupported_keys(validated_spec.keys(), SUPPORTED_KEYS) if len(unsupported_keys) > 0: logger.warn( ...
def _get_validated_json(json_spec, args)
Validates dxworkflow.json and returns the json that can be sent with the /workflow/new API or /globalworkflow/new request.
3.637955
3.375006
1.077911
validated = copy.deepcopy(json_spec) dxpy.executable_builder.inline_documentation_files(validated, args.src_dir) if 'title' not in json_spec: logger.warn("dxworkflow.json is missing a title, please add one in the 'title' field") if 'summary' not in json_spec: logger.warn("dxworkf...
def _get_validated_json_for_build_or_update(json_spec, args)
Validates those fields that can be used when either building a new version (of a local, project-based workflow) or updating an existing version (of a global workflow).
4.268427
4.202961
1.015576
executables = [i.get("executable") for i in workflow_spec.get("stages")] for exect in executables: if exect.startswith("applet-") and len(workflow_enabled_regions) > 1: raise WorkflowBuilderException("Building a global workflow with applets in more than one region is not yet supported...
def _assert_executable_regions_match(workflow_enabled_regions, workflow_spec)
Check if the global workflow regions and the regions of stages (apps) match. If the workflow contains any applets, the workflow can be currently enabled in only one region - the region in which the applets are stored.
3.377924
3.167192
1.066536
workflow_id = dxpy.api.workflow_new(json_spec)["id"] dxpy.api.workflow_close(workflow_id) return workflow_id
def _build_regular_workflow(json_spec)
Precondition: json_spec must be validated
3.364978
3.453675
0.974318
enabled_regions = dxpy.executable_builder.get_enabled_regions('globalworkflow', json_spec, from_command_line, Wor...
def _get_validated_enabled_regions(json_spec, from_command_line)
Returns a set of regions (region names) in which the global workflow should be enabled. Also validates and synchronizes the regions passed via CLI argument and in the regionalOptions field.
4.306735
4.05547
1.061957
# Create one temp project in each region projects_by_region = {} # Project IDs by region for region in enabled_regions: try: project_input = {"name": "Temporary build project for dx build global workflow", "region": region} if args.bill_to: ...
def _create_temporary_projects(enabled_regions, args)
Creates a temporary project needed to build an underlying workflow for a global workflow. Returns a dictionary with region names as keys and project IDs as values The regions in which projects will be created can be: i. regions specified in dxworkflow.json "regionalOptions" ii. regions specified as...
3.836937
3.443338
1.114307
projects_by_region = _create_temporary_projects(enabled_regions, args) workflows_by_region = {} try: for region, project in projects_by_region.items(): json_spec['project'] = project workflow_id = _build_regular_workflow(json_spec) logger.debug("Created work...
def _build_underlying_workflows(enabled_regions, json_spec, args)
Creates a workflow in a temporary project for each enabled region. Returns a tuple of dictionaries: workflow IDs by region and project IDs by region. The caller is responsible for destroying the projects if this method returns properly.
3.240301
2.743394
1.181128
# First determine in which regions the global workflow needs to be available enabled_regions = _get_validated_enabled_regions(json_spec, args.region) # Verify all the stages are also enabled in these regions # TODO: Add support for dx building multi-region global workflows with applets _assert...
def _build_global_workflow(json_spec, args)
Creates a workflow in a temporary project for each enabled region and builds a global workflow on the platform based on these workflows.
3.98605
3.838373
1.038474
try: if args.mode == 'workflow': json_spec = _get_validated_json(json_spec, args) workflow_id = _build_regular_workflow(json_spec) elif args.mode == 'globalworkflow': # Verify if the global workflow already exists and if the user has developer rights to it ...
def _build_or_update_workflow(json_spec, args)
Creates or updates a workflow on the platform. Returns the workflow ID, or None if the workflow cannot be created.
3.991158
3.977825
1.003352
if args is None: raise Exception("arguments not provided") try: json_spec = _parse_executable_spec(args.src_dir, "dxworkflow.json", parser) workflow_id = _build_or_update_workflow(json_spec, args) _print_output(workflow_id, args) except WorkflowBuilderException as e: ...
def build(args, parser)
Validates workflow source directory and creates a new (global) workflow based on it. Raises: WorkflowBuilderException if the workflow cannot be created.
5.187651
4.703473
1.102941
''' Copy the source to a destination that does not currently exist. This involves creating the target file/folder. ''' # Destination folder path is new => renaming if len(args.sources) != 1: # Can't copy and rename more than one object raise DXCLIError('The destination folder does no...
def cp_to_noexistent_destination(args, dest_path, dx_dest, dest_proj)
Copy the source to a destination that does not currently exist. This involves creating the target file/folder.
3.692101
3.536364
1.044039
"Returns the file size in readable form." B = num_bytes KB = float(1024) MB = float(KB * 1024) GB = float(MB * 1024) TB = float(GB * 1024) if B < KB: return '{0} {1}'.format(B, 'bytes' if B != 1 else 'byte') elif KB <= B < MB: return '{0:.2f} KiB'.format(B/KB) elif M...
def _readable_part_size(num_bytes)
Returns the file size in readable form.
1.548415
1.501581
1.03119
if media_type is not None: dx_hash["media"] = media_type resp = dxpy.api.file_new(dx_hash, **kwargs) self.set_ids(resp["id"], dx_hash["project"])
def _new(self, dx_hash, media_type=None, **kwargs)
:param dx_hash: Standard hash populated in :func:`dxpy.bindings.DXDataObject.new()` containing attributes common to all data object classes. :type dx_hash: dict :param media_type: Internet Media Type :type media_type: string Creates a new remote file with media type *media_type*, if giv...
3.801313
3.95738
0.960563
''' :param dxid: Object ID :type dxid: string :param project: Project ID :type project: string Discards the currently stored ID and associates the handler with *dxid*. As a side effect, it also flushes the buffer for the previous file object if the buffer...
def set_ids(self, dxid, project=None)
:param dxid: Object ID :type dxid: string :param project: Project ID :type project: string Discards the currently stored ID and associates the handler with *dxid*. As a side effect, it also flushes the buffer for the previous file object if the buffer is nonempty.
5.627716
2.346346
2.398502
''' :param offset: Position in the file to seek to :type offset: integer Seeks to *offset* bytes from the beginning of the file. This is a no-op if the file is open for writing. The position is computed from adding *offset* to a reference point; the reference point is selected...
def seek(self, offset, from_what=os.SEEK_SET)
:param offset: Position in the file to seek to :type offset: integer Seeks to *offset* bytes from the beginning of the file. This is a no-op if the file is open for writing. The position is computed from adding *offset* to a reference point; the reference point is selected by the *fro...
4.540232
3.294499
1.378125
''' Flushes the internal write buffer. ''' if self._write_buf.tell() > 0: data = self._write_buf.getvalue() self._write_buf = BytesIO() if multithread: self._async_upload_part_request(data, index=self._cur_part, **kwargs) e...
def flush(self, multithread=True, **kwargs)
Flushes the internal write buffer.
3.035717
2.821778
1.075817
''' :param data: Data to be written :type data: str or mmap object :param multithread: If True, sends multiple write requests asynchronously :type multithread: boolean Writes the data *data* to the file. .. note:: Writing to remote files is append-o...
def _write2(self, data, multithread=True, **kwargs)
:param data: Data to be written :type data: str or mmap object :param multithread: If True, sends multiple write requests asynchronously :type multithread: boolean Writes the data *data* to the file. .. note:: Writing to remote files is append-only. Using :meth:`se...
5.092974
3.845751
1.324312
''' :param data: Data to be written :type data: str or mmap object :param multithread: If True, sends multiple write requests asynchronously :type multithread: boolean Writes the data *data* to the file. .. note:: Writing to remote files is append-o...
def write(self, data, multithread=True, **kwargs)
:param data: Data to be written :type data: str or mmap object :param multithread: If True, sends multiple write requests asynchronously :type multithread: boolean Writes the data *data* to the file. .. note:: Writing to remote files is append-only. Using :meth:`se...
5.28866
3.588709
1.473694
''' :param block: If True, this function blocks until the remote file has closed. :type block: boolean Attempts to close the file. .. note:: The remote file cannot be closed until all parts have been fully uploaded. An exception will be thrown if this is n...
def close(self, block=False, **kwargs)
:param block: If True, this function blocks until the remote file has closed. :type block: boolean Attempts to close the file. .. note:: The remote file cannot be closed until all parts have been fully uploaded. An exception will be thrown if this is not the case.
5.662802
4.007582
1.413022
if not USING_PYTHON2: # In python3, the underlying system methods use the 'bytes' type, not 'string' assert(isinstance(data, bytes)) req_input = {} if index is not None: req_input["index"] = int(index) md5 = hashlib.md5() if hasattr(...
def upload_part(self, data, index=None, display_progress=False, report_progress_fn=None, **kwargs)
:param data: Data to be uploaded in this part :type data: str or mmap object, bytes on python3 :param index: Index of part to be uploaded; must be in [1, 10000] :type index: integer :param display_progress: Whether to print "." to stderr when done :type display_progress: boolean ...
4.582256
4.470378
1.025027
cmd = ['dx', 'ssh', '--suppress-running-check', job_id, '-o', 'StrictHostKeyChecking no'] cmd += ['-f', '-L', '{0}:localhost:{1}'.format(local_port, remote_port), '-N'] subprocess.check_call(cmd)
def setup_ssh_tunnel(job_id, local_port, remote_port)
Setup an ssh tunnel to the given job-id. This will establish the port over the given local_port to the given remote_port and then exit, keeping the tunnel in place until the job is terminated.
4.571255
4.994894
0.915186
sys.stdout.write('Waiting for server in {0} to initialize ...'.format(job_id)) sys.stdout.flush() desc = dxpy.describe(job_id) # Keep checking until the server has begun or it has failed. while(SERVER_READY_TAG not in desc['tags'] and desc['state'] != 'failed'): time.sleep(SLEEP_PERIOD)...
def poll_for_server_running(job_id)
Poll for the job to start running and post the SERVER_READY_TAG.
4.254395
4.023041
1.057507
if platform == "linux" or platform == "linux2": cmd = ['xdg-open', cmd] elif platform == "darwin": cmd = ['open', cmd] elif platform == "win32": cmd = ['start', cmd] subprocess.check_call(cmd)
def multi_platform_open(cmd)
Take the given command and use the OS to automatically open the appropriate resource. For instance, if a URL is provided, this will have the OS automatically open the URL in the default web browser.
1.814966
2.018499
0.899166
notebook_apps = dxpy.find_apps(name=NOTEBOOK_APP, all_versions=True) versions = [str(dxpy.describe(app['id'])['version']) for app in notebook_apps] return versions
def get_notebook_app_versions()
Get the valid version numbers of the notebook app.
3.91452
3.667923
1.067231
# Check that ssh is setup. Currently notebooks require ssh for tunelling. ssh_config_check() if args.only_check_config: return # If the user requested a specific version of the notebook server, # get the executable id. if args.version is not None: executable = get_app_from...
def run_notebook(args, ssh_config_check)
Launch the notebook server.
4.979423
4.911057
1.013921
NWORDS = _train(known_words) candidates = _known([word], NWORDS) or _known(_edits1(word), NWORDS) or _known_edits2(word, NWORDS) or [word] return max(candidates, key=NWORDS.get)
def correct(word, known_words)
:param word: Word to correct :type word: string :param known_words: List of known words :type known_words: iterable of strings Given **word**, suggests a correction from **known_words**. If no reasonably close correction is found, returns **word**.
4.618794
4.985095
0.926521
params = job_config.input_reader_params shard_count = job_config.shard_count query_spec = cls._get_query_spec(params) if not property_range.should_shard_by_property_range(query_spec.filters): return super(ModelDatastoreInputReader, cls).split_input(job_config) p_range = property_range.P...
def split_input(cls, job_config)
Inherit docs.
3.353891
3.291516
1.01895
super(ModelDatastoreInputReader, cls).validate(job_config) params = job_config.input_reader_params entity_kind = params[cls.ENTITY_KIND_PARAM] # Fail fast if Model cannot be located. try: model_class = util.for_name(entity_kind) except ImportError, e: raise errors.BadReaderParam...
def validate(cls, job_config)
Inherit docs.
3.973861
3.799511
1.045887
if not filters: return properties = model_class.properties() for f in filters: prop, _, val = f if prop not in properties: raise errors.BadReaderParamsError( "Property %s is not defined for entity type %s", prop, model_class.kind()) # Validate ...
def _validate_filters(cls, filters, model_class)
Validate user supplied filters. Validate filters are on existing properties and filter values have valid semantics. Args: filters: user supplied filters. Each filter should be a list or tuple of format (<property_name_as_str>, <query_operator_as_str>, <value_of_certain_type>). Value ...
5.317312
4.145453
1.282685
if not filters: return properties = model_class._properties for f in filters: prop, _, val = f if prop not in properties: raise errors.BadReaderParamsError( "Property %s is not defined for entity type %s", prop, model_class._get_kind()) # Valid...
def _validate_filters_ndb(cls, filters, model_class)
Validate ndb.Model filters.
5.462588
5.261225
1.038273
if ndb is not None and isinstance(value, ndb.Model): return None if getattr(value, "_populate_internal_entity", None): return value._populate_internal_entity() return value
def _normalize_entity(value)
Return an entity from an entity or model instance.
5.27122
4.26832
1.234964
if ndb is not None and isinstance(value, (ndb.Model, ndb.Key)): return None if getattr(value, "key", None): return value.key() elif isinstance(value, basestring): return datastore.Key(value) else: return value
def _normalize_key(value)
Return a key from an entity, model instance, key, or key string.
3.911032
3.139462
1.245765
if self.should_flush(): self.flush() self.items.append(item)
def append(self, item)
Add new item to the list. If needed, append will first flush existing items and clear existing items. Args: item: an item to add to the list.
6.11967
5.202465
1.176302
if not self.items: return retry = 0 options = {"deadline": DATASTORE_DEADLINE} while retry <= self.__timeout_retries: try: self.__flush_function(self.items, options) self.clear() break except db.Timeout, e: logging.warning(e) logging.warnin...
def flush(self)
Force a flush.
5.525031
5.356001
1.031559
actual_entity = _normalize_entity(entity) if actual_entity is None: return self.ndb_put(entity) self.puts.append(actual_entity)
def put(self, entity)
Registers entity to put to datastore. Args: entity: an entity or model instance to put.
6.23486
5.654063
1.102722
assert ndb is not None and isinstance(entity, ndb.Model) self.ndb_puts.append(entity)
def ndb_put(self, entity)
Like put(), but for NDB entities.
4.621603
4.223648
1.094221
key = _normalize_key(entity) if key is None: return self.ndb_delete(entity) self.deletes.append(key)
def delete(self, entity)
Registers entity to delete from datastore. Args: entity: an entity, model instance, or key to delete.
6.577676
6.572161
1.000839
if ndb is not None and isinstance(entity_or_key, ndb.Model): key = entity_or_key.key else: key = entity_or_key self.ndb_deletes.append(key)
def ndb_delete(self, entity_or_key)
Like delete(), but for NDB entities/keys.
2.47789
2.313424
1.071092
self.puts.flush() self.deletes.flush() self.ndb_puts.flush() self.ndb_deletes.flush()
def flush(self)
Flush(apply) all changed to datastore.
4.622487
3.745275
1.234218
datastore.Put(items, config=self._create_config(options))
def _flush_puts(self, items, options)
Flush all puts to datastore.
24.033228
18.089766
1.328554
datastore.Delete(items, config=self._create_config(options))
def _flush_deletes(self, items, options)
Flush all deletes to datastore.
24.318562
17.312263
1.404701
assert ndb is not None ndb.put_multi(items, config=self._create_config(options))
def _flush_ndb_puts(self, items, options)
Flush all NDB puts to datastore.
6.170493
5.902741
1.045361
assert ndb is not None ndb.delete_multi(items, config=self._create_config(options))
def _flush_ndb_deletes(self, items, options)
Flush all deletes to datastore.
6.554608
6.297352
1.040851
return datastore.CreateConfig(deadline=options["deadline"], force_writes=self.force_writes)
def _create_config(self, options)
Creates datastore Config. Returns: A datastore_rpc.Configuration instance.
18.998636
18.681145
1.016995