def test_with_errors(self): try: with TemporaryDirectory() as tmpdir: with path.changed_directory(tmpdir): raise ValueError("die mid-context") except ValueError as err: assert "die mid-context" in str(err) finally: assert os.getcwd() == self.original_dir
def prepare_data(_logging_only: bool = False) -> List[str]: """ Rebuild any dynamically buildable data """ flavours = ["bacteria", "fungi", "plants"] with path.changed_directory(path.get_full_path(__file__, "css")): built_files = [os.path.abspath("%s.css" % flavour) for flavour in flavours] if path.is_outdated(built_files, glob.glob("*.scss")): logging.info("CSS files out of date, rebuilding") for flavour in flavours: target = "%s.css" % flavour assert os.path.exists(flavour + ".scss"), flavour result = scss.Compiler(output_style="expanded").compile(flavour + ".scss") assert result with open(target, "w") as out: out.write(result) return []
def run_on_record(record: Record, results: Optional[SMCOGTreeResults], options: ConfigType) -> SMCOGTreeResults: """ Generates phylogeny trees of the classifications made by SMCOGs """ if results and isinstance(results, SMCOGTreeResults): return results # create the smcogs output directory if required relative_output_dir = os.path.relpath( os.path.join(options.output_dir, "smcogs"), os.getcwd()) smcogs_dir = os.path.abspath(relative_output_dir) if not os.path.exists(smcogs_dir): os.mkdir(smcogs_dir) nrpspks_genes = record.get_nrps_pks_cds_features() with path.changed_directory(smcogs_dir): trees = generate_trees(smcogs_dir, record.get_cds_features_within_regions(), nrpspks_genes) return SMCOGTreeResults(record.id, relative_output_dir, trees)
def get_git_version( fallback_filename: Optional[str] = GIT_VERSION_FALLBACK_FILENAME ) -> str: """Get the sha1 of the current git version""" git_version = "" try: with changed_directory(os.path.dirname(__file__)): version_cmd = execute(['git', 'rev-parse', '--short', 'HEAD']) status_cmd = execute(['git', 'status', '--porcelain']) if version_cmd.successful() and status_cmd.successful(): git_version = version_cmd.stdout.strip() changes = status_cmd.stdout.splitlines() if changes: git_version += "(changed)" except OSError: pass if git_version == "" and fallback_filename: if locate_file(fallback_filename, silent=True): with open(fallback_filename, 'rt') as handle: git_version = handle.read().strip() return git_version
def write_clusterblast_output(options: ConfigType, record: Record, cluster_result: RegionResult, proteins: Dict[str, Protein], searchtype: str = "clusterblast") -> None: """ Writes a text form of clusterblast results to file. Arguments: options: the antismash config record: the record that the results came from cluster_result: the RegionResult object to write information about proteins: a dict mapping protein name to Protein searchtype: the name of the module of which to write results for Returns: None """ assert isinstance(proteins, dict) region_number = cluster_result.region.get_region_number() filename = "%s_c%d.txt" % (record.id, region_number) with changed_directory(_get_output_dir(options, searchtype)): _write_output(filename, record, cluster_result, proteins)
def test_functions(self): with TemporaryDirectory() as tmpdir: assert os.getcwd() != tmpdir with path.changed_directory(tmpdir): assert os.getcwd() == tmpdir assert os.getcwd() == self.original_dir