Skip to content
Open
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
28 changes: 28 additions & 0 deletions .github/actions/run-appinspect/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Run Splunk AppInspect
description: Package a mock app containing the SDK and its dependencies, then validate it with AppInspect.

inputs:
mock-app-path:
description: Path to app packaged for scanning with AppInspect
required: true
default: ./tests/system/test_apps/generating_app

runs:
using: composite
steps:
- name: Install AppInspect dependencies
shell: bash
run: sudo apt-get install -y libmagic1
- name: Install the SDK and its dependencies into the mock app
shell: bash
run: |
mkdir -p ${{ inputs.mock-app-path }}/bin/lib
uv pip install ".[openai, anthropic]" --target ${{ inputs.mock-app-path }}/bin/lib
- name: Package the mock app
shell: bash
run: |
cd ${{ inputs.mock-app-path }}
tar -czf mock_app.tgz --exclude="__pycache__" bin default metadata
- name: Validate the mock app with AppInspect
shell: bash
run: uvx splunk-appinspect inspect ${{ inputs.mock-app-path }}/mock_app.tgz --included-tags cloud
12 changes: 9 additions & 3 deletions .github/actions/setup-sdk-environment/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,24 @@ inputs:
python-version:
description: Python version used for this run
required: true
default: "3.13"
deps-group:
description: Dependency groups passed to `uv sync --group`
required: true
default: lint

runs:
using: composite
steps:
- uses: astral-sh/setup-uv@cec208311dfd045dd5311c1add060b2062131d57
with:
version: 0.11.6
activate-environment: true
python-version: ${{ inputs.python-version }}
- name: Install dependencies from the ${{ inputs.deps-group }} group(s)
run: SDK_DEPS_GROUP="${{ inputs.deps-group }}" make uv-sync-ci
activate-environment: true
enable-cache: true
cache-python: true
- name: Install dependencies from the ${{ inputs.deps-group }} group
shell: bash
env:
SDK_DEPS_GROUP: ${{ inputs.deps-group }}
run: make uv-sync-ci
18 changes: 3 additions & 15 deletions .github/workflows/appinspect.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Validate SDK with Splunk AppInspect
on: [ push, workflow_dispatch ]
on: [push, workflow_dispatch]

env:
PYTHON_VERSION: 3.13
MOCK_APP_PATH: ./tests/system/test_apps/generating_app

jobs:
appinspect:
Expand All @@ -14,16 +13,5 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
deps-group: lint
- name: Install splunk-appinspect dependencies
run: sudo apt-get install -y libmagic1
- name: Install packages for the mock app
run: |
mkdir -p ${{ env.MOCK_APP_PATH }}/bin/lib
uv pip install ".[openai, anthropic]" --target ${{ env.MOCK_APP_PATH }}/bin/lib
- name: Copy splunklib to a test app and package it as a mock app
run: |
cd ${{ env.MOCK_APP_PATH }}
tar -czf mock_app.tgz --exclude="__pycache__" bin default metadata
- name: Validate mock app with splunk-appinspect
run: uvx splunk-appinspect inspect ${{ env.MOCK_APP_PATH }}/mock_app.tgz
--included-tags cloud
- name: Run AppInspect
uses: ./.github/actions/run-appinspect
29 changes: 21 additions & 8 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
name: Publish SDK to Test PyPI
on: [workflow_dispatch]
name: Publish pre-release to Test PyPI
on: [push]
# push:
# branches:
# - develop
# - release/2.x
# workflow_dispatch:

env:
PYTHON_VERSION: 3.13

jobs:
publish-to-test-pypi:
publish-pre-release:
runs-on: ubuntu-latest
permissions:
id-token: write
id-token: write # Required for publishing
environment:
name: splunk-test-pypi
steps:
Expand All @@ -17,9 +22,17 @@ jobs:
with:
python-version: ${{ env.PYTHON_VERSION }}
deps-group: release
- name: Set temporary pre-release version
run: |
VERSION_BASE="$(uv version --short)"
RUN_NUMBER="${{ github.run_number }}"
COMMIT_SHA="$(git rev-parse --short HEAD)"
uv version --frozen "${VERSION_BASE}.dev${RUN_NUMBER}+g${COMMIT_SHA}"
- name: Build packages for distribution
run: uv build
- name: Publish packages to Test PyPI
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b
with:
repository-url: https://test.pypi.org/legacy/
- name: Run AppInspect
uses: ./.github/actions/run-appinspect
# - name: Publish packages to Test PyPI
# uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b
# with:
# repository-url: https://test.pypi.org/legacy/
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
publish-to-pypi:
runs-on: ubuntu-latest
permissions:
id-token: write
id-token: write # Required for publishing
environment:
name: splunk-pypi
steps:
Expand All @@ -21,6 +21,8 @@ jobs:
deps-group: release
- name: Build packages for distribution
run: uv build
- name: Run AppInspect
uses: ./.github/actions/run-appinspect
- name: Publish packages to PyPI
uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b
with:
Expand Down
106 changes: 53 additions & 53 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
name: Python SDK CI
on: [push, workflow_dispatch]
# name: Python SDK CI
# on: [push, workflow_dispatch]

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
# concurrency:
# group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
# cancel-in-progress: true

jobs:
test-stage:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.13]
splunk-version: [latest]
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
- uses: ./.github/actions/setup-sdk-environment
with:
python-version: ${{ matrix.python-version }}
deps-group: test
- name: Download Splunk MCP Server App
run: uv run ./scripts/download_splunk_mcp_server_app.py
env:
SPLUNKBASE_USERNAME: ${{ secrets.SPLUNKBASE_USERNAME }}
SPLUNKBASE_PASSWORD: ${{ secrets.SPLUNKBASE_PASSWORD }}
- name: Launch Splunk Docker instance
run: SPLUNK_VERSION=${{ matrix.splunk-version }} docker compose up -d
- name: Set up .env
run: cp .env.template .env
- name: Write internal AI secrets to .env
run: |
echo "internal_ai_app_key=$INTERNAL_AI_APP_KEY" >> .env
echo "internal_ai_client_id=$INTERNAL_AI_CLIENT_ID" >> .env
echo "internal_ai_client_secret=$INTERNAL_AI_CLIENT_SECRET" >> .env
echo "internal_ai_token_url=$INTERNAL_AI_TOKEN_URL" >> .env
echo "internal_ai_base_url=$INTERNAL_AI_BASE_URL" >> .env
env:
INTERNAL_AI_APP_KEY: ${{ secrets.INTERNAL_AI_APP_KEY }}
INTERNAL_AI_CLIENT_ID: ${{ secrets.INTERNAL_AI_CLIENT_ID }}
INTERNAL_AI_CLIENT_SECRET: ${{ secrets.INTERNAL_AI_CLIENT_SECRET }}
INTERNAL_AI_TOKEN_URL: ${{ secrets.INTERNAL_AI_TOKEN_URL }}
INTERNAL_AI_BASE_URL: ${{ secrets.INTERNAL_AI_BASE_URL }}
- name: Restore pytest cache
if: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/develop' }}
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae
with:
path: .pytest_cache
key: pytest-cache-${{ runner.os }}-py${{ matrix.python-version }}-${{ github.ref_name }}-${{ github.sha }}
restore-keys: |
pytest-cache-${{ runner.os }}-py${{ matrix.python-version }}-${{ github.ref_name }}-
- name: Run unit tests
run: make test-unit
- name: Run entire test suite
run: make test-integration
# jobs:
# test-stage:
# strategy:
# matrix:
# os: [ubuntu-latest]
# python-version: [3.13]
# splunk-version: [latest]
# runs-on: ${{ matrix.os }}
# steps:
# - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd
# - uses: ./.github/actions/setup-sdk-environment
# with:
# python-version: ${{ matrix.python-version }}
# deps-group: test
# - name: Download Splunk MCP Server App
# env:
# SPLUNKBASE_USERNAME: ${{ secrets.SPLUNKBASE_USERNAME }}
# SPLUNKBASE_PASSWORD: ${{ secrets.SPLUNKBASE_PASSWORD }}
# run: uv run ./scripts/download_splunk_mcp_server_app.py
# - name: Launch Splunk Docker instance
# run: SPLUNK_VERSION=${{ matrix.splunk-version }} docker compose up -d
# - name: Set up .env
# run: cp .env.template .env
# - name: Write internal AI secrets to .env
# env:
# INTERNAL_AI_APP_KEY: ${{ secrets.INTERNAL_AI_APP_KEY }}
# INTERNAL_AI_CLIENT_ID: ${{ secrets.INTERNAL_AI_CLIENT_ID }}
# INTERNAL_AI_CLIENT_SECRET: ${{ secrets.INTERNAL_AI_CLIENT_SECRET }}
# INTERNAL_AI_TOKEN_URL: ${{ secrets.INTERNAL_AI_TOKEN_URL }}
# INTERNAL_AI_BASE_URL: ${{ secrets.INTERNAL_AI_BASE_URL }}
# run: |
# echo "internal_ai_app_key=$INTERNAL_AI_APP_KEY" >> .env
# echo "internal_ai_client_id=$INTERNAL_AI_CLIENT_ID" >> .env
# echo "internal_ai_client_secret=$INTERNAL_AI_CLIENT_SECRET" >> .env
# echo "internal_ai_token_url=$INTERNAL_AI_TOKEN_URL" >> .env
# echo "internal_ai_base_url=$INTERNAL_AI_BASE_URL" >> .env
# - name: Restore pytest cache
# if: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/develop' }}
# uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae
# with:
# path: .pytest_cache
# key: pytest-cache-${{ runner.os }}-py${{ matrix.python-version }}-${{ github.ref_name }}-${{ github.sha }}
# restore-keys: |
# pytest-cache-${{ runner.os }}-py${{ matrix.python-version }}-${{ github.ref_name }}-
# - name: Run unit tests
# run: make test-unit
# - name: Run entire test suite
# run: make test-integration
13 changes: 6 additions & 7 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import importlib.metadata
from datetime import datetime

import splunklib

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
Expand Down Expand Up @@ -40,17 +39,17 @@
master_doc = "index"

# General information about the project.
project = "Splunk SDK for Python"
copyright = f"{datetime.now().year}, Splunk Inc."
package_name = "splunk-sdk"
project = f"Splunk SDK for Python (f{package_name}/splunklib)"
copyright = f"2011-{datetime.now().year} Splunk, Inc."

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = splunklib.__version__
# The full version, including alpha/beta/rc tags.
release = splunklib.__version__
release = importlib.metadata.version(package_name)
version = ".".join(release.split(".")[:2])

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
8 changes: 2 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ download = "https://github.com/splunk/splunk-sdk-python/releases/latest"

[project]
name = "splunk-sdk"
dynamic = ["version"]
version = "3.0.0"
description = "Splunk Software Development Kit for Python"
readme = "README.md"
requires-python = ">=3.13"
Expand Down Expand Up @@ -57,8 +57,7 @@ dev = [
]

[build-system]
# setuptools v61 introduces pyproject.toml support
requires = ["setuptools>=61.0.0"]
requires = ["setuptools>=82.0.1"]
build-backend = "setuptools.build_meta"

[tool.setuptools]
Expand All @@ -71,9 +70,6 @@ packages = [
"splunklib.ai.engines",
]

[tool.setuptools.dynamic]
version = { attr = "splunklib.__version__" }

[tool.basedpyright]
exclude = [".venv"]
allowedUntypedLibraries = ["splunklib"]
Expand Down
4 changes: 0 additions & 4 deletions splunklib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,3 @@ def setup_logging(
level, log_format=DEFAULT_LOG_FORMAT, date_format=DEFAULT_DATE_FORMAT
):
logging.basicConfig(level=level, format=log_format, datefmt=date_format)


__version_info__ = (3, 0, 0)
__version__ = ".".join(map(str, __version_info__))
12 changes: 7 additions & 5 deletions splunklib/binding.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
:mod:`splunklib.client` module.
"""

import importlib.metadata
import io
import json
import logging
Expand All @@ -34,14 +35,13 @@
from contextlib import contextmanager
from datetime import datetime
from functools import wraps
from io import BytesIO
from urllib import parse
from http import client
from http.cookies import SimpleCookie
from io import BytesIO
from urllib import parse
from xml.etree.ElementTree import XML, ParseError
from .data import record
from . import __version__

from .data import record

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1787,9 +1787,11 @@ def connect(scheme, host, port):
def request(url, message, **kwargs):
scheme, host, port, path = _spliturl(url)
body = message.get("body", "")

sdk_version = importlib.metadata.version("splunk-sdk")
head = {
"Content-Length": str(len(body)),
"User-Agent": "splunk-sdk-python/%s" % __version__,
"User-Agent": f"splunk-sdk-python/{sdk_version}",
"Accept": "*/*",
"Connection": "Close",
} # defaults
Expand Down
Loading