Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_pyflakes_syntax(self) -> None:
rootPath = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
pyflakes.api.checkRecursive([rootPath + '/qupulse/', rootPath + '/tests/'], Reporter(sys.stdout, sys.stderr))
def check(text):
pyflakes.api.check(text,"test.py")
def run(self):
"""Execute pyflakes check."""
# Don't import the pyflakes code until now because setup.py needs to be
# able to install Pyflakes if its missing. This localizes the import to
# only after the setuptools code has run and verified everything is
# installed.
from pyflakes import api
from pyflakes import reporter
# Run the Pyflakes check against our package and check its output
val = api.checkRecursive([PACKAGE], reporter._makeDefaultReporter())
if val > 0:
sys.exit("ERROR: Pyflakes failed with exit code {}".format(val))
def main():
checker.Checker.builtIns = (set(dir(builtins)) |
set(['_']) |
set(checker._MAGIC_GLOBALS))
sys.exit(pyflakes.api.main())
del_files_str = git.Git(settings.BASE_DIR).ls_files("-d", "-k")
files = set(
pathlib.Path(p) for p in files_str.splitlines() if p[-3:] == ".py"
) - set(pathlib.Path(p) for p in del_files_str.splitlines())
num_lint_errors = 0
num_black_formats = 0
for p in files:
if not options["no_fix"]:
changed = black.format_file_in_place(
p, False, black.FileMode(), black.WriteBack.YES
)
if changed:
num_black_formats += 1
self.stdout.write("%s: Black formatted file" % str(p))
if not options["no_lint"]:
num_lint_errors += pyflakes.checkPath(str(p))
if num_black_formats:
raise CommandError("%i file(s) formatted by Black" % num_black_formats)
if num_lint_errors:
raise CommandError("%i liniting error(s) found" % num_lint_errors)
def pyls_lint(document):
reporter = PyflakesDiagnosticReport(document.lines)
pyflakes_api.check(
document.source.encode("utf-8"), document.path, reporter=reporter
)
return reporter.diagnostics
def inspect_code(self, code):
code = self._append_globals(code)
rep = reporter.Reporter(self.flakes_stdout.reset(), self.flakes_stderr.reset())
api.check(code, filename="block", reporter=rep)
# Match names
p = r"'(.+?)'"
out = rep._stdout()
# Using set to avoid repeating same entry if same missing name is called multiple times
undef_vars = set()
for l in list(filter(lambda a: a != '\n' and 'undefined name' in a, out)):
var_search = re.search(p, l)
undef_vars.add(var_search.group(1))
return set(undef_vars)
def runOnce(self):
reporter = Reporter()
pyflakes.api.check(self._document.documentText(),
self._document.documentMetaInfo("Filename").data(),
reporter=reporter)
return reporter.errors()
while EMPTY_RE.match(lines[curr_idx-1]):
bad_idx.append(curr_idx-1)
curr_idx -= 1
for idx in reversed(sorted(bad_idx)):
del lines[idx]
for idx, line in reversed(list(enumerate(lines[:]))):
if FUNCDEF_RE.match(line):
lines.insert(idx, '\n')
lines.insert(idx, '\n')
elif BAD_RE.search(line):
del lines[idx]
reset_lists()
pyfl.check(''.join(lines), output_file_path, GLOBAL_REPORTER)
bad_idx = []
while GLOBAL_REPORTER.indent_error:
do_break = False
for idx, _ in GLOBAL_REPORTER.indent_error:
curr_idx = idx-1
while not LINE_RE.match(lines[curr_idx-1]) and curr_idx >= 0:
curr_idx -= 1
final_idx = curr_idx - 1
if idx - final_idx == 2 and IF_RE.match(lines[final_idx]) and ELSE_RE.match(lines[idx-1]):
print(basename, lines[idx-1], lines[final_idx])
bad_idx.append(idx-1)
bad_idx.append(final_idx)
elif IF_RE.match(lines[final_idx]):
bad_idx.append(final_idx)
else:
do_break = True
def main(files):
"""Call main in all given files."""
t1 = time.time()
for fn in files:
# Report the file name.
assert g.os_path_exists(fn), fn
sfn = g.shortFileName(fn)
s = g.readFileIntoEncodedString(fn)
if s and s.strip():
r = reporter.Reporter(errorStream=sys.stderr, warningStream=sys.stderr)
api.check(s, sfn, r)
t2 = time.time()
n = len(files)
print('%s file%s, time: %5.2f sec.' % (n, g.plural(n), t2 - t1))
#@+node:ekr.20160518000549.14: ** report_version