Skip to content

Commit

Permalink
feat: Add help information to the TUI (#167)
Browse files Browse the repository at this point in the history
* Adds the help information in the TUI for each question;
* Allow using jinja2 tags for `default` value for each question.
  • Loading branch information
xmnlab authored Aug 10, 2023
1 parent b3d59cd commit 8c05a6d
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 62 deletions.
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 @@ -93,8 +93,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 @@ -103,8 +103,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 @@ -113,15 +113,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 @@ -143,8 +143,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 @@ -159,8 +159,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 @@ -169,8 +169,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 @@ -179,8 +179,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 @@ -196,8 +196,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 @@ -207,8 +207,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 @@ -217,8 +217,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 @@ -227,8 +227,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

0 comments on commit 8c05a6d

Please sign in to comment.