|
@@ -9,17 +9,40 @@ import java.util.UUID;
|
|
|
@Slf4j
|
|
|
public class PythonUtil {
|
|
|
|
|
|
+ /*
|
|
|
+ C:惯例,违反了编码风格标准
|
|
|
+ R:重构,代码非常糟糕
|
|
|
+ W:警告,某些 Python 特定的问题
|
|
|
+ E:错误,很可能是代码中的错误
|
|
|
+ F:致命错误,阻止 Pylint 进一步运行的错误
|
|
|
+ */
|
|
|
+
|
|
|
+ public static String LINE_TOO_LONG = "C0301";
|
|
|
+ public static String C = "C";
|
|
|
+ public static String R = "R";
|
|
|
+ public static String W = "W";
|
|
|
+ public static String E = "E";
|
|
|
+ public static String F = "F";
|
|
|
+ public static String PASS = "Your code has been rated at 10.00/10";
|
|
|
+
|
|
|
/**
|
|
|
* @param pythonCode python 代码
|
|
|
+ * @param disables 忽略指定等级的日志
|
|
|
*/
|
|
|
@SneakyThrows
|
|
|
- public static String pylint(String pythonCode) {
|
|
|
+ public static String pylint(String pythonCode, String... disables) {
|
|
|
//1 把代码保存成本地文件
|
|
|
String filePath = "/tmp/" + UUID.randomUUID().toString().replace("-", "") + ".py";
|
|
|
FileUtil.writeStringToLocalFile(pythonCode, filePath);
|
|
|
//2 执行命令检查格式
|
|
|
LinuxUtil.execute("apt install python-pip");
|
|
|
LinuxUtil.execute("pip3 install pylint");
|
|
|
- return LinuxUtil.execute("pylint " + filePath);
|
|
|
+ StringBuilder command = new StringBuilder("pylint --disable=");
|
|
|
+ for (String disable : disables) {
|
|
|
+ command.append(disable).append(",");
|
|
|
+ }
|
|
|
+ command.append(" ").append(filePath);
|
|
|
+ return LinuxUtil.execute(command.toString());
|
|
|
}
|
|
|
}
|
|
|
+
|