From 7bd0af15d2af41c6c63cc3470870098041abcf4f Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Thu, 30 Nov 2017 15:47:38 -0800 Subject: [PATCH] Enhance empty __init__ code-smell to check module_utils (#33438) Empty __init__ will allow us to use python namespaces with all of these files. That may be something we want to take advantage of for allowign them to be expanded by user dirs. Also might be needed for AnsiballZ or other wrapper enhancements in the future. --- .../dev_guide/testing/sanity/empty-init.rst | 5 ++++- lib/ansible/module_utils/__init__.py | 20 ------------------- test/sanity/code-smell/empty-init.sh | 7 +++++-- 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/docs/docsite/rst/dev_guide/testing/sanity/empty-init.rst b/docs/docsite/rst/dev_guide/testing/sanity/empty-init.rst index 198380d980..391fdf67a8 100644 --- a/docs/docsite/rst/dev_guide/testing/sanity/empty-init.rst +++ b/docs/docsite/rst/dev_guide/testing/sanity/empty-init.rst @@ -1,7 +1,10 @@ Sanity Tests ยป empty-init ========================= -The ``__init__.py`` files under the following directories must be empty: +The ``__init__.py`` files under the following directories must be empty. For some of these (modules +and tests), ``__init__.py`` files with code won't be used. For others (module_utils), we want the +possibility of using Python namespaces which an empty ``__init__.py`` will allow for. - ``lib/ansible/modules/`` +- ``lib/ansible/module_utils/`` - ``test/units/`` diff --git a/lib/ansible/module_utils/__init__.py b/lib/ansible/module_utils/__init__.py index 9cde27b522..e69de29bb2 100644 --- a/lib/ansible/module_utils/__init__.py +++ b/lib/ansible/module_utils/__init__.py @@ -1,20 +0,0 @@ -# 2013, Michael DeHaan -# -# This file is part of Ansible -# -# Ansible is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Ansible is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with Ansible. If not, see . - -# Note: Do not add any code to this file. module_utils may be a namespace -# package when using Ansible-2.1+ Anything in this file may not be available -# if one of the other packages in the namespace is loaded first. diff --git a/test/sanity/code-smell/empty-init.sh b/test/sanity/code-smell/empty-init.sh index cdfe71584f..3ae810f5f9 100755 --- a/test/sanity/code-smell/empty-init.sh +++ b/test/sanity/code-smell/empty-init.sh @@ -2,8 +2,11 @@ found='' -for path in lib/ansible/modules/ test/units/; do - files=$(find "${path}" -name __init__.py -size '+0') +for path in lib/ansible/modules/ lib/ansible/module_utils test/units/; do + # facts is grandfathered in but will break namespacing. Only way to fix it + # is to deprecate and eventually remove. + # six will break namespacing but because it is bundled we should not be overriding it + files=$(find "${path}" -name __init__.py -size '+0' | sed '\!lib/ansible/module_utils/\(six\|facts\)/__init__.py!d') if [ "${files}" ]; then echo "${files}"