feat: make technologies field optional in service.py and add SDK automation scripts and release v1.0.6#16
feat: make technologies field optional in service.py and add SDK automation scripts and release v1.0.6#16
Conversation
| if python3 -c " | ||
| import instana_client | ||
| print('✅ 1. Basic import: SUCCESS') | ||
| print('1. Basic import: SUCCESS') |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 "" |
There was a problem hiding this comment.
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 "" |
There was a problem hiding this comment.
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 | ||
|
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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" | ||
|
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 | ||
|
|
There was a problem hiding this comment.
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
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.shautomation/publish_pypi.shtwine check)SDK v1.0.5
1.0.4→1.0.6Fixes:
instana_client/models/service.py.openapi-generator-ignoreto prevent regeneration conflictsTesting
twine checkUsage