Skip to content
This repository has been archived by the owner on Dec 31, 2024. It is now read-only.

Commit

Permalink
Enable black after AWS lambda support has been readded
Browse files Browse the repository at this point in the history
See also: pfs/black@c0a7582e3d4cc8bec3b7f5a6c52b36880dcb57d7
  • Loading branch information
codingjoe committed Aug 29, 2020
1 parent 3b2c475 commit 7febb2a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 60 deletions.
4 changes: 2 additions & 2 deletions README.md
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.
57 changes: 3 additions & 54 deletions main.py
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", ".")
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
'''black will throw an error'''
"""black will throw an error"""
5 changes: 2 additions & 3 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
from pathlib import Path

import pytest

from main import BlackCheckRun
from lintipy import CheckRun

BASE_DIR = Path(os.path.dirname(__file__))


class TestBlackCheckRun:
@pytest.fixture
def handler(self):
return BlackCheckRun("black", "black", "--check", "--diff")
return CheckRun("black", "black", "--check", "--diff", "tests")

def test_run_process(self, handler):
code, output = handler.run_process(str(BASE_DIR / ".."))
Expand Down

0 comments on commit 7febb2a

Please sign in to comment.