freeipa / ansible-freeipa

Ansible roles and modules for FreeIPA
GNU General Public License v3.0
491 stars 231 forks source link

Change hashbang of Python scripts to python3 #1107

Closed keestux closed 1 year ago

keestux commented 1 year ago

As described in PEP 394 there can be confusion when a script is executed with the command "python". Many of the scripts changed in this commit are Python3 (e.g. they call subprocess.run). On some systems the python command is simply unavailable. On most distributions it is better to use the command "python3".

t-woerner commented 1 year ago

Thanks for the PR.

The issue is that ansible-test is only allowing to use #!/usr/bin/env python but not #!/usr/bin/env python3. Therefore we have to keep it as is.

keestux commented 1 year ago

@t-woerner would you accept a PR that would only change utils/build-galaxy-release.sh such that the command python is changed to python3? It does change the shebang anywhere.

Something like this?

diff --git a/utils/build-galaxy-release.sh b/utils/build-galaxy-release.sh
index e427013..e3e293e 100755
--- a/utils/build-galaxy-release.sh
+++ b/utils/build-galaxy-release.sh
@@ -109,12 +109,12 @@ find . -name "*~" -exec rm {} \;

 echo "Creating CHANGELOG.rst..."
-"$(dirname "$0")/changelog" --galaxy > CHANGELOG.rst
+python3 "$(dirname "$0")/changelog" --galaxy > CHANGELOG.rst
 echo -e "\033[ACreating CHANGELOG.rst... \033[32;1mDONE\033[0m"

 sed -i -e "s/ansible.module_utils.ansible_freeipa_module/ansible_collections.${collection_prefix}.plugins.module_utils.ansible_freeipa_module/" plugins/modules/*.py

-python utils/create_action_group.py "meta/runtime.yml" "$collection_prefix"
+python3 utils/create_action_group.py "meta/runtime.yml" "$collection_prefix"

 (cd plugins/module_utils && {
     ln -sf ../../roles/*/module_utils/*.py .
@@ -145,7 +145,7 @@ done
 echo "Fixing examples in plugins/modules..."
 find plugins/modules -name "*.py" -print0 |
     while IFS= read -d '' -r line; do
-        python utils/galaxyfy-module-EXAMPLES.py "$line" \
+        python3 utils/galaxyfy-module-EXAMPLES.py "$line" \
                "ipa" "$collection_prefix"
     done
 echo -e "\033[AFixing examples in plugins/modules... \033[32;1mDONE\033[0m"
@@ -153,35 +153,35 @@ echo -e "\033[AFixing examples in plugins/modules... \033[32;1mDONE\033[0m"
 echo "Fixing examples in roles/*/library..."
 find roles/*/library -name "*.py" -print0 |
     while IFS= read -d '' -r line; do
-        python utils/galaxyfy-module-EXAMPLES.py "$line" \
+        python3 utils/galaxyfy-module-EXAMPLES.py "$line" \
                "ipa" "$collection_prefix"
     done
 echo -e "\033[AFixing examples in roles/*/library... \033[32;1mDONE\033[0m"

 echo "Fixing playbooks in roles/*/tasks..."
 for line in roles/*/tasks/*.yml; do
-    python utils/galaxyfy-playbook.py "$line" "ipa" "$collection_prefix"
+    python3 utils/galaxyfy-playbook.py "$line" "ipa" "$collection_prefix"
 done
 echo -e "\033[AFixing playbooks in roles/*tasks... \033[32;1mDONE\033[0m"

 echo "Fixing playbooks in playbooks..."
 find playbooks -name "*.yml" -print0 |
     while IFS= read -d '' -r line; do
-        python utils/galaxyfy-playbook.py "$line" "ipa" "$collection_prefix"
+        python3 utils/galaxyfy-playbook.py "$line" "ipa" "$collection_prefix"
     done
 echo -e "\033[AFixing playbooks in playbooks... \033[32;1mDONE\033[0m"

 echo "Fixing README(s)..."
 find . -name "README*.md" -print0 |
     while IFS= read -d '' -r line; do
-        python utils/galaxyfy-README.py "$line" "ipa" "$collection_prefix"
+        python3 utils/galaxyfy-README.py "$line" "ipa" "$collection_prefix"
     done
 echo -e "\033[AFixing examples in plugins/modules... \033[32;1mDONE\033[0m"

 echo "Fixing playbooks in tests..."
 find tests -name "*.yml" -print0 |
     while IFS= read -d '' -r line; do
-        python utils/galaxyfy-playbook.py "$line" "ipa" "$collection_prefix"
+        python3 utils/galaxyfy-playbook.py "$line" "ipa" "$collection_prefix"
     done
 echo -e "\033[AFixing playbooks in tests... \033[32;1mDONE\033[0m"