-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathsourceant
More file actions
executable file
·70 lines (55 loc) · 2.04 KB
/
Copy pathsourceant
File metadata and controls
executable file
·70 lines (55 loc) · 2.04 KB
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
#!/usr/bin/env python3
import click
import sys
import subprocess
from src.config.settings import DATABASE_URL, STATELESS_MODE
from src.utils.logger import logger
from src.utils.migration_paths import resolve_version_locations
from alembic.config import Config, CommandLine
@click.group()
def cli():
pass
@click.command(name="db",
context_settings={"allow_extra_args": True, "ignore_unknown_options": True})
@click.pass_context
def db_command(ctx):
if STATELESS_MODE:
print("Application is in STATELESS_MODE. Skipping database command.")
logger.warning("Application is in STATELESS_MODE. Skipping database command.")
sys.exit(0)
if not DATABASE_URL:
print("DATABASE_URL not set, skipping database command.")
logger.warning("DATABASE_URL not set, skipping database command.")
sys.exit(0)
sys.argv = ["alembic"] + ctx.args
cmd = CommandLine()
options = cmd.parser.parse_args(ctx.args)
cfg = Config("alembic.ini", cmd_opts=options)
cfg.set_main_option("version_locations", " ".join(resolve_version_locations()))
fn, positional, kwarg = options.cmd
fn(cfg, *[getattr(options, k) for k in positional], **{k: getattr(options, k) for k in kwarg})
sys.exit(0)
@click.group(name='code')
def code_group():
pass
@click.command(name="lint")
def lint_command():
try:
subprocess.run(["black", "--check", "."], check=True)
except subprocess.CalledProcessError as e:
print("\nLinting failed! Run 'sourceant code lint:fix' to automatically fix linting issues.")
sys.exit(e.returncode)
@click.command(name="lint:fix")
def lint_fix_command():
try:
subprocess.run(["black", "."], check=True)
print("Linting issues fixed successfully.")
except subprocess.CalledProcessError as e:
print("Error while fixing linting issues:")
sys.exit(e.returncode)
cli.add_command(db_command)
code_group.add_command(lint_command)
code_group.add_command(lint_fix_command)
cli.add_command(code_group)
if __name__ == "__main__":
cli()