[meld] meld.build_helpers: Record some installation prefixes (bgo#730322)



commit f8b796ae7e97f8c6a36cc7d0ac732e242aca1da7
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sun Jun 1 08:14:57 2014 +1000

    meld.build_helpers: Record some installation prefixes (bgo#730322)
    
    On install, we now record the installation prefix in the meld.conf
    module, so that we can locate our CSS, icons, etc. in non-standard
    prefix build environments. This should also make jhbuild of Meld
    actually work.
    
    This method was inspired by gottengeography, and then it got ugly.

 meld/build_helpers.py |   50 +++++++++++++++++++++++++++++++++++++++++++++++++
 meld/conf.py          |    2 +
 setup.py              |    1 +
 3 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/meld/build_helpers.py b/meld/build_helpers.py
index 85fb0eb..7eb2fd1 100644
--- a/meld/build_helpers.py
+++ b/meld/build_helpers.py
@@ -22,11 +22,13 @@ from __future__ import print_function
 
 import distutils.cmd
 import distutils.command.build
+import distutils.command.build_py
 import distutils.command.install_data
 import distutils.dist
 import distutils.dir_util
 import glob
 import os.path
+import sys
 
 from distutils.log import info
 
@@ -310,6 +312,54 @@ class build_i18n(distutils.cmd.Command):
                 self.distribution.data_files.append((target, files_merged))
 
 
+class build_py(distutils.command.build_py.build_py):
+    """Insert real package installation locations into conf module
+
+    Adapted from gottengeography
+    """
+
+    data_line = 'DATADIR = "%s"'
+    locale_line = 'LOCALEDIR = "%s"'
+
+    def build_module(self, module, module_file, package):
+
+        if module_file == 'meld/conf.py':
+            with open(module_file) as f:
+                contents = f.read()
+
+            try:
+                iobj = self.distribution.command_obj['install']
+                prefix = iobj.prefix
+            except KeyError as e:
+                print (e)
+                prefix = sys.prefix
+
+            datadir = os.path.join(prefix, 'share', 'meld')
+            localedir = os.path.join(prefix, 'share', 'locale')
+
+            start, end = 0, 0
+            lines = contents.splitlines()
+            for i, line in enumerate(lines):
+                if line.startswith('# START'):
+                    start = i
+                elif line.startswith('# END'):
+                    end = i
+
+            if start and end:
+                lines[start:end + 1] = [
+                    self.data_line % datadir,
+                    self.locale_line % localedir,
+                ]
+
+            module_file = module_file + "-installed"
+            contents = "\n".join(lines)
+            with open(module_file, 'w') as f:
+                f.write(contents)
+
+        distutils.command.build_py.build_py.build_module(
+            self, module, module_file, package)
+
+
 class install_data(distutils.command.install_data.install_data):
 
     def run(self):
diff --git a/meld/conf.py b/meld/conf.py
index 919254f..d1610c7 100644
--- a/meld/conf.py
+++ b/meld/conf.py
@@ -5,8 +5,10 @@ import sys
 __package__ = "meld"
 __version__ = "3.11.2"
 
+# START; these paths are clobbered on install by meld.build_helpers
 DATADIR = os.path.join(sys.prefix, "share", "meld")
 LOCALEDIR = os.path.join(sys.prefix, "share", "locale")
+# END
 UNINSTALLED = False
 
 # Installed from main script
diff --git a/setup.py b/setup.py
index 2960b34..9a94768 100644
--- a/setup.py
+++ b/setup.py
@@ -65,6 +65,7 @@ setup(
         "build_help": meld.build_helpers.build_help,
         "build_icons": meld.build_helpers.build_icons,
         "build_data": meld.build_helpers.build_data,
+        "build_py": meld.build_helpers.build_py,
         "install_data": meld.build_helpers.install_data,
     },
     distclass=meld.build_helpers.MeldDistribution,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]