Skip to content

Commit 4977221

Browse files
authored
refactor(gazelle): report missing BUILD_WORKSPACE_DIRECTORY key more directly (#3240)
Replace `os.environ.get("BUILD_WORKSPACE_DIRECTORY")` with `os.environ["BUILD_WORKSPACE_DIRECTORY"]`. The former may return None if the environment variable is not set, in which case the code will crash with a TypeError when the line is run since the result is concatenated with a `pathlib.Path` object, and is therefore making it impossible to use rules_python_gazelle_plugin along with rules_mypy: These changes allow rules_mypy users to also use rules_python_gazelle_plugin without having to work around the type error. Now if the environment variable is not set, the code will still crash, but now with an error that better indicates the failed precondition, namely `KeyError("BUILD_WORKSPACE_DIRECTORY")` rather than `TypeError("unsupported operand type(s) for /: 'PosixPath' and 'NoneType')`.
1 parent 1169eec commit 4977221

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

gazelle/manifest/copy_to_source.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def copy_to_source(generated_relative_path: Path, target_relative_path: Path) ->
2020
generated_absolute_path = Path.cwd() / generated_relative_path
2121

2222
# Similarly, the target is relative to the source directory.
23-
target_absolute_path = os.getenv("BUILD_WORKSPACE_DIRECTORY") / target_relative_path
23+
target_absolute_path = os.environ["BUILD_WORKSPACE_DIRECTORY"] / target_relative_path
2424

2525
print(f"Copying {generated_absolute_path} to {target_absolute_path}")
2626
target_absolute_path.parent.mkdir(parents=True, exist_ok=True)

0 commit comments

Comments
 (0)