Skip to content

Commit

Permalink
Add PDOC_ALLOW_EXEC escape hatch, fix #450 (#451)
Browse files Browse the repository at this point in the history
* add PDOC_ALLOW_EXEC escape hatch, fix #450

* [autofix.ci] apply automated fixes

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
mhils and autofix-ci[bot] authored Nov 5, 2022
1 parent 316554d commit 5f78c54
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
- Fix handling of type annotations in nested classes.
([#440](https://github.com/mitmproxy/pdoc/issues/440), [@mhils](https://github.com/mhils))
- `Doc.type` is now `Doc.kind` to avoid confusion with `builtins.type`.
- The new `PDOC_ALLOW_EXEC` environment variable provides an escape hatch for
modules that cannot be imported without executing subprocesses.
([#450](https://github.com/mitmproxy/pdoc/issues/450), [@mhils](https://github.com/mhils))

# 2022-09-20: pdoc 12.2.0

Expand Down
9 changes: 8 additions & 1 deletion pdoc/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,14 @@ def __init__(self, *args, **kwargs): # pragma: no cover
"git",
)
)
if not command_allowed:
if not command_allowed and os.environ.get("PDOC_ALLOW_EXEC", "") == "":
# sys.stderr is patched, so we need to unpatch it for printing a warning.
with patch("sys.stderr", new=sys.__stderr__):
warnings.warn(
f"Suppressed execution of {args[0]!r} during import. "
f"Set PDOC_ALLOW_EXEC=1 as an environment variable to allow subprocess execution.",
stacklevel=2,
)
kwargs["executable"] = self._noop_exe
super().__init__(*args, **kwargs)

Expand Down

0 comments on commit 5f78c54

Please sign in to comment.