Skip to content

Commit 17972f5

Browse files
authored
Fix: preserve absolute Path object for tfdir (#91)
* Fix: preserve absolute Path object for tfdir - Ensure `_abspath` returns the original `Path` object when it's absolute, reverting the modernization regression. - Cast `self.tfdir` to `str` before encoding to prevent `AttributeError` when cache is enabled. - Add test cases to verify both behaviors. * Chore: add missing license boilerplate to new files * Chore: add GEMINI.md with CLI instructions
1 parent 4d4fca5 commit 17972f5

4 files changed

Lines changed: 55 additions & 2 deletions

File tree

.github/workflows/publish-pypi.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
name: Publish to PyPI
216

317
on:

GEMINI.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Gemini CLI Instructions for terraform-python-testing-helper
2+
3+
- **Git Workflow:** Never use `git commit --amend`. Always create a new commit and push to the same branch to update an existing Pull Request.
4+
- **File Editing:** Always use the `replace` tool (or `write_file` for new files) for file edits. Do NOT use shell heredocs (`cat << 'EOF'`) or inline Python scripts to modify files.
5+
- **Copyright Boilerplate:** All new files must include the Apache 2.0 license boilerplate at the top. Ensure the copyright year is current (e.g., 2026).
6+
- **Linting:** Always run the project's linters before committing changes. Specifically, check formatting with `yapf --diff --recursive --parallel *.py test` and verify license headers with `python3 .github/workflows/scripts/check_boilerplate.py .`.
7+
- **Regressions & Testing:** When fixing a regression, fix it at the source library level. Do not modify the caller's code to work around the issue. Always create a reliable test case that reproduces the error before implementing the fix.

test/test_tfdir_path.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Copyright 2026 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import tempfile
16+
from pathlib import Path
17+
import tftest
18+
19+
20+
def test_tfdir_as_path():
21+
with tempfile.TemporaryDirectory() as tmpdir:
22+
tmpdir_path = Path(tmpdir).resolve()
23+
tf = tftest.TerraformTest(tmpdir_path)
24+
# The regression: tf.tfdir / 'something' throws TypeError
25+
# if tf.tfdir is converted to a string.
26+
assert (tf.tfdir / 'something') == tmpdir_path / 'something'
27+
28+
29+
def test_tfdir_as_str():
30+
with tempfile.TemporaryDirectory() as tmpdir:
31+
tf = tftest.TerraformTest(tmpdir)
32+
assert isinstance(tf.tfdir, str)

tftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,7 @@ def _abspath(self, path):
349349
"""Make relative path absolute from base dir."""
350350
path_obj = Path(path)
351351
if path_obj.is_absolute():
352-
return str(path_obj)
352+
return path
353353
return str(Path(self._basedir) / path)
354354

355355
def _dirhash(self, directory, hash, ignore_hidden=False,
@@ -429,7 +429,7 @@ def cache(self, **kwargs):
429429
return func(self, **kwargs)
430430

431431
cache_dir = self.cache_dir / \
432-
Path(sha1(self.tfdir.encode("cp037")).hexdigest()) / \
432+
Path(sha1(str(self.tfdir).encode("cp037")).hexdigest()) / \
433433
Path(func.__name__)
434434
cache_dir.mkdir(parents=True, exist_ok=True)
435435

0 commit comments

Comments
 (0)