What changed, and why it matters
This commit is a small code cleanup that changes how the app finds the project root directory. It replaces a method based on the current working directory with one based on the location of the source file itself. There is no security issue visible in the change.
No security action needed. Treat as a normal refactoring review.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch refactors Version._get_dot_git_dir() and Version._get_last_src_edit() in src/seedsigner/helpers/version.py to derive the project root from file rather than os.getcwd(). It removes conditional logic that adjusted for different runtime working directories and normalizes the path calculation. The test file only has a whitespace fix. No security-sensitive behavior is introduced or removed.
Changed components
src/seedsigner/helpers/version.pyInspect captured patch +8 / −13
diff --git a/src/seedsigner/helpers/version.py b/src/seedsigner/helpers/version.py
index db1d4ab..a807554 100644
--- a/src/seedsigner/helpers/version.py
+++ b/src/seedsigner/helpers/version.py
@@ -22,14 +22,11 @@ class Version:
@classmethod
def _get_dot_git_dir(cls) -> str:
- # .git will be in the project root, if it exists
- git_HEAD_dir = os.getcwd()
+ # If it exists, the .git dir will be in the project root
+ path = os.path.dirname(os.path.abspath(__file__))
+ project_root = path.rsplit("/src", 1)[0]
- # Main app runs from src/ dir, tests and screenshot generator from project root
- if "src" in git_HEAD_dir:
- git_HEAD_dir = git_HEAD_dir.rsplit("src", 1)[0]
-
- return os.path.join(git_HEAD_dir, ".git")
+ return os.path.join(project_root, ".git")
@classmethod
@@ -96,10 +93,8 @@ class Version:
Recursively scan the src/ directory for the most recent python file edit time.
"""
try:
- src_path = os.getcwd()
- if "src" not in src_path:
- # Screenshot generator runs from the project root
- src_path = os.path.join(src_path, "src")
+ path = os.path.dirname(os.path.abspath(__file__))
+ src_path = path.rsplit("/src", 1)[0] + "/src"
last_modified = 0.0
num_files = 0
@@ -111,7 +106,7 @@ class Version:
num_files += 1
filepath = os.path.join(dirpath, filename)
- # getmtime
+ # getmtime returns the file's last modified time
file_mtime = os.path.getmtime(filepath)
last_modified = max(file_mtime, last_modified)
diff --git a/tests/test_version.py b/tests/test_version.py
index 8006966..4d450d6 100644
--- a/tests/test_version.py
+++ b/tests/test_version.py
@@ -65,7 +65,7 @@ class TestVersion(BaseTest):
with mock.patch.object(Version, '_get_matching_tag', return_value=tag_name):
version = Version.get_version()
assert version == tag_name
-
+
def test_get_last_src_edit(self):
"""
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.