Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add help information to the TUI #167

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 47 additions & 47 deletions src/scicookie/profiles/base.yaml
Original file line number Diff line number Diff line change
@@ -1,62 +1,62 @@
author_full_name:
message: Author's name
help: See more at https://
message: Type the author's name
help: https://osl-incubator.github.io/scicookie/guide.html#information-about-the-project
type: text
default: Roronoa Zoro
enabled: true

author_email:
message: Author's email
help: ""
message: Type the author's email
help: https://osl-incubator.github.io/scicookie/guide.html#information-about-the-project
type: text
default: zoro@one.piece
enabled: true

project_name:
message: Project name the title of the project
help: ""
message: Type the project's title
help: https://osl-incubator.github.io/scicookie/guide.html#information-about-the-project
type: text
default: OSL Python package
enabled: true

project_short_description:
message: Project short description
help: ""
message: Type a short description about the project
help: https://osl-incubator.github.io/scicookie/guide.html#information-about-the-project
type: text
default: This Project aims to ...
enabled: true

project_slug:
message: Project slug the code name for your project
help: ""
message: Type the code name for your project (e.g. the repository name)
help: https://osl-incubator.github.io/scicookie/guide.html#information-about-the-project
type: text
default: osl-template
enabled: true

package_slug:
message: Package slug the code name for your package
help: ""
message: Type the code name for your package (the name used to import your package)
help: https://osl-incubator.github.io/scicookie/guide.html#information-about-the-project
type: text
default: osl_template
default: "{{project_slug.replace('-', '_')}}"
enabled: true

project_version:
message: Project version
help: ""
message: Type the project version
help: https://osl-incubator.github.io/scicookie/guide.html#information-about-the-project
type: text
default: 0.1.0
enabled: true

project_url:
message: Project URL
help: ""
message: Type the project URL
help: https://osl-incubator.github.io/scicookie/guide.html#information-about-the-project
type: text
default: https://osl-template.com
enabled: true

project_license:
message: Select the project license
help: ""
message: Select one option for the project license
help: https://osl-incubator.github.io/scicookie/guide.html#information-about-the-project
type: single-choice
choices:
- MIT
Expand All @@ -68,17 +68,17 @@ project_license:
enabled: true

project_layout:
message: Select the project layout
help: ""
message: Select one option for the project layout
help: "For more information, check:\n https://osl-incubator.github.io/scicookie/guide.html#project-layout"
type: single-choice
choices:
- src
- flat
enabled: false

build_system:
message: Select the build system
help: ""
message: Select one option for the build system
help: "For more information, check:\n https://osl-incubator.github.io/scicookie/guide.html#build-system"
type: single-choice
choices:
- poetry
Expand All @@ -92,8 +92,8 @@ build_system:
enabled: false

command_line_interface:
message: Select the Command Line Interface (CLI)
help: ""
message: Select one option for Command Line Interface (CLI)
help: "For more information, check:\n https://osl-incubator.github.io/scicookie/guide.html#command-line-interfaces-clis"
type: single-choice
choices:
- No command-line interface
Expand All @@ -102,8 +102,8 @@ command_line_interface:
enabled: false

documentation_engine:
message: Select the Documentation Engine
help: ""
message: Select one option for the Documentation Engine
help: "For more information, check:\n https://osl-incubator.github.io/scicookie/guide.html#documentation-engine"
type: single-choice
choices:
- mkdocs
Expand All @@ -112,15 +112,15 @@ documentation_engine:
enabled: false

documentation_url:
message: Documentation URL
help: ""
message: Type the documentation URL
help: The URL for the documentation page.
type: text
default: ""
enabled: false

use_tools:
message: Select the initial tools you want to add to your project
help: ""
message: Select all the initial tools you want to add to your project
help: "For more information, check:\n https://osl-incubator.github.io/scicookie/guide.html#project-tools"
type: multiple-choices
choices:
- bandit
Expand All @@ -142,8 +142,8 @@ use_tools:
enabled: false

use_containers:
message: Select the container technology for this project
help: ""
message: Select one option for the container technology for this project
help: "For more information, check:\n https://osl-incubator.github.io/scicookie/guide.html#integration-with-devops-tools"
type: single-choice
choices:
- None
Expand All @@ -158,8 +158,8 @@ use_containers:
# default: Material

code_of_conduct:
message: Select Code of Conduct
help: ""
message: Select one option for the Code of Conduct
help: "For more information, check:\n https://osl-incubator.github.io/scicookie/guide.html#code-of-conduct"
type: single-choice
choices:
- None
Expand All @@ -168,8 +168,8 @@ code_of_conduct:
enabled: true

governance_document:
message: Select a governance document template
help: ""
message: Select one option for a governance document template
help: "For more information, check:\n https://osl-incubator.github.io/scicookie/guide.html#governance-document"
type: single-choice
choices:
- None
Expand All @@ -178,8 +178,8 @@ governance_document:
enabled: false

roadmap_document:
message: Select a Roadmap document template
help: ""
message: Select one option for a Roadmap document template
help: "For more information, check:\n https://osl-incubator.github.io/scicookie/guide.html#roadmap-document"
type: single-choice
choices:
- None
Expand All @@ -195,8 +195,8 @@ roadmap_document:
# enabled: false

git_username:
message: Git username
help: ""
message: Type the GIT username
help: https://osl-incubator.github.io/scicookie/guide.html#control-version
type: "text"
default: zoro_roronoa
depends_on:
Expand All @@ -206,8 +206,8 @@ git_username:
enabled: false

git_https_origin:
message: Git https origin URL
help: ""
message: Type the GIT HTTPS origin URL
help: https://osl-incubator.github.io/scicookie/guide.html#control-version
type: "text"
depends_on:
option: use_git
Expand All @@ -216,8 +216,8 @@ git_https_origin:
enabled: false

git_https_upstream:
message: Git https upstream URL
help: ""
message: Type the GIT HTTPS upstream URL
help: https://osl-incubator.github.io/scicookie/guide.html#control-version
type: "text"
depends_on:
option: use_git
Expand All @@ -226,8 +226,8 @@ git_https_upstream:
enabled: false

git_main_branch:
message: Git main branch
help: ""
message: Type the GIT main branch
help: https://osl-incubator.github.io/scicookie/guide.html#control-version
type: "text"
default: main
depends_on:
Expand Down
39 changes: 24 additions & 15 deletions src/scicookie/ui.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Define functions for the interface with the user."""
from typing import Dict, Optional, Type
from __future__ import annotations

from typing import Optional, Type

import inquirer
from jinja2 import Template

from scicookie.logs import SciCookieErrorType, SciCookieLogs

Expand All @@ -14,8 +17,6 @@ def _create_question(
return None

# config required
default_answer = question.get("default", "")
question_message = question.get("message", "")
question_type = question.get("type", "")
# todo: implement help text int he prompt
# question_help = question.get("help")
Expand All @@ -37,18 +38,12 @@ def _create_question(
SciCookieErrorType.SCICOOKIE_INVALID_CONFIGURATION,
)

content = {
"message": (
question_message
if not default_answer
else f"{question_message} (default: {default_answer})"
)
}
content = {"message": ""}

if question.get("choices"):
content["choices"] = question.get("choices")
content["choices"] = question.get("choices", [])

fn_questions: Dict[str, Type[inquirer.questions.Question]] = {
fn_questions: dict[str, Type[inquirer.questions.Question]] = {
"text": inquirer.Text,
"single-choice": inquirer.List,
"multiple-choices": inquirer.Checkbox,
Expand All @@ -63,11 +58,25 @@ def _create_question(

def make_questions(questions: dict):
"""Generate all the enabled questions."""
questions_ui = []
answers: dict[str, str] = {}

for question_id, question in questions.items():
question_obj = _create_question(question_id, question)
# note: if question_object is None, that means that the question is
# not enabled
if question_obj:
questions_ui.append(question_obj)
default_answer = question.get("default", "")
default_answer = Template(default_answer).render(answers)
message = question.get("message", "")
print(f"{message} (default: {default_answer}):")
print(">> HELP:", question["help"])
answer = inquirer.prompt([question_obj])

return inquirer.prompt(questions_ui)
# note: if answer is none, it means that the user cancelled
# the process.
if answer is None:
return {}
answers[question_id] = (
answer.get(question_id, "") or default_answer
)
return answers