This repository has been archived by the owner on Dec 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable black after AWS lambda support has been readded
See also: pfs/black@c0a7582e3d4cc8bec3b7f5a6c52b36880dcb57d7
- Loading branch information
Showing
4 changed files
with
8 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# black -- Decommissioned | ||
# black | ||
|
||
Black is no longer supported, due to it's lack of single processing support, see also https://github.com/psf/black/issues/421 | ||
Python's black linter run on AWS lambda. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,5 @@ | ||
#!/usr/bin/env python | ||
"""Lambda function that executes Black, a static file linter.""" | ||
import logging | ||
import os | ||
import resource | ||
import subprocess | ||
import sys | ||
import glob | ||
from lintipy import CheckRun | ||
|
||
from lintipy import CheckRun, COMPLETED, TIMED_OUT | ||
|
||
root_logger = logging.getLogger('') | ||
logger = logging.getLogger('black') | ||
root_logger.setLevel(logging.DEBUG) | ||
root_logger.addHandler(logging.StreamHandler(sys.stdout)) | ||
|
||
|
||
class BlackCheckRun(CheckRun): | ||
cmd_timeout = 1 | ||
|
||
def run_process(self, code_path): | ||
code = 0 | ||
cmd = ' '.join(('python', '-m', self.cmd) + self.cmd_args) | ||
log = "$ %s .\n" % cmd | ||
for file_name in glob.glob(os.path.join(code_path, '**/**.py'), recursive=True): | ||
if os.path.isfile(file_name): | ||
try: | ||
logger.info('Running: %s', cmd) | ||
process = subprocess.run( # nosec | ||
('python', '-m', self.cmd) + self.cmd_args + (file_name,), | ||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, | ||
cwd=code_path, env=self.get_env(), | ||
timeout=self.cmd_timeout, | ||
) | ||
except subprocess.TimeoutExpired: | ||
self.update_check_run( | ||
COMPLETED, 'Command timed out after %ss' % self.cmd_timeout, TIMED_OUT | ||
) | ||
raise | ||
else: | ||
info = resource.getrusage(resource.RUSAGE_CHILDREN) | ||
lines = process.stdout.decode().splitlines() | ||
log += '\n'.join(lines[:-2]) | ||
logger.debug(log) | ||
logger.debug('exit %s', process.returncode) | ||
logger.info( | ||
'linter exited with status code %s in %ss' % (process.returncode, info.ru_utime) | ||
) | ||
if process.returncode != 0: | ||
code = process.returncode | ||
return code, log | ||
|
||
|
||
handle = BlackCheckRun.as_handler( | ||
'black', | ||
'black', '--check', '--diff', | ||
) | ||
handle = CheckRun.as_handler("black", "black", "--check", "--diff", ".") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
'''black will throw an error''' | ||
"""black will throw an error""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters