| 1 |
|
| 2 |
|
| 3 |
import json |
| 4 |
import os.path |
| 5 |
import shlex |
| 6 |
import sys |
| 7 |
|
| 8 |
threshold = "b" |
| 9 |
binstub = "radon3" |
| 10 |
include_paths = ["."] |
| 11 |
|
| 12 |
if os.path.exists("/config.json"): |
| 13 |
contents = open("/config.json").read() |
| 14 |
config = json.loads(contents) |
| 15 |
|
| 16 |
if config.get("config"): |
| 17 |
if config["config"].get("threshold"): |
| 18 |
threshold = config["config"]["threshold"].lower() |
| 19 |
|
| 20 |
if config["config"].get("python_version"): |
| 21 |
version = config["config"].get("python_version") |
| 22 |
if version == "2" or version == 2: |
| 23 |
binstub = "radon2" |
| 24 |
elif version != "3" and version != 3: |
| 25 |
sys.exit("Invalid python_version; must be either 2 or 3") |
| 26 |
if config["config"].get("encoding"): |
| 27 |
encoding = config["config"].get("encoding") |
| 28 |
os.environ["RADONFILESENCODING"] = encoding |
| 29 |
|
| 30 |
if config.get("include_paths"): |
| 31 |
config_paths = config.get("include_paths") |
| 32 |
python_paths = [] |
| 33 |
for i in config_paths: |
| 34 |
ext = os.path.splitext(i)[1] |
| 35 |
if os.path.isdir(i) or "py" in ext: |
| 36 |
python_paths.append(i) |
| 37 |
include_paths = python_paths |
| 38 |
|
| 39 |
include_paths = config.get("include_paths", ["."]) |
| 40 |
include_paths = [shlex.quote(path) for path in include_paths |
| 41 |
if os.path.isdir(path) or path.endswith(".py")] |
| 42 |
|
| 43 |
if len(include_paths) > 0: |
| 44 |
paths = " ".join(include_paths) |
| 45 |
|
| 46 |
print("Running {0}...".format(binstub), file = sys.stderr) |
| 47 |
os.system("{0} cc {1} -n{2} --codeclimate".format(binstub, paths, threshold)) |
| 48 |
else: |
| 49 |
print("Empty workspace; skipping...", file = sys.stderr) |