laminlabs / bionty-base

Access public biological ontologies.
https://bionty-base.lamin.ai
Apache License 2.0
15 stars 3 forks source link

Implement proper prompt for source_reset #463

Closed Zethson closed 1 year ago

Zethson commented 1 year ago
def reset_sources(confirm: bool = False):
    """Reset local bionty sources file."""
    from importlib import reload

    import bionty

    if confirm:
        try:
            LOCAL_SOURCES.unlink()
            logger.success(f"Removed file: {LOCAL_SOURCES}.")
        except FileNotFoundError:
            pass
        try:
            CURRENT_SOURCES.unlink()
            logger.success(f"Removed file: {CURRENT_SOURCES}.")
        except FileNotFoundError:
            pass
        try:
            LAMINDB_SOURCES.unlink()
            logger.success(f"Removed file: {LAMINDB_SOURCES}.")
        except FileNotFoundError:
            pass

        reload(bionty)
        logger.info("Reloaded bionty!")

    else:
        logger.warning(
            "Are you sure to reset your local bionty sources? Pass 'confirm=True'"
        )

Not the prettiest UX to get asked to run the function again with a parameter. Ideally use https://github.com/tmbo/questionary but it is an additional dependency (only prompt_toolkit as a transitive one)