URL: https://github.com/freeipa/freeipa/pull/183
Author: tiran
 Title: #183: Add __name__ == __main__ guards to setup.pys
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/183/head:pr183
git checkout pr183
From 07c46dd705bbebb3faca13997497926c5a77c038 Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Mon, 24 Oct 2016 14:56:58 +0200
Subject: [PATCH] Add __name__ == __main__ guards to setup.pys

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 ipaclient/setup.py   | 40 +++++++++++++++---------------
 ipalib/setup.py      | 26 +++++++++----------
 ipaplatform/setup.py | 34 ++++++++++++-------------
 ipapython/setup.py   | 32 ++++++++++++------------
 ipaserver/setup.py   | 39 ++++++++++++++---------------
 ipatests/pytest.ini  |  7 ++++++
 ipatests/setup.py    | 70 ++++++++++++++++++++++++++--------------------------
 7 files changed, 127 insertions(+), 121 deletions(-)

diff --git a/ipaclient/setup.py b/ipaclient/setup.py
index 8b9dd58..32778b0 100644
--- a/ipaclient/setup.py
+++ b/ipaclient/setup.py
@@ -20,26 +20,26 @@
 
 FreeIPA is a server for identity, policy, and audit.
 """
-import os
+from os.path import abspath, dirname
 import sys
 
-# include ../ for ipasetup.py
-sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+if __name__ == '__main__':
+    # include ../ for ipasetup.py
+    sys.path.append(dirname(dirname(abspath(__file__))))
+    from ipasetup import ipasetup  # noqa: E402
 
-from ipasetup import ipasetup  # noqa: E402
-
-ipasetup(
-    name="ipaclient",
-    doc=__doc__,
-    scripts=['../ipa'],
-    package_dir={'ipaclient': ''},
-    packages=[
-        "ipaclient",
-        "ipaclient.plugins",
-        "ipaclient.remote_plugins",
-        "ipaclient.remote_plugins.2_49",
-        "ipaclient.remote_plugins.2_114",
-        "ipaclient.remote_plugins.2_156",
-        "ipaclient.remote_plugins.2_164",
-    ],
-)
+    ipasetup(
+        name="ipaclient",
+        doc=__doc__,
+        scripts=['../ipa'],
+        package_dir={'ipaclient': ''},
+        packages=[
+            "ipaclient",
+            "ipaclient.plugins",
+            "ipaclient.remote_plugins",
+            "ipaclient.remote_plugins.2_49",
+            "ipaclient.remote_plugins.2_114",
+            "ipaclient.remote_plugins.2_156",
+            "ipaclient.remote_plugins.2_164",
+        ],
+    )
diff --git a/ipalib/setup.py b/ipalib/setup.py
index 62a4499..982a783 100644
--- a/ipalib/setup.py
+++ b/ipalib/setup.py
@@ -20,19 +20,19 @@
 
 FreeIPA is a server for identity, policy, and audit.
 """
-import os
+from os.path import abspath, dirname
 import sys
 
-# include ../ for ipasetup.py
-sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+if __name__ == '__main__':
+    # include ../ for ipasetup.py
+    sys.path.append(dirname(dirname(abspath(__file__))))
+    from ipasetup import ipasetup  # noqa: E402
 
-from ipasetup import ipasetup  # noqa: E402
-
-ipasetup(
-    name="ipalib",
-    doc=__doc__,
-    package_dir={'ipalib': ''},
-    packages=[
-        "ipalib",
-    ],
-)
+    ipasetup(
+        name="ipalib",
+        doc=__doc__,
+        package_dir={'ipalib': ''},
+        packages=[
+            "ipalib",
+        ],
+    )
diff --git a/ipaplatform/setup.py b/ipaplatform/setup.py
index 8b2d75d..82499da 100644
--- a/ipaplatform/setup.py
+++ b/ipaplatform/setup.py
@@ -20,23 +20,23 @@
 
 FreeIPA is a server for identity, policy, and audit.
 """
-import os
+from os.path import abspath, dirname
 import sys
 
-# include ../ for ipasetup.py
-sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+if __name__ == '__main__':
+    # include ../ for ipasetup.py
+    sys.path.append(dirname(dirname(abspath(__file__))))
+    from ipasetup import ipasetup  # noqa: E402
 
-from ipasetup import ipasetup  # noqa: E402
-
-ipasetup(
-    name="ipaplatform",
-    doc=__doc__,
-    package_dir={'ipaplatform': ''},
-    packages=[
-        "ipaplatform",
-        "ipaplatform.base",
-        "ipaplatform.fedora",
-        "ipaplatform.redhat",
-        "ipaplatform.rhel"
-    ],
-)
+    ipasetup(
+        name="ipaplatform",
+        doc=__doc__,
+        package_dir={'ipaplatform': ''},
+        packages=[
+            "ipaplatform",
+            "ipaplatform.base",
+            "ipaplatform.fedora",
+            "ipaplatform.redhat",
+            "ipaplatform.rhel"
+        ],
+    )
diff --git a/ipapython/setup.py b/ipapython/setup.py
index 81e032b..47acdd6 100755
--- a/ipapython/setup.py
+++ b/ipapython/setup.py
@@ -20,22 +20,22 @@
 
 FreeIPA is a server for identity, policy, and audit.
 """
-import os
+from os.path import abspath, dirname
 import sys
 
-# include ../ for ipasetup.py
-sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+if __name__ == '__main__':
+    # include ../ for ipasetup.py
+    sys.path.append(dirname(dirname(abspath(__file__))))
+    from ipasetup import ipasetup  # noqa: E402
 
-from ipasetup import ipasetup  # noqa: E402
-
-ipasetup(
-    name="ipapython",
-    doc=__doc__,
-    package_dir={'ipapython': ''},
-    packages=[
-        "ipapython",
-        "ipapython.dnssec",
-        "ipapython.secrets",
-        "ipapython.install"
-    ],
-)
+    ipasetup(
+        name="ipapython",
+        doc=__doc__,
+        package_dir={'ipapython': ''},
+        packages=[
+            "ipapython",
+            "ipapython.dnssec",
+            "ipapython.secrets",
+            "ipapython.install"
+        ],
+    )
diff --git a/ipaserver/setup.py b/ipaserver/setup.py
index 73afb70..e24e197 100755
--- a/ipaserver/setup.py
+++ b/ipaserver/setup.py
@@ -22,26 +22,25 @@
 """
 Python-level packaging using setuptools
 """
-import os
+from os.path import abspath, dirname
 import sys
 
-# include ../ for ipasetup.py and ipalib
-sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+if __name__ == '__main__':
+    # include ../ for ipasetup.py
+    sys.path.append(dirname(dirname(abspath(__file__))))
+    from ipasetup import ipasetup  # noqa: E402
 
-from ipasetup import ipasetup  # noqa: E402
-
-
-ipasetup(
-    name='freeipa',
-    doc=__doc__,
-    package_dir={'ipaserver': ''},
-    packages=[
-        'ipaserver',
-        'ipaserver.advise',
-        'ipaserver.advise.plugins',
-        'ipaserver.plugins',
-        'ipaserver.install',
-        'ipaserver.install.plugins',
-        'ipaserver.install.server',
-    ],
-)
+    ipasetup(
+        name='freeipa',
+        doc=__doc__,
+        package_dir={'ipaserver': ''},
+        packages=[
+            'ipaserver',
+            'ipaserver.advise',
+            'ipaserver.advise.plugins',
+            'ipaserver.plugins',
+            'ipaserver.install',
+            'ipaserver.install.plugins',
+            'ipaserver.install.server',
+        ],
+    )
diff --git a/ipatests/pytest.ini b/ipatests/pytest.ini
index 5b89942..b2497cb 100644
--- a/ipatests/pytest.ini
+++ b/ipatests/pytest.ini
@@ -15,7 +15,14 @@ addopts = --doctest-modules
           -p ipatests.pytest_plugins.additional_config
             # Ignore files for doc tests.
             # TODO: ideally, these should all use __name__=='__main__' guards
+          --ignore=ipasetup.py
           --ignore=setup.py
+          --ignore=ipaclient/setup.py
+          --ignore=ipalib/setup.py
+          --ignore=ipaplatform/setup.py
+          --ignore=ipapython/setup.py
+          --ignore=ipaserver/setup.py
+          --ignore=ipatests/setup.py
           --ignore=checks/check-ra.py
           --ignore=daemons/ipa-otpd/test.py
           --ignore=doc/examples/python-api.py
diff --git a/ipatests/setup.py b/ipatests/setup.py
index 86ee912..32a5207 100644
--- a/ipatests/setup.py
+++ b/ipatests/setup.py
@@ -20,41 +20,41 @@
 
 FreeIPA is a server for identity, policy, and audit.
 """
-import os
+from os.path import abspath, dirname
 import sys
 
-# include ../ for ipasetup.py
-sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+if __name__ == '__main__':
+    # include ../ for ipasetup.py
+    sys.path.append(dirname(dirname(abspath(__file__))))
+    from ipasetup import ipasetup  # noqa: E402
 
-from ipasetup import ipasetup  # noqa: E402
-
-ipasetup(
-    name="ipatests",
-    doc=__doc__,
-    package_dir={'ipatests': ''},
-    packages=[
-        "ipatests",
-        "ipatests.pytest_plugins",
-        "ipatests.test_cmdline",
-        "ipatests.test_install",
-        "ipatests.test_integration",
-        "ipatests.test_ipalib",
-        "ipatests.test_ipapython",
-        "ipatests.test_ipaserver",
-        "ipatests.test_ipaserver.test_install",
-        "ipatests.test_pkcs10",
-        "ipatests.test_webui",
-        "ipatests.test_xmlrpc",
-        "ipatests.test_xmlrpc.tracker"
-    ],
-    scripts=['ipa-run-tests', 'ipa-test-config', 'ipa-test-task'],
-    package_data={
-        'ipatests': ['pytest.ini'],
-        'ipatests.test_install': ['*.update'],
-        'ipatests.test_integration': ['scripts/*'],
-        'ipatests.test_ipalib': ['data/*'],
-        'ipatests.test_pkcs10': ['*.csr'],
-        "ipatests.test_ipaserver": ['data/*'],
-        'ipatests.test_xmlrpc': ['data/*'],
-    }
-)
+    ipasetup(
+        name="ipatests",
+        doc=__doc__,
+        package_dir={'ipatests': ''},
+        packages=[
+            "ipatests",
+            "ipatests.pytest_plugins",
+            "ipatests.test_cmdline",
+            "ipatests.test_install",
+            "ipatests.test_integration",
+            "ipatests.test_ipalib",
+            "ipatests.test_ipapython",
+            "ipatests.test_ipaserver",
+            "ipatests.test_ipaserver.test_install",
+            "ipatests.test_pkcs10",
+            "ipatests.test_webui",
+            "ipatests.test_xmlrpc",
+            "ipatests.test_xmlrpc.tracker"
+        ],
+        scripts=['ipa-run-tests', 'ipa-test-config', 'ipa-test-task'],
+        package_data={
+            'ipatests': ['pytest.ini'],
+            'ipatests.test_install': ['*.update'],
+            'ipatests.test_integration': ['scripts/*'],
+            'ipatests.test_ipalib': ['data/*'],
+            'ipatests.test_pkcs10': ['*.csr'],
+            "ipatests.test_ipaserver": ['data/*'],
+            'ipatests.test_xmlrpc': ['data/*'],
+        }
+    )
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to