Feat: prompts and write prompt_exam
This commit is contained in:
parent
6d93ef62d7
commit
49cc52f7d1
9
recopytex/scripts/getconfig.py
Normal file
9
recopytex/scripts/getconfig.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
CONFIGPATH = "recoconfig.yml"
|
||||||
|
|
||||||
|
with open(CONFIGPATH, "r") as config:
|
||||||
|
config = yaml.load(config, Loader=yaml.FullLoader)
|
||||||
|
|
70
recopytex/scripts/prompts.py
Normal file
70
recopytex/scripts/prompts.py
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# encoding: utf-8
|
||||||
|
|
||||||
|
|
||||||
|
from PyInquirer import prompt, print_json
|
||||||
|
from datetime import datetime
|
||||||
|
from functools import wraps
|
||||||
|
|
||||||
|
from .getconfig import config
|
||||||
|
|
||||||
|
|
||||||
|
def prompt_until_validate(func):
|
||||||
|
@wraps(func)
|
||||||
|
def wrapper(*args, **kwrd):
|
||||||
|
ans = func(*args, **kwrd)
|
||||||
|
question = [
|
||||||
|
{"type": "confirm", "name": "confirm", "message": "C'est bon?(enter)"}
|
||||||
|
]
|
||||||
|
while not prompt(question)["confirm"]:
|
||||||
|
ans = func(ans)
|
||||||
|
return ans
|
||||||
|
|
||||||
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
@prompt_until_validate
|
||||||
|
def prompt_exam(default={}):
|
||||||
|
""" Prompt questions to edit an exam """
|
||||||
|
questions = [
|
||||||
|
{
|
||||||
|
"type": "list",
|
||||||
|
"name": "_tribe",
|
||||||
|
"message": "Nom de la classe",
|
||||||
|
"choices": [t["name"] for t in config["tribes"]],
|
||||||
|
"default": default.get("tribe", ""),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input",
|
||||||
|
"name": "type",
|
||||||
|
"message": "Type d'évaluation",
|
||||||
|
"default": default.get("type", "DS"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input",
|
||||||
|
"name": "_date",
|
||||||
|
"message": "Date (%y%m%d)",
|
||||||
|
"validate": lambda x: (len(x) == 6) and x.isdigit(),
|
||||||
|
"default": default.get("_date", datetime.today().strftime("%y%m%d")),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "input",
|
||||||
|
"name": "ExQty",
|
||||||
|
"message": "Nombre d'exercice",
|
||||||
|
"validate": lambda x: x.isdigit(),
|
||||||
|
"default": default.get("ExQty", "1"),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
exam = prompt(questions)
|
||||||
|
exam["tribe"] = [t for t in config["tribes"] if exam["_tribe"] == t["name"]][0]
|
||||||
|
exam["date"] = datetime.strptime(exam["_date"], "%y%m%d")
|
||||||
|
|
||||||
|
return exam
|
||||||
|
|
||||||
|
|
||||||
|
def prompt_exercise(number=1):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def prompt_question():
|
||||||
|
pass
|
@ -3,15 +3,12 @@
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import yaml
|
|
||||||
import sys
|
import sys
|
||||||
import papermill as pm
|
import papermill as pm
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
CONFIGPATH = "recoconfig.yml"
|
from .getconfig import config
|
||||||
|
from .prompts import prompt_exam
|
||||||
with open(CONFIGPATH, "r") as config:
|
|
||||||
config = yaml.load(config, Loader=yaml.FullLoader)
|
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
@click.group()
|
||||||
@ -26,6 +23,21 @@ def print_config():
|
|||||||
click.echo(config)
|
click.echo(config)
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
def setup():
|
||||||
|
"""Setup the environnement using recoconfig.yml"""
|
||||||
|
for tribe in config["tribes"]:
|
||||||
|
Path(tribe["name"]).mkdir(exist_ok=True)
|
||||||
|
if not Path(tribe["students"]).exists():
|
||||||
|
print(f"The file {tribe['students']} does not exists")
|
||||||
|
|
||||||
|
|
||||||
|
@cli.command()
|
||||||
|
def new_exam():
|
||||||
|
""" Create new exam csv file """
|
||||||
|
exam = prompt_exam()
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.argument("csv_file")
|
@click.argument("csv_file")
|
||||||
def report(csv_file):
|
def report(csv_file):
|
||||||
@ -60,7 +72,10 @@ def report(csv_file):
|
|||||||
str(template),
|
str(template),
|
||||||
str(dest / f"{assessment}.ipynb"),
|
str(dest / f"{assessment}.ipynb"),
|
||||||
parameters=dict(
|
parameters=dict(
|
||||||
tribe=tribe, assessment=assessment, date=f"{date:%d/%m/%y}", csv_file=str(csv_file.absolute())
|
tribe=tribe,
|
||||||
|
assessment=assessment,
|
||||||
|
date=f"{date:%d/%m/%y}",
|
||||||
|
csv_file=str(csv_file.absolute()),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -78,4 +93,3 @@ def report(csv_file):
|
|||||||
# str(dest / f"{st}.ipynb"),
|
# str(dest / f"{st}.ipynb"),
|
||||||
# parameters=dict(tribe=tribe, student=st, source=str(tribe_dir.absolute())),
|
# parameters=dict(tribe=tribe, student=st, source=str(tribe_dir.absolute())),
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user