Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repos:

# Python linting and formatting
- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: 'v0.15.0'
rev: 'v0.16.8'
hooks:
# Run the linter.
- id: ruff
Expand All @@ -30,6 +30,6 @@ repos:

# Shell formatting
- repo: https://github.com/scop/pre-commit-shfmt
rev: v3.12.0-2
rev: v3.14.1-1
hooks:
- id: shfmt-docker # Docker image (requires Docker to run)
15 changes: 2 additions & 13 deletions local_hooks/app_tests/app_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,8 @@
"type": "boolean"
},
"python_version": {
"oneOf": [
{
"type": "string",
"pattern": "^3(\\.\\d+)?(,\\s*3(\\.\\d+)?)*$"
},
{
"type": "array",
"items": {
"type": "string",
"pattern": "^3(\\.\\d+)?$"
}
}
]
"type": "string",
"pattern": "^3(\\.\\d+)?(,\\s*3(\\.\\d+)?)*$"
},
"latest_tested_versions": {
"type": "array",
Expand Down
23 changes: 23 additions & 0 deletions local_hooks/app_tests/json_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,29 @@ def _is_connector_template_placeholder(self) -> bool:
for field, value in CONNECTOR_TEMPLATE_IDENTITY.items()
)

@TestSuite.test(critical=False)
def check_python_version_format(self):
"""Normalizes Python versions to the string format accepted by Splunkbase"""
if self._parser.uv_lock_filepath:
return SKIP_SDK_APP

python_version = self._app_json.get("python_version")
if not isinstance(python_version, list) or not all(
isinstance(version, str) for version in python_version
):
return create_test_result_response(success=True, message=TEST_PASS_MESSAGE)

self._app_json["python_version"] = ", ".join(python_version)
self._parser.update_app_json(self._app_json)
return create_test_result_response(
success=False,
message=(
f'Converted "python_version" to the Splunkbase-compatible string format in '
f"{self._parser.app_json_name}"
),
fixed=True,
)

@staticmethod
def format_as_index(indices: list[Any], container: str = "schema") -> str:
"""
Expand Down
28 changes: 28 additions & 0 deletions local_hooks/tests/test_static_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,40 @@
from pathlib import Path

from local_hooks.app_tests.json_tests import JSONTests
from local_hooks.app_tests.utils.app_parser import AppParser

PRE_COMMIT_DIR = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))

logging.getLogger().setLevel(logging.INFO)


def test_python_version_array_is_rewritten_for_splunkbase(tmp_path: Path):
app_json_path = tmp_path / "app.json"
app_json_path.write_text(json.dumps({"python_version": ["3.9", "3.13"]}) + "\n")
suite = JSONTests.__new__(JSONTests)
suite._parser = AppParser(tmp_path)
suite._app_json = suite._parser.app_json

result = suite.check_python_version_format()

assert result["success"] is False
assert result["fixed"] is True
assert json.loads(app_json_path.read_text())["python_version"] == "3.9, 3.13"


def test_python_version_string_is_unchanged(tmp_path: Path):
app_json_path = tmp_path / "app.json"
app_json_path.write_text(json.dumps({"python_version": "3.9, 3.13"}) + "\n")
suite = JSONTests.__new__(JSONTests)
suite._parser = AppParser(tmp_path)
suite._app_json = suite._parser.app_json

result = suite.check_python_version_format()

assert result["success"] is True
assert app_json_path.read_text() == '{"python_version": "3.9, 3.13"}\n'


def test_python_script_is_valid_asset_configuration_type():
schema_path = Path(__file__).parents[1] / "app_tests" / "app_schema.json"
app_schema = json.loads(schema_path.read_text())
Expand Down
Loading