Skip to content

Commit

Permalink
Merge 081f331 into ac3bc44
Browse files Browse the repository at this point in the history
  • Loading branch information
stuhood committed Dec 9, 2020
2 parents ac3bc44 + 081f331 commit d08d2a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/python/pants/bin/pants_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import importlib
import locale
import os
import sys
import warnings
from textwrap import dedent

Expand All @@ -14,6 +15,8 @@ class PantsLoader:
ENTRYPOINT_ENV_VAR = "PANTS_ENTRYPOINT"
DEFAULT_ENTRYPOINT = "pants.bin.pants_exe:main"

RECURSION_LIMIT_ENV_VAR = "PANTS_RECURSION_LIMIT"

ENCODING_IGNORE_ENV_VAR = "PANTS_IGNORE_UNRECOGNIZED_ENCODING"

class InvalidLocaleError(Exception):
Expand Down Expand Up @@ -67,6 +70,10 @@ def ensure_locale(cls):
)
)

@classmethod
def set_recursion_limit(cls):
sys.setrecursionlimit(int(os.environ.get(cls.RECURSION_LIMIT_ENV_VAR, "10000")))

@staticmethod
def determine_entrypoint(env_var, default):
return os.environ.pop(env_var, default)
Expand All @@ -86,6 +93,7 @@ def load_and_execute(entrypoint):
def run(cls):
cls.setup_warnings()
cls.ensure_locale()
cls.set_recursion_limit()
entrypoint = cls.determine_entrypoint(cls.ENTRYPOINT_ENV_VAR, cls.DEFAULT_ENTRYPOINT)
cls.load_and_execute(entrypoint)

Expand Down
16 changes: 15 additions & 1 deletion tests/python/pants_test/bin/loader_integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Licensed under the Apache License, Version 2.0 (see LICENSE).

from pants.bin.pants_loader import PantsLoader
from pants.testutil.pants_integration_test import run_pants
from pants.testutil.pants_integration_test import PantsResult, run_pants


def test_invalid_locale() -> None:
Expand Down Expand Up @@ -49,3 +49,17 @@ def test_alternate_entrypoint_scrubbing() -> None:
)
pants_run.assert_success()
assert "PANTS_ENTRYPOINT=None" in pants_run.stdout


def test_recursion_limit() -> None:
def run(limit: str) -> PantsResult:
return run_pants(command=["help"], extra_env={"PANTS_RECURSION_LIMIT": limit})

# Large value succeeds.
run("100000").assert_success()
# Very small value fails in an arbitrary spot.
small_run = run("1")
small_run.assert_failure()
assert "RecursionError" in small_run.stderr
# Non integer value fails.
run("this isn't an int").assert_failure()

0 comments on commit d08d2a6

Please sign in to comment.