Skip to content

cmd.create

cmd.create¤

describe_dataset() ¤

describe_dataset asks the user to specify some basic info about the dataset

Source code in dataherb/cmd/create.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def describe_dataset() -> dict:
    """
    describe_dataset asks the user to specify some basic info about the dataset
    """
    questions = [
        inquirer.List(
            "source",
            message="Where is/will be the dataset synced to?",
            choices=["git", "s3"],
        ),
        inquirer.Text("name", message="How would you like to name the dataset?"),
        inquirer.Text("id", message="Please specify a unique id for the dataset"),
        inquirer.Text(
            "description",
            message="What is the dataset about? This will be the description of the dataset.",
        ),
        inquirer.Text(
            "uri",
            message="What is the dataset's URI? This will be the URI of the dataset.",
        ),
    ]

    answers = inquirer.prompt(questions)

    metadata_uri = get_metadata_uri(answers)

    meta = {
        "source": answers.get("source"),
        "name": answers.get("name", ""),
        "id": answers["id"],
        "description": answers.get("description", ""),
        "uri": answers.get("uri", ""),
        "metadata_uri": metadata_uri,
    }

    return meta

get_metadata_uri(answers, branch='main') ¤

get_metadata_uri reconstructs the datapackage uri from the user's answers.

Parameters:

Name Type Description Default
answers dict

answers from inquirer prompt

required
Source code in dataherb/cmd/create.py
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def get_metadata_uri(answers: dict, branch: str = "main") -> str:
    """
    get_metadata_uri reconstructs the datapackage uri from the user's answers.

    :param answers: answers from inquirer prompt
    """

    if answers.get("source") == "git":
        git_repo_link = answers.get("uri", "")
        git_repo = "/".join(git_repo_link[:-4].split("/")[-2:])
        metadata_uri = (
            f"https://raw.githubusercontent.com/{git_repo}/{branch}/dataherb.json"
        )
    elif answers.get("source") == "s3":
        s3_uri = answers.get("uri", "")
        if s3_uri.endswith("/"):
            s3_uri = s3_uri[:-1]
        metadata_uri = f"{s3_uri}/dataherb.json"
    else:
        click.echo(f'source type {answers.get("source")} is not supported.')

    return metadata_uri