-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·90 lines (71 loc) · 2.44 KB
/
run.py
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
"""
Inspects a repository for NMinD compatibility. This script can check:
1) Presence of a license
2) Presence of a README
3) GitHub issues enabled / presence of an external issue tracker
4) Coding style (if language was provided)
"""
import click
from pathlib import Path
__version__ = "0.0.1"
CONTEXT_SETTINGS = {"help_option_names": ["-h", "--help"]}
def check_license(repo: Path) -> bool:
import requests
def check_readme(repo: Path) -> bool:
import requests
def check_issues(repo: str, alt_issues: str = None) -> bool:
# TODO: Query repo with GH API
import requests
def check_style(repo: Path, language: str) -> bool:
linters = {
"python": ["flake8", str(repo)],
}
lint_cmd = linters.get(language)
if lint_cmd is None:
raise NotImplementedError(
f"Checking coding style for {language} is not yet supported."
)
from shutil import which
import subprocess as sp
lint_prog = lint_cmd[0]
if which(lint_prog) is None:
raise RuntimeError(f"Linter {lint_prog} was not found on the system.")
proc = sp.run(lint_cmd, stdout=sp.PIPE, stderr=sp.PIPE)
return bool(proc.returncode)
# CLI
@click.group(context_settings=CONTEXT_SETTINGS)
@click.version_option(__version__, prog_name="nmind-code")
def cli():
"""Command-line interface for NMinD."""
pass
@cli.command(context_settings=CONTEXT_SETTINGS)
@click.argument(
"command",
type=click.Choice(("license", "readme", "issues", "style"), case_sensitive=False),
)
@click.option("--repo", help="Repository in GitHub notation (owner/repository)")
@click.option("--language", help="Language to check style")
@click.option(
"--local-path",
type=click.Path(file_okay=False),
default=Path(),
show_default=True,
help="Local path to repository",
)
@click.option(
"--alt-issues", default=None, help="Alternate site for user questions / bug reports"
)
def check(command, repo, language, local_path, alt_issues):
if command == "license":
return check_license(local_path)
if command == "readme":
return check_readme(local_path)
if command == "issues":
return check_issues(repo, alt_issues)
if command == "style":
assert language is not None, "Please specify the target programming language"
return check_style(local_path, language)
raise NotImplementedError(f"Command {command} not available")
if __name__ == "__main__":
check()