def get_version(self, module_name): # pylint: disable=no-self-use """Get module version""" # Check built-in module if module_name in sys.builtin_module_names: return platform.python_version() # Check package declared module version try: # ToDo: This is slow! Is there any alternative? return pkg_resources.get_distribution(module_name).version except Exception: # pylint: disable=broad-except pass # Check explicitly declared module version try: module = importlib.import_module(module_name) for attr in ["__version__", "version", "__VERSION__", "VERSION"]: try: module_version = getattr(module, attr) if isinstance(module_version, string): return default_string(module_version) if isinstance(module_version, tuple): return ".".join(cvmap(str, module_version)) except AttributeError: pass except Exception: # pylint: disable=broad-except pass # If no other option work, return None return None
def show(self, _print=lambda x, offset=0: print(x)): """Show object Keyword arguments: _print -- custom print function (default=print) """ global_vars = list(self.globals) if global_vars: _print("{name}: {values}".format( name="Globals", values=", ".join(cvmap(str, global_vars)))) arg_vars = list(self.arguments) if arg_vars: _print("{name}: {values}".format( name="Arguments", values=", ".join(cvmap(str, arg_vars)))) if self.return_value: _print("Return value: {ret}".format(ret=self.return_value)) _show_slicing("Variables:", self.variables, _print) _show_slicing("Usages:", self.variables_usages, _print) _show_slicing("Dependencies:", self.source_variables, _print)
def extract_disasm(self): """Extract disassembly code""" compiled = cross_compile(self.code, self.path, "exec") if self.path == self.metascript.path: self.metascript.compiled = compiled self.disasm = instruction_dis_sorted_by_line(compiled, recurse=True) if self.metascript.disasm0: print("------------------------------------------------------") print(self.path) print("------------------------------------------------------") print("\n".join(cvmap(repr, self.disasm))) print("------------------------------------------------------")
def collect_provenance(self): """Collect definition provenance from scripts in metascript.paths""" metascript = self.metascript print_msg(" registering user-defined functions") for path, file_definition in viewitems(metascript.paths): visitor = self._visit_ast(file_definition) if visitor: if metascript.disasm: print("--------------------------------------------------") print(path) print("--------------------------------------------------") print("\n".join(cvmap(repr, visitor.disasm))) print("--------------------------------------------------") self._add_visitor(visitor)
def extract_disasm(self): """Extract disassembly code""" compiled = cross_compile( self.code, self.path, "exec") if self.path == self.metascript.path: self.metascript.compiled = compiled self.disasm = instruction_dis_sorted_by_line(compiled, recurse=True) if self.metascript.disasm0: print("------------------------------------------------------") print(self.path) print("------------------------------------------------------") print("\n".join(cvmap(repr, self.disasm))) print("------------------------------------------------------")
def create_automatic_tag(cls, trial_id, code_hash, command, session=None): """Create automatic tag for trial id Find maximum automatic tag by code_hash and command If it has the same code_hash and command, increment patch If it has the same code_hash, increment minor Otherwise, increment major Arguments: trial_id -- id of trial that should be tagged code_hash -- code_hash of trial script command -- command line Keyword arguments: session -- specify session for loading (default=relational.session) """ session = session or relational.session tag_typ, tag = cls.fast_load_auto_tag(trial_id, code_hash, command, session=session) new_tag = "" if tag_typ == 1: tag[2] += 1 elif tag_typ == 2: tag[1] += 1 tag[2] = 1 elif tag_typ == 3: tag[0] += 1 tag[1] = 1 tag[2] = 1 new_tag = ".".join(cvmap(str, tag)) session.execute( cls.t.insert(), dict(trial_id=trial_id, type="AUTO", name=new_tag, timestamp=datetime.now())) session.commit()
def create_automatic_tag(cls, trial_id, code_hash, command, session=None): """Create automatic tag for trial id Find maximum automatic tag by code_hash and command If it has the same code_hash and command, increment patch If it has the same code_hash, increment minor Otherwise, increment major Arguments: trial_id -- id of trial that should be tagged code_hash -- code_hash of trial script command -- command line Keyword arguments: session -- specify session for loading (default=relational.session) """ session = session or relational.session tag_typ, tag = cls.fast_load_auto_tag( trial_id, code_hash, command, session=session) new_tag = "" if tag_typ == 1: tag[2] += 1 elif tag_typ == 2: tag[1] += 1 tag[2] = 1 elif tag_typ == 3: tag[0] += 1 tag[1] = 1 tag[2] = 1 new_tag = ".".join(cvmap(str, tag)) session.execute(cls.t.insert(), dict( trial_id=trial_id, type="AUTO", name=new_tag, timestamp=datetime.now() )) session.commit()