Skip to content

Commit 1a94ad4

Browse files
committed
Explicitly watch the python version file we read
If we read a python_version_file (specified with the defaults tag class or the default @@//:.python-version file), explicitly start watching that file. There are some circumstances where such a watch wouldn't be allowed, but since it's new functionality it doesn't break anything for anyone to insist on the watch. If a specific use case requires the relaxation of the requirement, that can always be considered later.
1 parent b5a337b commit 1a94ad4

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

python/private/python.bzl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def parse_modules(*, module_ctx, _fail = fail):
111111
if default_python_version_file:
112112
default_python_version = _one_or_the_same(
113113
default_python_version,
114-
module_ctx.read(default_python_version_file).strip(),
114+
module_ctx.read(default_python_version_file, watch = "yes").strip(),
115115
)
116116
if default_python_version_env:
117117
default_python_version = module_ctx.getenv(
@@ -121,7 +121,10 @@ def parse_modules(*, module_ctx, _fail = fail):
121121
if not default_python_version:
122122
fallback_python_version_file = module_ctx.path(Label("@@//:.python-version"))
123123
if fallback_python_version_file.exists:
124-
default_python_version = module_ctx.read(fallback_python_version_file).strip()
124+
default_python_version = module_ctx.read(
125+
fallback_python_version_file,
126+
watch = "yes",
127+
).strip()
125128

126129
seen_versions = {}
127130
for mod in module_ctx.modules:

tests/python/python_tests.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ _tests = []
2323
def _mock_mctx(*modules, environ = {}, mocked_files = {}):
2424
return struct(
2525
path = lambda x: struct(exists = x in mocked_files, _file = x),
26-
read = lambda x: mocked_files[x._file if "_file" in dir(x) else x],
26+
read = lambda x, watch = None: mocked_files[x._file if "_file" in dir(x) else x],
2727
getenv = environ.get,
2828
os = struct(environ = environ),
2929
modules = [

0 commit comments

Comments
 (0)