Source

suds python 3 patches / unexpected-setup-cwd

# HG changeset patch
# Parent 5b3cd64bddbc27b6e9d05853b6e2d9fc063b07cd
Report an error if running setup.py from an unexpected folder.

Setup documentation incorrectly states that it will search for packages relative
to the setup script folder by default when in fact it will search for them
relative to the current working folder. It seems avoiding this problem cleanly
and making the setup script runnable with any current working folder would
require better setup() support.

diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -15,10 +15,34 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 # written by: Jeff Ortel ( jortel@redhat.com )
-
+
+import os
 import os.path
 from setuptools import setup, find_packages
 
+# Setup documentation incorrectly states that it will search for packages
+# relative to the setup script folder by default when in fact it will search
+# for them relative to the current working folder. It seems avoiding this
+# problem cleanly and making the setup script runnable with any current working
+# folder would require better setup() support.
+# Attempted alternatives:
+#   * Changing the current working folder internally makes any passed path
+#     parameters be interpreted relative to the setup script folder when they
+#     should be interpreted relative to the initial current working folder.
+#   * Passing the script folder as setup() & find_packages() function
+#     parameters makes the final installed distribution contain the absolute
+#     package source location information and not include some other meta-data
+#     package information as well.
+script_folder = os.path.abspath(os.path.dirname(__file__))
+current_folder = os.path.abspath(os.getcwd())
+if script_folder != current_folder:
+    print("ERROR: Suds library setup script needs to be run from the folder "
+        "containing it.")
+    print()
+    print("Current folder: {}".format(current_folder))
+    print("Script folder: {}".format(script_folder))
+    sys.exit(-2)
+
 # Load the suds library version information directly into this module without
 # having to import the whole suds library itself. Importing the suds package
 # would have caused problems like the following: