Skip to content

Add python compatibility check function to ./scripts/setup.sh #1329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

JH-LEE-KR
Copy link
Contributor

On Ubuntu, the default Python version varies by release:

  • Ubuntu 18.04 LTS: Python 2.7
  • Ubuntu 20.04 LTS: Python 3.8
  • Ubuntu 22.04 LTS: Python 3.10

Currently, the Ansible installation process in ./scripts/setup.sh proceeds without verifying the compatibility of the Python version on the system.
This can result in installation failures that may be difficult for users to determine the cause of.

I propose enhancing the setup process to first check the compatibility between the Ansible version and the Python version.
This pre-check will help users understand potential incompatibilities upfront and prevent confusing installation errors.

@dholt dholt requested a review from Copilot June 26, 2025 17:08
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds a pre-check in setup.sh to verify that the system’s Python version satisfies the Python requirement declared by the targeted Ansible release.

  • Introduces jq to platform-specific dependency lists
  • Fetches Ansible metadata from PyPI and extracts requires_python
  • Implements a Bash function to parse and enforce version constraints
Comments suppressed due to low confidence (1)

scripts/setup.sh:90

  • [nitpick] This new compatibility-check logic isn’t covered by any automated tests; adding unit or integration tests for common version scenarios will help prevent regressions.
# Check Local Python and Ansible Compatibility

}

check_python_compatibility() {
for c in $(sed 's/,//g' <<< "$1"); do
Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

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

The constraint parsing removes commas instead of splitting on them, so multi-part requirements like ">=2.7,<4.0" become a single token. Replace sed 's/,//g' with sed 's/,/ /g' to iterate over each requirement separately.

Suggested change
for c in $(sed 's/,//g' <<< "$1"); do
for c in $(sed 's/,/ /g' <<< "$1"); do

Copilot uses AI. Check for mistakes.

Comment on lines +92 to +93
JSON=$(wget -qO- "https://pypi.org/pypi/ansible/$ANSIBLE_VERSION/json")
[[ -z "$JSON" || "$JSON" == *"Not Found"* ]] && { echo "Not found: Ansible $ANSIBLE_VERSION"; exit 1; }
Copy link
Preview

Copilot AI Jun 26, 2025

Choose a reason for hiding this comment

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

[nitpick] Relying on response content to detect a missing package can be brittle. Consider checking the HTTP status code (e.g., with wget --server-response or using curl -s -o /dev/null -w '%{http_code}') before parsing the body.

Suggested change
JSON=$(wget -qO- "https://pypi.org/pypi/ansible/$ANSIBLE_VERSION/json")
[[ -z "$JSON" || "$JSON" == *"Not Found"* ]] && { echo "Not found: Ansible $ANSIBLE_VERSION"; exit 1; }
HTTP_STATUS=$(wget --server-response -qO- "https://pypi.org/pypi/ansible/$ANSIBLE_VERSION/json" 2>&1 | awk '/^ HTTP/{print $2}' | tail -n1)
if [[ "$HTTP_STATUS" != "200" ]]; then
echo "Not found: Ansible $ANSIBLE_VERSION (HTTP status: $HTTP_STATUS)"
exit 1
fi
JSON=$(wget -qO- "https://pypi.org/pypi/ansible/$ANSIBLE_VERSION/json")

Copilot uses AI. Check for mistakes.

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.

1 participant