Skip to content

feat: make technologies field optional in service.py and add SDK automation scripts and release v1.0.6#16

Open
Jayssgss wants to merge 6 commits intomainfrom
SDK-Update-Automation
Open

feat: make technologies field optional in service.py and add SDK automation scripts and release v1.0.6#16
Jayssgss wants to merge 6 commits intomainfrom
SDK-Update-Automation

Conversation

@Jayssgss
Copy link
Collaborator

@Jayssgss Jayssgss commented Mar 18, 2026

Summary

This PR introduces automation scripts for SDK maintenance and publishes Instana Python SDK v1.0.5 with bug fixes.


Changes

Automation Scripts

Added scripts to streamline SDK generation and publishing:

  • automation/update_sdk.sh

    • Regenerates SDK from OpenAPI spec
    • Handles version bumping
    • Runs tests and builds packages
    • Supports dry-run and rollback
  • automation/publish_pypi.sh

    • Automates PyPI publishing
    • Validates packages (twine check)
    • Supports PyPI and TestPyPI

SDK v1.0.5

  • Version bump: 1.0.41.0.6
  • Updated across all relevant files

Fixes:

  • Resolved model issue in instana_client/models/service.py
  • Updated .openapi-generator-ignore to prevent regeneration conflicts

Testing


Usage

./automation/update_sdk.sh --spec-path ./openapi.yaml --version 1.0.6
./automation/publish_pypi.sh --password <PYPI_TOKEN>

@Jayssgss Jayssgss requested a review from sunjit10 March 18, 2026 11:16
@Jayssgss Jayssgss changed the title feat: make technologies field optional in service.py and add SDK automation scripts and release v1.0.5 feat: make technologies field optional in service.py and add SDK automation scripts and release v1.0.6 Mar 18, 2026
if python3 -c "
import instana_client
print('1. Basic import: SUCCESS')
print('1. Basic import: SUCCESS')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Potential problem with this import

REQUIRED_PACKAGES=("setuptools" "pydantic" "python-dateutil" "urllib3")
for package in "${REQUIRED_PACKAGES[@]}"; do
    if ! python3 -c "import $package" 2>/dev/null; then

Can you check if python-dateutil import works? In some cases, the actual package name that is used in import command can be different.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an alternate approach:

declare -A REQUIRED_PACKAGES=(
    ["setuptools"]="setuptools"
    ["pydantic"]="pydantic"
    ["python-dateutil"]="dateutil"
    ["urllib3"]="urllib3"
)

for package in "${!REQUIRED_PACKAGES[@]}"; do
    import_name="${REQUIRED_PACKAGES[$package]}"
    if ! python3 -c "import ${import_name}" 2>/dev/null; then
        print_warning "${package} not found, installing..."
        # Installation logic...
    fi
done

print_success " Configuration works"
print_success " File structure valid"
print_success " Integration test passed"
echo ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated to these changes but something that can come handy when troubleshooting.

Let's say some packages are not installed as expected when doing this:

if python3 -m pip install --break-system-packages "$package" >/dev/null 2>&1; then
    print_success "$package installed successfully"
elif python3 -m pip install "$package" >/dev/null 2>&1; then

Adding a log message telling which $package did not install as expected would be helpful.

print_success " Integration test passed"
echo ""
print_success "The Instana Python SDK is ready for production! 🚀"
echo ""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another legacy issue: setup.py check and setup.py build are deprecated in modern Python packaging.

if python3 setup.py check >/dev/null 2>&1; then
if python3 setup.py build >/dev/null 2>&1; then

Here is an alternative:

# Test 1: Check package configuration using modern tools
print_status "Testing package configuration..."
if python3 -m build --help >/dev/null 2>&1; then
    print_success "Build tools available"
else
    print_warning "Installing build tools..."
    python3 -m pip install --break-system-packages build
fi

# Test 2: Validate package metadata
print_status "Validating package metadata..."
if python3 -m pip install --break-system-packages check-manifest >/dev/null 2>&1; then
    if check-manifest --ignore 'build/*,dist/*,*.egg-info/*' >/dev/null 2>&1; then
        print_success "Package manifest is valid"
    else
        print_warning "Package manifest has issues (non-critical)"
    fi
fi


# Update configuration.py
sed -i.bak "s/SDK Package Version: $CURRENT_VERSION/SDK Package Version: $NEW_VERSION/" instana_client/configuration.py

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those sed command above might cause issues on MacOS if the sed used is not compatible with GNU sed. This is a safer approach:

safe_sed_replace() {
    local pattern="$1"
    local file="$2"
    sed "$pattern" "$file" > "${file}.tmp" && mv "${file}.tmp" "$file"
}

safe_sed_replace "s/VERSION = \"$CURRENT_VERSION\"/VERSION = \"$NEW_VERSION\"/" setup.py

print_status "Running OpenAPI generator..."

# Check if openapi-generator-cli is available
if ! command -v openapi-generator-cli &> /dev/null; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to check all the required dependencies at the top of the script during initial phases.
Something like shown below (you can include openapi-generator-cli in that required_commands plus anything else that the script depends on.

check_dependencies() {
    local missing_deps=()
    local required_commands=("python3" "grep" "sed" "git")
    
    for cmd in "${required_commands[@]}"; do
        if ! command -v "$cmd" &> /dev/null; then
            missing_deps+=("$cmd")
        fi
    done
    
    if [ ${#missing_deps[@]} -gt 0 ]; then
        print_error "Missing required dependencies: ${missing_deps[*]}"
        return 1
    fi
    
    return 0
}

# Call early in script
check_dependencies || exit 1

print_error "Package check failed"
deactivate
rm -rf .venv-publish
exit 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If deactivate fails or virtual environment wasn't activated, cleanup may fail silently. You can make it more resilient by using trap instead of manual cleanup calls. Something like:

cleanup() {
    local exit_code=$?
    if [ -n "$VIRTUAL_ENV" ]; then
        deactivate 2>/dev/null || true
    fi
    if [ -d ".venv-publish" ]; then
        rm -rf .venv-publish
    fi
    return $exit_code
}

trap cleanup EXIT ERR


# Check if packages exist
PACKAGE_COUNT=$(ls -1 dist/*.whl dist/*.tar.gz 2>/dev/null | wc -l)
if [ "$PACKAGE_COUNT" -eq 0 ]; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ls with multiple patterns can fail if one pattern has no matches.
Here is an alternative approach that counts packages more reliably.

WHEEL_COUNT=$(find dist -maxdepth 1 -name "*.whl" 2>/dev/null | wc -l)
TARBALL_COUNT=$(find dist -maxdepth 1 -name "*.tar.gz" 2>/dev/null | wc -l)
PACKAGE_COUNT=$((WHEEL_COUNT + TARBALL_COUNT))

if [ "$PACKAGE_COUNT" -eq 0 ]; then
    print_error "No distribution packages found in dist/"
    print_status "Run './automation/update_sdk.sh' first to build packages"
    exit 1
fi

print_success "Found $PACKAGE_COUNT distribution package(s) ($WHEEL_COUNT wheels, $TARBALL_COUNT tarballs)"


# Install twine
print_status "Installing twine..."
pip install --upgrade twine
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to add some logs/checks in case something goes wrong when installing packages. Something like:

print_status "Installing twine..."
if ! pip install --upgrade twine; then
    print_error "Failed to install twine"
    exit 1
fi

# STEP 1: Validate prerequisites
# =============================================================================
print_header "Step 1: Validating prerequisites"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to check if python3 exists in the system when validating prerequisites.


detect_python() {
    for cmd in python3 python; do
        if command -v "$cmd" >/dev/null 2>&1; then
            PYTHON_CMD="$cmd"
            PYTHON_VERSION=$("$cmd" --version 2>&1 | awk '{print $2}')
            print_status "Using Python: $PYTHON_CMD ($PYTHON_VERSION)"
            return 0
        fi
    done
    print_error "Python not found. Please install Python 3.7+"
    exit 1
}

detect_python

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the future commands in the script where python3 is referenced directly, you can change that to use PYTHON_CMD instead of python3

$PYTHON_CMD -m venv .venv-publish

BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m' # No Color

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Above ANSI codes might not work in all terminals. How about some checks:

if [ -t 1 ] && command -v tput >/dev/null 2>&1; then
    RED=$(tput setaf 1)
    GREEN=$(tput setaf 2)
    YELLOW=$(tput setaf 3)
    BLUE=$(tput setaf 4)
    CYAN=$(tput setaf 6)
    NC=$(tput sgr0)
else
    RED=''
    GREEN=''
    YELLOW=''
    BLUE=''
    CYAN=''
    NC=''
fi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants