forked from rubik/radon
-
Notifications
You must be signed in to change notification settings - Fork 1
/
codeclimate-radon
executable file
·49 lines (40 loc) · 1.6 KB
/
codeclimate-radon
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
#!/usr/bin/env python3
import json
import os.path
import shlex
import sys
threshold = "b"
binstub = "radon3"
include_paths = ["."]
if os.path.exists("/config.json"):
contents = open("/config.json").read()
config = json.loads(contents)
if config.get("config"):
if config["config"].get("threshold"):
threshold = config["config"]["threshold"].lower()
if config["config"].get("python_version"):
version = config["config"].get("python_version")
if version == "2" or version == 2:
binstub = "radon2"
elif version != "3" and version != 3:
sys.exit("Invalid python_version; must be either 2 or 3")
if config["config"].get("encoding"):
encoding = config["config"].get("encoding")
os.environ["RADONFILESENCODING"] = encoding
if config.get("include_paths"):
config_paths = config.get("include_paths")
python_paths = []
for i in config_paths:
ext = os.path.splitext(i)[1]
if os.path.isdir(i) or "py" in ext:
python_paths.append(i)
include_paths = python_paths
include_paths = config.get("include_paths", ["."])
include_paths = [shlex.quote(path) for path in include_paths
if os.path.isdir(path) or path.endswith(".py")]
if len(include_paths) > 0:
paths = " ".join(include_paths)
print("Running {0}...".format(binstub), file = sys.stderr)
os.system("{0} cc {1} -n{2} --codeclimate".format(binstub, paths, threshold))
else:
print("Empty workspace; skipping...", file = sys.stderr)