text
stringlengths
81
112k
Given that records are based on the parent, and the same entry point(s) will reference those same records multiple times, the actual stored records must be limited. def store_records_for_package(self, entry_point, records): """ Given that records are based on the parent, and the same en...
Get default encoder cwr file :return: def default_file_encoder(): """ Get default encoder cwr file :return: """ config = CWRConfiguration() field_configs = config.load_field_config('table') field_configs.update(config.load_field_config('common')) field_values = CWRTables() for...
Parses a CWR file name from a FileTag object. The result will be a string following the format CWyynnnnsss_rrr.Vxx, where the numeric sequence will have the length set on the encoder's constructor. :param tag: FileTag to parse :return: a string file name parsed from the FileTag...
Encodes the data, creating a CWR structure from an instance from the domain model. :param entity: the instance to encode :return: a cwr string structure created from the received data def encode(self, transmission): """ Encodes the data, creating a CWR structure from an instanc...
get a random scan def getScans(self, modifications=True, fdr=True): """ get a random scan """ if not self.scans: for i in self: yield i else: for i in self.scans.values(): yield i yield None
allows random lookup def getScan(self, title, peptide=None): """ allows random lookup """ if self.ra.has_key(title): self.filename.seek(self.ra[title][0],0) toRead = self.ra[title][1]-self.ra[title][0] info = self.filename.read(toRead) sca...
All input follows the BEGIN IONS row and ends before END IONS def parseScan(self, scan): """ All input follows the BEGIN IONS row and ends before END IONS """ setupScan = True foundCharge = False foundMass = False foundTitle = False scanObj = ScanObject()...
get a random scan def getScan(self, specId, peptide=None): """ get a random scan """ sql = self.base_sql + " where sh.SpectrumID = %d and p.Sequence = '%s'"%(int(specId),peptide) self.cur.execute(sql) i = self.cur.fetchone() if not i: return None ...
get a random scan def getScans(self, modifications=False, fdr=True): """ get a random scan """ if fdr: sql = self.base_sql+"WHERE p.ConfidenceLevel >= {} and p.SearchEngineRank <= {} {}".format(self.clvl, self.srank, self.extra) try: self.cur.exec...
parses scan info for giving a Spectrum Obj for plotting. takes significantly longer since it has to unzip/parse xml def parseFullScan(self, i, modifications=False): """ parses scan info for giving a Spectrum Obj for plotting. takes significantly longer since it has to unzip/parse xml """ ...
get a random scan def getScans(self, modifications=True, fdr=True): """ get a random scan """ if fdr: sql = "select sp.Spectrum, p.Sequence, p.PeptideID, p.SpectrumID from spectrumheaders sh left join spectra sp on (sp.UniqueSpectrumID=sh.UniqueSpectrumID) left join peptides...
parses scan info for giving a Spectrum Obj for plotting. takes significantly longer since it has to unzip/parse xml def parseFullScan(self, i, modifications=True): """ parses scan info for giving a Spectrum Obj for plotting. takes significantly longer since it has to unzip/parse xml """ ...
Attempt to resolve the distribution from the provided class in the most naive way - this assumes the Python module path to the class contains the name of the package that provided the module and class. def _cls_lookup_dist(cls): """ Attempt to resolve the distribution from the provided class in the ...
To ensure that the provided builder has a signature that is at least compatible. def verify_builder(builder): """ To ensure that the provided builder has a signature that is at least compatible. """ try: d = getcallargs(builder, package_names=[], export_target='some_path') except T...
Extract the builder result to produce a ``Toolchain`` and ``Spec`` instance. def extract_builder_result(builder_result, toolchain_cls=Toolchain): """ Extract the builder result to produce a ``Toolchain`` and ``Spec`` instance. """ try: toolchain, spec = builder_result except Except...
Trace the versions of the involved packages for the provided toolchain instance. def trace_toolchain(toolchain): """ Trace the versions of the involved packages for the provided toolchain instance. """ pkgs = [] for cls in getmro(type(toolchain)): if not issubclass(cls, Toolchain):...
Similar to pkg_resources.resource_filename, however this works with the information cached in this registry instance, and arguments are not quite the same. Arguments: package_name The name of the package to get the artifact from artifact_name The exact n...
Yield the list of paths to the artifacts in the order of the dependency resolution Arguments: package_names The names of the packages to probe the dependency graph, to be provided as a list of strings. artifact_name The exact name of the artifact. ...
Return metadata of the artifacts built through this registry. def get_artifact_metadata(self, package_name): """ Return metadata of the artifacts built through this registry. """ filename = self.metadata.get(package_name) if not filename or not exists(filename): ret...
After the toolchain and spec have been executed, this may be called to generate the artifact export entry for persistence into the metadata file. def generate_metadata_entry(self, entry_point, toolchain, spec): """ After the toolchain and spec have been executed, this may be cal...
Iterate records for a specific package. def iter_records_for(self, package_name): """ Iterate records for a specific package. """ entry_points = self.packages.get(package_name, NotImplemented) if entry_points is NotImplemented: logger.debug( "package...
Yields exactly one builder if both the provided entry point and export target satisfies the checks required. def generate_builder(self, entry_point, export_target): """ Yields exactly one builder if both the provided entry point and export target satisfies the checks required. "...
Accepts the arguments provided by the builder and executes them. def execute_builder(self, entry_point, toolchain, spec): """ Accepts the arguments provided by the builder and executes them. """ toolchain(spec) if not exists(spec['export_target']): logger.error( ...
Build artifacts declared for the given package. def process_package(self, package_name): """ Build artifacts declared for the given package. """ metadata = super(ArtifactRegistry, self).process_package(package_name) if metadata: self.update_artifact_metadata(package...
Creates the grammar for an alphanumeric code where the size ranges between two values. :param min_size: minimum size :param max_size: maximum size :param name: name for the field :return: grammar for an alphanumeric field of a variable size def alphanum_variable(min_size, max_size, name=None): ...
Creates the grammar for a field containing a year. :param columns: the number of columns for the year :param name: the name of the field :return: def year(columns, name=None): """ Creates the grammar for a field containing a year. :param columns: the number of columns for the year :param ...
Check that the value is either a JSON decodable string or a dict that can be encoded into a JSON. Raises ValueError when validation fails. def is_json_compat(value): """ Check that the value is either a JSON decodable string or a dict that can be encoded into a JSON. Raises ValueError when va...
Check for json validity. def validate_json_field(dist, attr, value): """ Check for json validity. """ try: is_json_compat(value) except ValueError as e: raise DistutilsSetupError("%r %s" % (attr, e)) return True
Validate that the value is compatible def validate_line_list(dist, attr, value): """ Validate that the value is compatible """ # does not work as reliably in Python 2. if isinstance(value, str): value = value.split() value = list(value) try: check = (' '.join(value)).split...
Write JSON captured from the defined argname into the package's egg-info directory using the specified filename. def write_json_file(argname, cmd, basename, filename): """ Write JSON captured from the defined argname into the package's egg-info directory using the specified filename. """ value...
Write out the retrieved value as list of lines. def write_line_list(argname, cmd, basename, filename): """ Write out the retrieved value as list of lines. """ values = getattr(cmd.distribution, argname, None) if isinstance(values, list): values = '\n'.join(values) cmd.write_or_delete_f...
Locate a package's distribution by its name. def find_pkg_dist(pkg_name, working_set=None): """ Locate a package's distribution by its name. """ working_set = working_set or default_working_set req = Requirement.parse(pkg_name) return working_set.find(req)
Convert package names, which can be a string of a number of package names or requirements separated by spaces. def convert_package_names(package_names): """ Convert package names, which can be a string of a number of package names or requirements separated by spaces. """ results = [] error...
Return the entire list of dependency requirements, reversed from the bottom. def find_packages_requirements_dists(pkg_names, working_set=None): """ Return the entire list of dependency requirements, reversed from the bottom. """ working_set = working_set or default_working_set requirements...
Leverages the `find_packages_requirements_dists` but strip out the distributions that matches pkg_names. def find_packages_parents_requirements_dists(pkg_names, working_set=None): """ Leverages the `find_packages_requirements_dists` but strip out the distributions that matches pkg_names. """ d...
Safely get a json within an egginfo from a distribution. def read_dist_egginfo_json(dist, filename=DEFAULT_JSON): """ Safely get a json within an egginfo from a distribution. """ # use the given package's distribution to acquire the json file. if not dist.has_metadata(filename): logger.deb...
Read json from egginfo of a package identified by `pkg_name` that's already installed within the current Python environment. def read_egginfo_json(pkg_name, filename=DEFAULT_JSON, working_set=None): """ Read json from egginfo of a package identified by `pkg_name` that's already installed within the cur...
Flatten a distribution's egginfo json, with the depended keys to be flattened. Originally this was done for this: Resolve a distribution's (dev)dependencies through the working set and generate a flattened version package.json, returned as a dict, from the resolved distributions. Default work...
A shorthand calling convention where the package name is supplied instead of a distribution. Originally written for this: Generate a flattened package.json with packages `pkg_names` that are already installed within the current Python environment (defaults to the current global working_set which s...
Return a tuple of functions that will provide the usage of the JSON egginfo based around the provided field. def build_helpers_egginfo_json( json_field, json_key_registry, json_filename=None): """ Return a tuple of functions that will provide the usage of the JSON egginfo based around the provi...
Return a tuple of funtions that will provide the functions that return the relevant sets of module registry records based on the dependencies defined for the provided packages. def build_helpers_module_registry_dependencies(registry_name='calmjs.module'): """ Return a tuple of funtions that will provid...
For a distutils command to verify that the artifact build step is possible. def has_calmjs_artifact_declarations(cmd, registry_name='calmjs.artifacts'): """ For a distutils command to verify that the artifact build step is possible. """ return any(get(registry_name).iter_records_for( c...
Trigger the artifact build process through the setuptools. def build_calmjs_artifacts(dist, key, value, cmdclass=BuildCommand): """ Trigger the artifact build process through the setuptools. """ if value is not True: return build_cmd = dist.get_command_obj('build') if not isinstance(b...
Returns the rule for the field identified by the id. If it is set as not being compulsory, the rule will be adapted to accept string composed only of white characters. :param field_id: unique id in the system for the field :return: the rule of a field def get_rule(self, field_id): ...
Creates the field with the specified parameters. :param field_id: identifier for the field :return: the basic rule for the field def _create_field(self, field_id): """ Creates the field with the specified parameters. :param field_id: identifier for the field :return: t...
Parses a CSV file into a list. :param file_name: name of the CSV file :return: a list with the file's contents def read_csv_file(self, file_name): """ Parses a CSV file into a list. :param file_name: name of the CSV file :return: a list with the file's contents ...
Parses a YAML file into a matrix. :param file_name: name of the YAML file :return: a matrix with the file's contents def read_yaml_file(self, file_name): """ Parses a YAML file into a matrix. :param file_name: name of the YAML file :return: a matrix with the file's con...
Acquires the data from the table identified by the id. The file is read only once, consecutive calls to this method will return the sale collection. :param file_id: identifier for the table :return: all the values from the table def get_data(self, file_id): """ Acquire...
Creates a record type field. These serve as the header field on records, identifying them. Usually this field can be only an specific value, but sometimes a small range of codes is allowed. This is specified by the 'values' parameter. While it is possible to set this field as optional, it is expected...
Creates a record prefix for the specified record type. :param required_type: the type of the record using this prefix :param factory: field factory :return: the record prefix def record_prefix(required_type, factory): """ Creates a record prefix for the specified record type. :param required_...
Search and return entity or sub entity that contain value of this field. :param entity: :return: entity :raise KeyError def expand_entity(self, entity): """ Search and return entity or sub entity that contain value of this field. :param entity: :return: entity ...
Encode this :param entity: :return: cwr string def encode(self, entity): """ Encode this :param entity: :return: cwr string """ entity = self.expand_entity(entity) value = entity[self.name] result = self.format(value) return result
Reads a CWR grammar config file. :param file_name: name of the text file :return: the file's contents def read_config_file(self, file_name): """ Reads a CWR grammar config file. :param file_name: name of the text file :return: the file's contents """ wi...
Loads the CWR default values file, creating a matrix from it, and then returns this data. The file will only be loaded once. :return: the CWR default values matrix def _load_cwr_defaults(self): """ Loads the CWR default values file, creating a matrix from it, and then ...
Loads the configuration fields file for the id. :param file_id: the id for the field :return: the fields configuration def load_field_config(self, file_id): """ Loads the configuration fields file for the id. :param file_id: the id for the field :return: the fields con...
Loads the configuration fields file for the id. :param file_id: the id for the field :return: the fields configuration def load_group_config(self, file_id): """ Loads the configuration fields file for the id. :param file_id: the id for the field :return: the fields con...
Loads the configuration fields file for the id. :param file_id: the id for the field :return: the fields configuration def load_record_config(self, file_id): """ Loads the configuration fields file for the id. :param file_id: the id for the field :return: the fields co...
Loads the configuration fields file for the id. :param file_id: the id for the field :return: the fields configuration def load_transaction_config(self, file_id): """ Loads the configuration fields file for the id. :param file_id: the id for the field :return: the fiel...
Loads the CWR acknowledge config :return: the values matrix def load_acknowledge_config(self, file_id): """ Loads the CWR acknowledge config :return: the values matrix """ if self._cwr_defaults is None: self._cwr_defaults = self._reader.read_yaml_file( ...
Same as error, without the dying in a fire part. def soft_error(self, message): """ Same as error, without the dying in a fire part. """ self.print_usage(sys.stderr) args = {'prog': self.prog, 'message': message} self._print_message( _('%(prog)s: error: %(me...
Creates a decoder which parses CWR filenames following the old or the new convention. :return: a CWR filename decoder for the old and the new conventions def default_filename_decoder(): """ Creates a decoder which parses CWR filenames following the old or the new convention. :return: a CWR fi...
Parses the file, creating a CWRFile from it. It requires a dictionary with two values: - filename, containing the filename - contents, containing the file contents :param data: dictionary with the data to parse :return: a CWRFile instance def decode(self, data): """ ...
Parses the filename, creating a FileTag from it. It will try both the old and the new conventions, if the filename does not conform any of them, then an empty FileTag will be returned. :param file_name: filename to parse :return: a FileTag instance def decode(self, file_name): ...
Shorthand to enable pretty logging def enable_pretty_logging(logger='calmjs', level=logging.DEBUG, stream=None): """ Shorthand to enable pretty logging """ def cleanup(): logger.removeHandler(handler) logger.level = old_level if not isinstance(logger, logging.Logger): logg...
Produce a platform specific env for passing into subprocess.Popen family of external process calling methods, and the supplied env will be updated on top of it. Returns a new env. def finalize_env(env): """ Produce a platform specific env for passing into subprocess.Popen family of external proces...
Do a fork-exec through the subprocess.Popen abstraction in a way that takes a stdin and return stdout. def fork_exec(args, stdin='', **kwargs): """ Do a fork-exec through the subprocess.Popen abstraction in a way that takes a stdin and return stdout. """ as_bytes = isinstance(stdin, bytes) ...
Helper for raising the correct exception under Python 3 while still being able to raise the same common exception class in Python 2.7. def raise_os_error(_errno, path=None): """ Helper for raising the correct exception under Python 3 while still being able to raise the same common exception class in Py...
Given cmd, check where it is on PATH. Loosely based on the version in python 3.3. def which(cmd, mode=os.F_OK | os.X_OK, path=None): """ Given cmd, check where it is on PATH. Loosely based on the version in python 3.3. """ if os.path.dirname(cmd): if os.path.isfile(cmd) and os.access...
Turn the records into actual usable keys. def _init(self): """ Turn the records into actual usable keys. """ self._entry_points = {} for entry_point in self.raw_entry_points: if entry_point.dist.project_name != self.reserved.get( entry_point.name...
For updating a base dict with a fresh one, returning a list of 3-tuples containing the key, previous value (base[key]) and the fresh value (fresh[key]) for all colliding changes (reassignment of identical values are omitted). def dict_update_overwrite_check(base, fresh): """ For updating a base dic...
Resolve a BasePluginLoaderRegistry instance from spec, and update spec[CALMJS_LOADERPLUGIN_REGISTRY] with that value before returning it. def spec_update_loaderplugin_registry(spec, default=None): """ Resolve a BasePluginLoaderRegistry instance from spec, and update spec[CALMJS_LOADERPLUGIN_REGISTR...
Take an existing spec and a sourcepath mapping (that could be produced via calmjs.dist.*_module_registry_dependencies functions) and split out the keys that does not contain loaderplugin syntax and assign it to the spec under sourcepath_key. For the parts with loader plugin syntax (i.e. modnames (keys)...
A standard helper function for combining the filtered (e.g. using ``spec_update_sourcepath_filter_loaderplugins``) loaderplugin sourcepath mappings back into one that is usable with the standard ``toolchain_spec_compile_entries`` function. Arguments: toolchain The toolchain spec ...
The standardized Toolchain Spec Entries compile function This function accepts a toolchain instance, the spec to be operated with and the entries provided for the process name. The standard flow is to deferr the actual processing to the toolchain method `compile_{process_name}_entry` for each entry in...
The generalized raw spec entry process invocation loop. def process_compile_entries( processor, spec, entries, modpath_logger=None, targetpath_logger=None): """ The generalized raw spec entry process invocation loop. """ # Contains a mapping of the module name to the compiled file's # rela...
Like update, however a list of selected keys must be provided. def update_selected(self, other, selected): """ Like update, however a list of selected keys must be provided. """ self.update({k: other[k] for k in selected})
Overriding of this is only permitted if and only if your name is Megumin and you have a pet/familiar named Chomusuke. def __advice_stack_frame_protection(self, frame): """ Overriding of this is only permitted if and only if your name is Megumin and you have a pet/familiar named Chomusuk...
Add an advice that will be handled later by the handle method. Arguments: name The name of the advice group f A callable method or function. The rest of the arguments will be passed as arguments and keyword arguments to f when it's invoked. def advise(...
Call all advices at the provided name. This has an analogue in the join point in aspected oriented programming, but the analogy is a weak one as we don't have the proper metaobject protocol to support this. Implementation that make use of this system should make it clear that they will...
Resolve and update the path key in the spec with its realpath, based on the working directory. def realpath(self, spec, key): """ Resolve and update the path key in the spec with its realpath, based on the working directory. """ if key not in spec: # do noth...
Set up the compile prefix, sourcepath and the targetpath suffix attributes, which are the prefix to the function name and the suffixes to retrieve the values from for creating the generator function. def setup_prefix_suffix(self): """ Set up the compile prefix, sourcepath and th...
Essentially validate that the target is inside the build_dir. def _validate_build_target(self, spec, target): """ Essentially validate that the target is inside the build_dir. """ if not realpath(target).startswith(spec[BUILD_DIR]): raise ValueError('build_target %s is outs...
The function that gets called by compile_transpile_entry for processing the provided JavaScript source file provided by some Python package through the transpiler instance. def transpile_modname_source_target(self, spec, modname, source, target): """ The function that gets called by com...
The original simple transpile method called by compile_transpile on each target. def simple_transpile_modname_source_target( self, spec, modname, source, target): """ The original simple transpile method called by compile_transpile on each target. """ opener...
Handler for each entry for the transpile method of the compile process. This invokes the transpiler that was set up to transpile the input files into the build directory. def compile_transpile_entry(self, spec, entry): """ Handler for each entry for the transpile method of the compile ...
Handler for each entry for the bundle method of the compile process. This copies the source file or directory into the build directory. def compile_bundle_entry(self, spec, entry): """ Handler for each entry for the bundle method of the compile process. This copies the source ...
Generic loader plugin entry handler. The default implementation assumes that everything up to the first '!' symbol resolves to some known loader plugin within the registry. The registry instance responsible for the resolution of the loader plugin handlers must be available in t...
Create a target file name from the input module name and its source file name. The result should be a path relative to the build_dir, and this is derived directly from the modname with NO implicit convers of path separators (i.e. '/' or any other) into a system or OS specific form (e.g....
Typical JavaScript tools will get confused if '.js' is added, so by default the same modname is returned as path rather than the target file for the module path to be written to the output file for linkage by tools. Some other tools may desire the target to be returned instead, or const...
Private generator that will consume those above functions. This should NOT be overridden. Produces the following 4-tuple on iteration with the input dict; the definition is written at the module level documention for calmjs.toolchain, but in brief: modname The Java...
Generic step that compiles from a spec to build the specified things into the build directory `build_dir`, by gathering all the files and feed them through the transpilation process or by simple copying. def compile(self, spec): """ Generic step that compiles from a spec to buil...
The main call, assuming the base spec is prepared. Also, no advices will be triggered. def _calf(self, spec): """ The main call, assuming the base spec is prepared. Also, no advices will be triggered. """ self.prepare(spec) self.compile(spec) self.asse...
Typical safe usage is this, which sets everything that could be problematic up. Requires the filename which everything will be produced to. def calf(self, spec): """ Typical safe usage is this, which sets everything that could be problematic up. Requires the filename w...
Calls the original version. def transpile_modname_source_target(self, spec, modname, source, target): """ Calls the original version. """ return self.simple_transpile_modname_source_target( spec, modname, source, target)
Get the version string through the binary. def get_bin_version_str(bin_path, version_flag='-v', kw={}): """ Get the version string through the binary. """ try: prog = _get_exec_binary(bin_path, kw) version_str = version_expr.search( check_output([prog, version_flag], **kw)....
Get the version string through the binary and return a tuple of integers. def get_bin_version(bin_path, version_flag='-v', kw={}): """ Get the version string through the binary and return a tuple of integers. """ version_str = get_bin_version_str(bin_path, version_flag, kw) if version_str:...
Calls node with an inline source. Returns decoded output of stdout and stderr; decoding determine by locale. def node(self, source, args=(), env={}): """ Calls node with an inline source. Returns decoded output of stdout and stderr; decoding determine by locale. ...
This was originally designed to be invoked at the module level for packages that implement specific support, but this can be used to create an instance that has the Node.js backed executable be found via current directory's node_modules or NODE_PATH. def create_for_module_vars(cls, scop...
Returns the manifest JSON for the Python package name. Default npm implementation calls for package.json. If this class is initiated using standard procedures, this will mimic the functionality of ``npm view`` but mostly for showing the dependencies. This is done as a default action. ...
Note: default implementation calls for npm and package.json, please note that it may not be the case for this instance of Driver. If this class is initiated using standard procedures, this will emulate the functionality of ``npm init`` for the generation of a working ``package.j...