File size: 2,248 Bytes
b72f4a5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
71
72
73
74
75
76
# Used for setting some constants for the project codebase
import toml
import typer
from pathlib import Path
from loguru import logger
from typing_extensions import Annotated

app = typer.Typer()

# Root Path
ROOT = Path(__file__).resolve().parents[1]

try:
    logger.info('Loading config.toml...')
    with open(ROOT / 'config.toml', 'r') as f:
        config = toml.load(f, dict)
        f.close()

    if 'repositories' not in config.keys() or \
        'bin_repo' not in config['repositories'] or \
        'ml_repo' not in config['repositories'] or \
        'ds_repo' not in config['repositories']:
        raise Exception('Malformed toml config file.')
    
    logger.success('config.toml loaded successfully.')
except Exception as e:
    logger.error(e)
    config = {
        'repositories': {
            'bin_repo': '',
            'ml_repo': '', 
            'ds_repo': ''
        }
    }

    with open(ROOT / 'config.toml', 'w') as f:
        toml.dump(config, f)
        f.close()


# HF Hub Repositories
BIN_REPO = config['repositories']['bin_repo']
ML_REPO = config['repositories']['ml_repo']
DATASET_REPO = config['repositories']['ds_repo']

@app.command()
def main(
    bin_repo: Annotated[str, typer.Option("--binary-repo", "-b")] = None,
    ml_repo: Annotated[str, typer.Option("--multilabel-regression-repo", "-m")] = None,
    ds_repo: Annotated[str, typer.Option("--dataset-repo", "-d")] = None
):
    toml_edited = False

    if bin_repo is not None and len(bin_repo) > 0:
        config['repositories']['bin_repo'] = bin_repo
        toml_edited = True
        logger.success(f'Successfully updated binary repository to {bin_repo}.')

    if ml_repo is not None and len(ml_repo) > 0:
        config['repositories']['ml_repo'] = ml_repo
        toml_edited = True
        logger.success(f'Successfully updated binary repository to {ml_repo}.')

    if ds_repo is not None and len(ds_repo) > 0:
        config['repositories']['ds_repo'] = ds_repo
        toml_edited = True
        logger.success(f'Successfully updated binary repository to "{ds_repo}".')

    if toml_edited:
        with open(ROOT / 'config.toml', 'w') as f:
            toml.dump(config, f)
            f.close()


if __name__ == "__main__":
    app()