URL: https://github.com/freeipa/freeipa/pull/188
Author: tiran
 Title: #188: Move Python build artefacts to top level directory
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/188/head:pr188
git checkout pr188
From c01ca1a9b10e89afc29b7f747cfdb1c248bb2faf Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Wed, 26 Oct 2016 12:33:07 +0200
Subject: [PATCH] Move egg-info to support out-of-tree builds

The egg-info directories are now created in build root. For in-place
builds the build root is the project root. For out-of-tree builds it's
$(buildir)/build/../.., which is the same as $(top_builddir) for all
Python projects.

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 .gitignore           |  3 +--
 Makefile             |  3 ++-
 freeipa.spec.in      |  2 +-
 ipaclient/setup.py   |  2 +-
 ipalib/setup.py      |  2 +-
 ipaplatform/setup.py |  2 +-
 ipapython/setup.py   |  2 +-
 ipaserver/setup.py   |  4 ++--
 ipasetup.py.in       | 31 ++++++++++++++++++++++++++++++-
 ipatests/setup.py    |  2 +-
 10 files changed, 41 insertions(+), 12 deletions(-)

diff --git a/.gitignore b/.gitignore
index ac69f97..4c113f0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,12 +39,11 @@ freeipa2-dev-doc
 /freeipa.spec
 !/Makefile
 /dist/
-/*/dist/
 /RELEASE
 /rpmbuild/
 # Build
 /ipasetup.py
-*.egg-info
+/*.egg-info
 
 # Subdirectories
 /daemons/ipa-otpd/ipa-otpd
diff --git a/Makefile b/Makefile
index 761b57d..3e82ce7 100644
--- a/Makefile
+++ b/Makefile
@@ -131,6 +131,7 @@ pylint: bootstrap-autogen
 	FILES=`find . \
 		-type d -exec test -e '{}/__init__.py' \; -print -prune -o \
 		-path '*/.*' -o \
+		-path '*/build/*' -o \
 		-path './dist/*' -o \
 		-path './lextab.py' -o \
 		-path './yacctab.py' -o \
@@ -166,7 +167,7 @@ ipasetup.py: ipasetup.py.in FORCE
 	sed -e s/__VERSION__/$(IPA_VERSION)/ $< > $@
 
 .PHONY: egg_info
-egg_info: ipapython/version.py ipaplatform/__init__.py ipasetup.py
+egg_info: ipapython/version.py ipasetup.py
 	for directory in $(PYPKGDIRS); do \
 	    pushd $${directory} ; \
 	    $(PYTHON) setup.py egg_info $(EXTRA_SETUP); \
diff --git a/freeipa.spec.in b/freeipa.spec.in
index 7d55a71..678661b 100644
--- a/freeipa.spec.in
+++ b/freeipa.spec.in
@@ -1127,7 +1127,7 @@ fi
 %defattr(-,root,root,-)
 %doc README Contributors.txt
 %license COPYING
-%{python_sitelib}/freeipa-*.egg-info
+%{python_sitelib}/ipaserver-*.egg-info
 %dir %{python_sitelib}/ipaserver
 %dir %{python_sitelib}/ipaserver/install
 %dir %{python_sitelib}/ipaserver/install/plugins
diff --git a/ipaclient/setup.py b/ipaclient/setup.py
index 32778b0..89501fd 100644
--- a/ipaclient/setup.py
+++ b/ipaclient/setup.py
@@ -32,7 +32,7 @@
         name="ipaclient",
         doc=__doc__,
         scripts=['../ipa'],
-        package_dir={'ipaclient': ''},
+        setupfile=__file__,
         packages=[
             "ipaclient",
             "ipaclient.plugins",
diff --git a/ipalib/setup.py b/ipalib/setup.py
index 982a783..be496dd 100644
--- a/ipalib/setup.py
+++ b/ipalib/setup.py
@@ -31,7 +31,7 @@
     ipasetup(
         name="ipalib",
         doc=__doc__,
-        package_dir={'ipalib': ''},
+        setupfile=__file__,
         packages=[
             "ipalib",
         ],
diff --git a/ipaplatform/setup.py b/ipaplatform/setup.py
index 82499da..ce1957d 100644
--- a/ipaplatform/setup.py
+++ b/ipaplatform/setup.py
@@ -31,7 +31,7 @@
     ipasetup(
         name="ipaplatform",
         doc=__doc__,
-        package_dir={'ipaplatform': ''},
+        setupfile=__file__,
         packages=[
             "ipaplatform",
             "ipaplatform.base",
diff --git a/ipapython/setup.py b/ipapython/setup.py
index 47acdd6..8b5a686 100755
--- a/ipapython/setup.py
+++ b/ipapython/setup.py
@@ -31,7 +31,7 @@
     ipasetup(
         name="ipapython",
         doc=__doc__,
-        package_dir={'ipapython': ''},
+        setupfile=__file__,
         packages=[
             "ipapython",
             "ipapython.dnssec",
diff --git a/ipaserver/setup.py b/ipaserver/setup.py
index e24e197..df1b1a3 100755
--- a/ipaserver/setup.py
+++ b/ipaserver/setup.py
@@ -31,9 +31,9 @@
     from ipasetup import ipasetup  # noqa: E402
 
     ipasetup(
-        name='freeipa',
+        name='ipaserver',
         doc=__doc__,
-        package_dir={'ipaserver': ''},
+        setupfile=__file__,
         packages=[
             'ipaserver',
             'ipaserver.advise',
diff --git a/ipasetup.py.in b/ipasetup.py.in
index f291d22..81a264b 100644
--- a/ipasetup.py.in
+++ b/ipasetup.py.in
@@ -15,9 +15,33 @@
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
+from __future__ import print_function
+
 import os
 import sys
 
+from setuptools.command.egg_info import egg_info as setuptools_egg_info
+
+
+class egg_info(setuptools_egg_info):
+    def initialize_options(self):
+        setuptools_egg_info.initialize_options(self)
+        self.build_base = None
+
+    def finalize_options(self):
+        setuptools_egg_info.finalize_options(self)
+        # set self.build_base from build.build_base
+        self.set_undefined_options(
+            'build',
+            ('build_base', 'build_base'))
+        # egg-info directories are stored in project root
+        # /ipaplatform/build/../.. == /
+        toplevel = os.path.join(self.build_base, os.pardir, os.pardir)
+        self.egg_base = os.path.relpath(toplevel)
+        self.egg_info = os.path.join(self.egg_base,
+                                     os.path.basename(self.egg_info))
+
+
 common_args = dict(
     version="__VERSION__",
     license="GPL",
@@ -27,6 +51,9 @@ common_args = dict(
     maintainer_email="freeipa-devel@redhat.com",
     url="http://www.freeipa.org/";,
     download_url="http://www.freeipa.org/page/Downloads";,
+    cmdclass={
+        "egg_info": egg_info,
+    },
     platforms=["Linux", "Solaris", "Unix"],
     classifiers=[
         "Development Status :: 5 - Production/Stable",
@@ -45,14 +72,16 @@ local_path = os.path.dirname(os.path.abspath(sys.argv[0]))
 old_path = os.path.abspath(os.getcwd())
 
 
-def ipasetup(name, doc, **kwargs):
+def ipasetup(name, doc, setupfile, **kwargs):
     doclines = doc.split("\n")
+    package_root = os.path.abspath(os.path.dirname(setupfile))
 
     setup_kwargs = common_args.copy()
     setup_kwargs.update(
         name=name,
         description=doclines[0],
         long_description="\n".join(doclines[:2]),
+        package_dir={name: package_root},
         **kwargs
     )
     # exclude setup helpers from getting installed
diff --git a/ipatests/setup.py b/ipatests/setup.py
index 32a5207..052d92f 100644
--- a/ipatests/setup.py
+++ b/ipatests/setup.py
@@ -31,7 +31,7 @@
     ipasetup(
         name="ipatests",
         doc=__doc__,
-        package_dir={'ipatests': ''},
+        setupfile=__file__,
         packages=[
             "ipatests",
             "ipatests.pytest_plugins",
-- 
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