Skip to content

Commit

Permalink
Add new timeout_seconds support into primer.json
Browse files Browse the repository at this point in the history
- If present, will set forked process limit to that value in seconds
- Otherwise, stay with default 10 minutes (600 seconds)
  • Loading branch information
cooperlees committed Aug 15, 2021
1 parent e854fab commit 554c6e6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 8 additions & 2 deletions src/black_primer/lib.py
Expand Up @@ -28,6 +28,7 @@
import click


TEN_MINUTES_SECONDS = 600
WINDOWS = system() == "Windows"
BLACK_BINARY = "black.exe" if WINDOWS else "black"
GIT_BINARY = "git.exe" if WINDOWS else "git"
Expand All @@ -49,7 +50,7 @@ class Results(NamedTuple):

async def _gen_check_output(
cmd: Sequence[str],
timeout: float = 600,
timeout: float = TEN_MINUTES_SECONDS,
env: Optional[Dict[str, str]] = None,
cwd: Optional[Path] = None,
stdin: Optional[bytes] = None,
Expand Down Expand Up @@ -171,6 +172,11 @@ async def black_run(
else:
cmd.append(".")

timeout = (
project_config["timeout_seconds"]
if "timeout_seconds" in project_config
else TEN_MINUTES_SECONDS
)
with TemporaryDirectory() as tmp_path:
# Prevent reading top-level user configs by manipulating environment variables
env = {
Expand All @@ -183,7 +189,7 @@ async def black_run(
try:
LOG.debug(f"Running black for {project_name}: {' '.join(cmd)}")
_stdout, _stderr = await _gen_check_output(
cmd, cwd=cwd_path, env=env, stdin=stdin
cmd, cwd=cwd_path, env=env, stdin=stdin, timeout=timeout
)
except asyncio.TimeoutError:
results.stats["failed"] += 1
Expand Down
5 changes: 3 additions & 2 deletions src/black_primer/primer.json
@@ -1,5 +1,5 @@
{
"configuration_format_version": 20200509,
"configuration_format_version": 20210815,
"projects": {
"STDIN": {
"cli_arguments": ["--experimental-string-processing"],
Expand Down Expand Up @@ -62,7 +62,8 @@
"expect_formatting_changes": true,
"git_clone_url": "https://github.com/python/cpython.git",
"long_checkout": false,
"py_versions": ["3.9", "3.10"]
"py_versions": ["3.9", "3.10"],
"timeout_seconds": 900
},
"django": {
"cli_arguments": [
Expand Down

0 comments on commit 554c6e6

Please sign in to comment.