This is an automated email from the ASF dual-hosted git repository.

sbp pushed a commit to branch sbp
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git


The following commit(s) were added to refs/heads/sbp by this push:
     new 9664bcb  Store the RAT command as a string on results, and add the 
scan directory
9664bcb is described below

commit 9664bcb9f51b7d13cd1c477d26a6f0d65c0750e9
Author: Sean B. Palmer <[email protected]>
AuthorDate: Thu Jan 29 20:41:02 2026 +0000

    Store the RAT command as a string on results, and add the scan directory
---
 atr/models/checkdata.py       |  3 ++-
 atr/tasks/checks/rat.py       |  4 +++-
 tests/unit/test_checks_rat.py | 44 +++++++++++++++++++++++++++----------------
 3 files changed, 33 insertions(+), 18 deletions(-)

diff --git a/atr/models/checkdata.py b/atr/models/checkdata.py
index 18703bf..0058225 100644
--- a/atr/models/checkdata.py
+++ b/atr/models/checkdata.py
@@ -40,4 +40,5 @@ class Rat(schema.Lax):
     warning: str | None = schema.default(None)
     unapproved_files: list[RatFileEntry] = schema.factory(list)
     unknown_license_files: list[RatFileEntry] = schema.factory(list)
-    command: list[str] = schema.factory(list)
+    command: str = schema.default("")
+    directory: str = schema.default("")
diff --git a/atr/tasks/checks/rat.py b/atr/tasks/checks/rat.py
index df80c13..3812157 100644
--- a/atr/tasks/checks/rat.py
+++ b/atr/tasks/checks/rat.py
@@ -18,6 +18,7 @@
 import asyncio
 import os
 import pathlib
+import shlex
 import subprocess
 import tempfile
 import xml.etree.ElementTree as ElementTree
@@ -525,6 +526,7 @@ def _synchronous_extract(
     # The unknown_license_files and unapproved_files contain FileEntry objects
     # The path is relative to scan_root, so we prepend the scan_root relative 
path
     scan_root_rel = os.path.relpath(scan_root, temp_dir)
+    result.directory = scan_root_rel
     if scan_root_rel != ".":
         for file in result.unknown_license_files:
             file.name = os.path.join(scan_root_rel, 
os.path.normpath(file.name))
@@ -533,7 +535,7 @@ def _synchronous_extract(
 
     result.excludes_source = excludes_source
     result.extended_std_applied = apply_extended_std
-    result.command = _sanitise_command_for_storage(command)
+    result.command = shlex.join(_sanitise_command_for_storage(command))
     return result
 
 
diff --git a/tests/unit/test_checks_rat.py b/tests/unit/test_checks_rat.py
index d550545..6039084 100644
--- a/tests/unit/test_checks_rat.py
+++ b/tests/unit/test_checks_rat.py
@@ -16,6 +16,7 @@
 # under the License.
 
 import pathlib
+import shlex
 
 import pytest
 
@@ -43,11 +44,13 @@ def rat_available() -> tuple[bool, bool]:
 def test_check_includes_command(rat_available: tuple[bool, bool]):
     _skip_if_unavailable(rat_available)
     result = rat._synchronous(str(TEST_ARCHIVE), [])
-    assert len(result.command) > 0
-    assert "java" in result.command
-    assert "-jar" in result.command
-    assert "--" in result.command
-    assert "." in result.command
+    command = _command_args(result.command)
+    assert len(command) > 0
+    assert "java" in command
+    assert "-jar" in command
+    assert "--" in command
+    assert "." in command
+    assert result.directory == "."
 
 
 def test_check_includes_excludes_source_none(rat_available: tuple[bool, bool]):
@@ -68,7 +71,8 @@ def 
test_excludes_archive_ignores_policy_when_file_exists(rat_available: tuple[b
     result = rat._synchronous(str(TEST_ARCHIVE_WITH_RAT_EXCLUDES), ["*.py", 
"*.txt"])
     assert result.excludes_source == "archive"
     # Should NOT use the RAT policy file
-    assert rat._POLICY_EXCLUDES_FILENAME not in result.command
+    command = _command_args(result.command)
+    assert rat._POLICY_EXCLUDES_FILENAME not in command
 
 
 def test_excludes_archive_uses_rat_excludes_file(rat_available: tuple[bool, 
bool]):
@@ -76,10 +80,12 @@ def 
test_excludes_archive_uses_rat_excludes_file(rat_available: tuple[bool, bool
     _skip_if_unavailable(rat_available)
     result = rat._synchronous(str(TEST_ARCHIVE_WITH_RAT_EXCLUDES), [])
     assert result.excludes_source == "archive"
-    assert "--input-exclude-file" in result.command
+    command = _command_args(result.command)
+    assert "--input-exclude-file" in command
     # Should use the RAT excludes file, not the RAT policy file
-    idx = result.command.index("--input-exclude-file")
-    assert result.command[idx + 1] == rat._RAT_EXCLUDES_FILENAME
+    idx = command.index("--input-exclude-file")
+    assert command[idx + 1] == rat._RAT_EXCLUDES_FILENAME
+    assert result.directory == "apache-test-0.2"
 
 
 def test_excludes_none_has_no_exclude_file(rat_available: tuple[bool, bool]):
@@ -87,10 +93,11 @@ def test_excludes_none_has_no_exclude_file(rat_available: 
tuple[bool, bool]):
     _skip_if_unavailable(rat_available)
     result = rat._synchronous(str(TEST_ARCHIVE), [])
     assert result.excludes_source == "none"
-    assert "--input-exclude-file" not in result.command
+    command = _command_args(result.command)
+    assert "--input-exclude-file" not in command
     # Should have neither excludes file in command
-    assert rat._RAT_EXCLUDES_FILENAME not in result.command
-    assert rat._POLICY_EXCLUDES_FILENAME not in result.command
+    assert rat._RAT_EXCLUDES_FILENAME not in command
+    assert rat._POLICY_EXCLUDES_FILENAME not in command
 
 
 def test_excludes_policy_uses_atr_rat_excludes(rat_available: tuple[bool, 
bool]):
@@ -99,12 +106,13 @@ def 
test_excludes_policy_uses_atr_rat_excludes(rat_available: tuple[bool, bool])
     # The second argument to rat._synchronous is a list of exclusions from 
policy
     result = rat._synchronous(str(TEST_ARCHIVE), ["*.py"])
     assert result.excludes_source == "policy"
-    assert "--input-exclude-file" in result.command
+    command = _command_args(result.command)
+    assert "--input-exclude-file" in command
     # Should use the RAT policy file, not the RAT excludes file
-    idx = result.command.index("--input-exclude-file")
-    assert result.command[idx + 1] == rat._POLICY_EXCLUDES_FILENAME
+    idx = command.index("--input-exclude-file")
+    assert command[idx + 1] == rat._POLICY_EXCLUDES_FILENAME
     # Should therefore NOT have the RAT excludes file in the command
-    assert rat._RAT_EXCLUDES_FILENAME not in result.command
+    assert rat._RAT_EXCLUDES_FILENAME not in command
 
 
 def test_sanitise_command_replaces_absolute_paths():
@@ -125,6 +133,10 @@ def test_sanitise_command_replaces_absolute_paths():
     assert result[6] == ".rat-excludes"
 
 
+def _command_args(command: str) -> list[str]:
+    return shlex.split(command)
+
+
 def _skip_if_unavailable(rat_available: tuple[bool, bool]) -> None:
     java_ok, jar_ok = rat_available
     if not java_ok:


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to