Exemple #1
0
def test_config_helper():

    config = Config.helper()

    assert config.projects_dir == defaults.PROJECTS_DIR
    assert config.token == "Put your GitHub personal access token here"
    assert config.username == "This your GitHub username"
    assert config.editor == defaults.EDITOR
    assert config.conda_bin == defaults.CONDA_BIN
    assert config.common_packages == defaults.COMMON_PACKAGES
    assert config.git == defaults.GIT
Exemple #2
0
def interactive_config() -> None:
    """
    Prompt the user with a series of questions
    to configure pytoil interactively.
    """
    printer.warn("No pytoil config file detected!")
    interactive: bool = questionary.confirm(
        "Interactively configure pytoil?", default=False, auto_enter=False
    ).ask()

    if not interactive:
        # User doesn't want to interactively walk through a config file
        # so just make a default and exit cleanly
        Config.helper().write()
        printer.good("I made a default file for you.")
        printer.note(
            f"It's here: {defaults.CONFIG_FILE}, you can edit it with `pytoil"
            " config edit``",
            exits=0,
        )
        return

    # If we get here, the user wants to interactively make the config
    projects_dir: str = questionary.path(
        "Where do you keep your projects?",
        default=str(defaults.PROJECTS_DIR),
        only_directories=True,
    ).ask()

    token: str = questionary.text("GitHub personal access token?").ask()

    username: str = questionary.text("What's your GitHub username?").ask()

    use_editor: bool = questionary.confirm(
        "Auto open projects in an editor?", default=False, auto_enter=False
    ).ask()

    if use_editor:
        editor: str = questionary.text("Name of the editor binary to use?").ask()
    else:
        editor = "None"

    git: bool = questionary.confirm(
        "Make git repos when creating new projects?", default=True, auto_enter=False
    ).ask()

    conda_bin: str = questionary.select(
        "Use conda or mamba for conda environments?",
        choices=("conda", "mamba"),
        default="conda",
    ).ask()

    config = Config(
        projects_dir=Path(projects_dir).resolve(),
        token=token,
        username=username,
        editor=editor,
        conda_bin=conda_bin,
        git=git,
    )

    config.write()

    printer.good("Config created")
    printer.note(f"It's available at {defaults.CONFIG_FILE}.", exits=0)