2022-07-31 21:35:18 +02:00
|
|
|
import flake8.main.application
|
2021-12-26 19:49:16 +01:00
|
|
|
import os
|
2021-12-26 19:49:19 +01:00
|
|
|
import subprocess
|
2022-07-31 21:35:18 +02:00
|
|
|
import tempfile
|
2021-12-26 19:49:16 +01:00
|
|
|
from checkpackagelib.base import _Tool
|
|
|
|
|
|
|
|
|
|
|
|
class NotExecutable(_Tool):
|
2022-07-31 21:35:16 +02:00
|
|
|
def ignore(self):
|
|
|
|
return False
|
|
|
|
|
2021-12-26 19:49:16 +01:00
|
|
|
def run(self):
|
2022-07-31 21:35:16 +02:00
|
|
|
if self.ignore():
|
|
|
|
return
|
2021-12-26 19:49:16 +01:00
|
|
|
if os.access(self.filename, os.X_OK):
|
2021-12-26 19:49:17 +01:00
|
|
|
return ["{}:0: This file does not need to be executable{}".format(self.filename, self.hint())]
|
2021-12-26 19:49:19 +01:00
|
|
|
|
|
|
|
|
2022-07-31 21:35:18 +02:00
|
|
|
class Flake8(_Tool):
|
|
|
|
def run(self):
|
|
|
|
with tempfile.NamedTemporaryFile() as output:
|
|
|
|
app = flake8.main.application.Application()
|
|
|
|
app.run(['--output-file={}'.format(output.name), self.filename])
|
|
|
|
stdout = output.readlines()
|
|
|
|
processed_output = [str(line.decode().rstrip()) for line in stdout if line]
|
|
|
|
if len(stdout) == 0:
|
|
|
|
return
|
|
|
|
return ["{}:0: run 'flake8' and fix the warnings".format(self.filename),
|
|
|
|
'\n'.join(processed_output)]
|
|
|
|
|
|
|
|
|
2021-12-26 19:49:19 +01:00
|
|
|
class Shellcheck(_Tool):
|
|
|
|
def run(self):
|
|
|
|
cmd = ['shellcheck', self.filename]
|
|
|
|
try:
|
|
|
|
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
stdout = p.communicate()[0]
|
|
|
|
processed_output = [str(line.decode().rstrip()) for line in stdout.splitlines() if line]
|
|
|
|
if p.returncode == 0:
|
|
|
|
return
|
|
|
|
return ["{}:0: run 'shellcheck' and fix the warnings".format(self.filename),
|
|
|
|
'\n'.join(processed_output)]
|
|
|
|
except FileNotFoundError:
|
|
|
|
return ["{}:0: failed to call 'shellcheck'".format(self.filename)]
|