File: main.py

package info (click to toggle)
node-playwright 1.38.0%2Bds-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,728 kB
  • sloc: javascript: 114,018; sh: 899; java: 372; xml: 247; cs: 118; python: 29; makefile: 12
file content (34 lines) | stat: -rw-r--r-- 849 bytes parent folder | download
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
import json
import sys
import black

def check_code_snippet(code_snippet: str):
    try:
        formatted_code = black.format_str(code_snippet, mode=black.FileMode())
    except Exception as e:
        return {
            'status': 'error',
            'error': str(e),
        }
    if formatted_code.strip() == code_snippet.strip():
        return {
            'status': 'success',
        }
    return {
        'status': 'updated',
        'newCode': formatted_code,
    }


def main():
    code_snippets_path = sys.argv[1]
    if not code_snippets_path:
        print("No code snippets path provided")
        return
    code_snippets = json.load(open(code_snippets_path))
    formatted_codes = [check_code_snippet(snippet["code"]) for snippet in code_snippets]
    print(json.dumps(formatted_codes))


if __name__ == "__main__":
    main()