Skip to content

Commit aef86d4

Browse files
committed
pre-commit
1 parent b9ca395 commit aef86d4

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

python/private/repl_template.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ def start_repl():
1414
cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
1515
sys.stderr.write("Python %s on %s\n%s\n" % (sys.version, sys.platform, cprt))
1616

17+
# If there's a PYTHONSTARTUP script, we need to capture the new variables
18+
# that it defines.
1719
new_globals = {}
1820

1921
# Simulate Python's behavior when a valid startup script is defined by the
@@ -32,7 +34,11 @@ def start_repl():
3234
eval(compiled_code, new_globals)
3335

3436
bazel_runfiles = runfiles.Create()
35-
runpy.run_path(bazel_runfiles.Rlocation(STUB_PATH), init_globals=new_globals, run_name="__main__")
37+
runpy.run_path(
38+
bazel_runfiles.Rlocation(STUB_PATH),
39+
init_globals=new_globals,
40+
run_name="__main__",
41+
)
3642

3743

3844
if __name__ == "__main__":

tests/repl/repl_test.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import sys
44
import tempfile
55
import unittest
6-
from typing import Iterable
76
from pathlib import Path
7+
from typing import Iterable
88

99
from python import runfiles
1010

@@ -21,6 +21,7 @@
2121
foo = 1234
2222
"""
2323

24+
2425
class ReplTest(unittest.TestCase):
2526
def setUp(self):
2627
self.repl = rfiles.Rlocation("rules_python/python/bin/repl")
@@ -87,9 +88,12 @@ def test_pythonstartup_gets_executed(self):
8788
env = os.environ.copy()
8889
env["PYTHONSTARTUP"] = str(pythonstartup)
8990

90-
result = self.run_code_in_repl([
91-
"print(f'The value of foo is {foo}')",
92-
], env=env)
91+
result = self.run_code_in_repl(
92+
[
93+
"print(f'The value of foo is {foo}')",
94+
],
95+
env=env,
96+
)
9397

9498
self.assertIn("The value of foo is 1234", result)
9599

@@ -109,8 +113,9 @@ def test_pythonstartup_doesnt_leak(self):
109113
for var_name in ("exitmsg", "sys", "code", "bazel_runfiles", "STUB_PATH"):
110114
with self.subTest(var_name=var_name):
111115
result = self.run_code_in_repl([f"print({var_name})"], env=env)
112-
self.assertIn(f"NameError: name '{var_name}' is not defined", result)
113-
116+
self.assertIn(
117+
f"NameError: name '{var_name}' is not defined", result
118+
)
114119

115120

116121
if __name__ == "__main__":

0 commit comments

Comments
 (0)