-
-
Notifications
You must be signed in to change notification settings - Fork 611
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support custom python-executable (#1333)
- Loading branch information
Showing
7 changed files
with
238 additions
and
4 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
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# WARNING! BE CAREFUL UPDATING THIS FILE | ||
# Consider possible security implications associated with subprocess module. | ||
import subprocess # nosec | ||
|
||
|
||
def run_python_snippet(python_executable: str, code_to_run: str) -> str: | ||
""" | ||
Executes python code by calling python_executable with '-c' option. | ||
""" | ||
py_exec_cmd = python_executable, "-c", code_to_run | ||
|
||
# subprocess module should never be used with untrusted input | ||
return subprocess.check_output( # nosec | ||
py_exec_cmd, | ||
shell=False, | ||
universal_newlines=True, | ||
) |
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
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
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import sys | ||
|
||
from piptools.subprocess_utils import run_python_snippet | ||
|
||
|
||
def test_run_python_snippet_returns_multilne(): | ||
result = run_python_snippet(sys.executable, r'print("MULTILINE\nOUTPUT", end="")') | ||
assert result == "MULTILINE\nOUTPUT" |
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