"""本库的一些信息"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../src/notebooks/00_help (library information).ipynb.

# %% auto 0
__all__ = [
    "lib_paths",
    "lib_name_en_us",
    "lib_name_zh_cn",
    "lib_name",
    "author_name_en_us",
    "author_name_zh_cn",
    "github_user",
    "github_repo",
    "import_name",
    "upgrade_command_pip",
    "pretty_name",
    "LibraryPaths",
    "setup_paths",
    "create_variables_from_dict",
    "combine_bilingual_pretty",
]

# %% ../src/notebooks/00_help (library information).ipynb 5
# https://stackoverflow.com/questions/1547466/check-if-a-parameter-is-a-python-module
from types import ModuleType

# %% ../src/notebooks/00_help (library information).ipynb 6
from dataclasses import dataclass
from pathlib import Path
import inspect
from typing import Any


@dataclass
class LibraryPaths:
    lib_init_path: Path
    lib_directory_path: Path
    lib_repo_path: Path
    readme_path: Path
    runs_path: Path
    runs_figs_path: Path
    data_path: Path


def setup_paths(this_library: ModuleType) -> LibraryPaths:
    """
    Sets up paths for a given library module.

    Parameters:
    - this_library: The library module for which to set up paths.

    Returns:
    - LibraryPaths: A dataclass containing all the necessary paths.
    """
    lib_init_path = Path(inspect.getfile(this_library))
    lib_directory_path = lib_init_path.parent
    lib_repo_path = lib_directory_path.parent

    runs_path = lib_repo_path / "runs"
    runs_path.mkdir(exist_ok=True, parents=True)

    runs_figs_path = runs_path / "figs"
    runs_figs_path.mkdir(exist_ok=True, parents=True)

    data_path = lib_repo_path / "data"
    data_path.mkdir(exist_ok=True, parents=True)

    readme_path = lib_repo_path / "README.md"

    # TODO 这个需要吗，真的缺乏doc吗
    if readme_path.exists():
        with open(lib_repo_path / "README.md") as readme:
            this_library.__doc__ = readme.read()

    return LibraryPaths(
        lib_init_path=lib_init_path,
        lib_directory_path=lib_directory_path,
        lib_repo_path=lib_repo_path,
        readme_path=readme_path,
        runs_path=runs_path,
        runs_figs_path=runs_figs_path,
        data_path=data_path,
    )


# %% ../src/notebooks/00_help (library information).ipynb 7
import scholarly_infrastructure as this_library

lib_paths = setup_paths(this_library)

# %% ../src/notebooks/00_help (library information).ipynb 9
from dataclasses import dataclass, asdict, is_dataclass


def create_variables_from_dict(d: dict[str, Any] | Any, global_dict=None) -> None:
    if is_dataclass(d):
        d = asdict(d)
    else:
        assert isinstance(d, dict), (
            f"Input must be a dictionary or a dataclass, but got {type(d)}. "
        )
    if global_dict is None:
        global_dict = globals()
    global_dict |= d


# %% ../src/notebooks/00_help (library information).ipynb 10
create_variables_from_dict(lib_paths)


# %% ../src/notebooks/00_help (library information).ipynb 14
def combine_bilingual_pretty(primary: str, auxiliary: str) -> str:
    return f"{primary} ({auxiliary}) "


# %% ../src/notebooks/00_help (library information).ipynb 15
lib_name_en_us = "Scholarly Infrastructure"
lib_name_zh_cn = "大师荟萃之楼"  # 群贤毕至之厦，群英聚首之阁
lib_name = combine_bilingual_pretty(lib_name_zh_cn, lib_name_en_us)

author_name_en_us = "THU-CVML"
author_name_zh_cn = "清华大学计算机视觉与机器学习实验室"
github_user = "THU-CVML"
github_repo = "ScholarlyInfrastructure"
import_name = "scholarly_infrastructure"  # pypi name and python import name

upgrade_command_pip = (
    f"pip install --upgrade {import_name}"  # command to upgrade the library
)

pretty_name = combine_bilingual_pretty(
    f"{author_name_zh_cn}/{lib_name_zh_cn}", f"{author_name_en_us}/{lib_name_en_us}"
)
