This is the mail archive of the mailing list for the Archer project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[python] Packacking - Python scripts directories

Hi Tom,

while rpm-packaging [python] branch into Archer I found there is IMO incorrect
placement of the Python scripts.
describes it should be placed in
Not /usr/lib64/python2.5 on 64-bit as these files are arch-independent.
I would also place it in /usr/share as arch-independent but this is the way
described both by the Fedora guidelines and seen at all the (tried) Fedora
existing packages providing 3rd party modules for Python (like libxml2-python).

--with-gdb-datadir should probably remain present as it is in use by

--with-gdb-pythondir and `maint set gdb_pythondir' should be new
(IMO the GDB style would be more like `maint set python-directory'.)

The code trying 2.4/2.5/2.6 directories to find the include
directory can be IMO replaced by:
  python -c "from distutils.sysconfig import get_python_inc; print get_python_inc()"
  (which prints `/usr/include/python2.5')

The target directory for Python scripts should be:
  python -c "from distutils.sysconfig import get_python_lib; print get_python_lib()"
  (which prints `/usr/lib/python2.5/site-packages')

As gdb.pythonlibdir is now the same as the system Python modules directory it
can be IMO removed.  (I do not understand why `import' with some
error-catching is not used instead of locating the include file in the code
and using execfile() which IMO does not provide the modules namespaces.)

There are some remaining issue i do not have opinion on (relocatability of the
Python directories).

[archer-jankratochvil-python] ebd9eefcf0e56102c40cfd104eb1c290526b3f51 which
has been reduced and checked-in:
[archer] 181911192955f46beb536919ea096b83b8ec5d75

Feel free to modify it in [archer-jankratochvil-python] + merge in [archer],

diff --git a/gdb/ b/gdb/
index 716884d..951ade8 100644
--- a/gdb/
+++ b/gdb/
 # Did the user give us a --with-gdb-datadir option?
 # Helper code from gnulib.
 LIBGNU = gnulib/libgnu.a
 INCGNU = -I$(srcdir)/gnulib -Ignulib
@@ -1978,22 +1980,31 @@ PY_FILES = gdb/ gdb/command/ \
     gdb/command/ gdb/command/ \
     gdb/command/ gdb/command/ \
     gdb/libstdcxx/v6/ gdb/libstdcxx/v6/ \
-    gdb/libstdcxx/ gdb/function/	\
+    gdb/libstdcxx/ gdb/function/ \
     gdb/function/ gdb/function/ gdb/ \
 # Install the Python library.  Python library files go under
-# $(GDB_DATADIR_PATH)/python.
+# $(GDB_PYTHONDIR_PATH)/python.
 	files='$(PY_FILES)'; for file in $$files; do \
 	  dir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
-	  $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(GDB_DATADIR_PATH)/python/$$dir; \
-	  $(INSTALL_DATA) $(srcdir)/python/lib/$$file $(DESTDIR)$(GDB_DATADIR_PATH)/python/$$file; \
+	  $(SHELL) $(srcdir)/../mkinstalldirs $(DESTDIR)$(GDB_PYTHONDIR_PATH)/$$dir; \
+	  $(INSTALL_DATA) $(srcdir)/python/lib/$$file $(DESTDIR)$(GDB_PYTHONDIR_PATH)/$$file; \
-# Brute force.
+# Other packages may have their files installed in $(GDB_PYTHONDIR_PATH).
-	rm -rf $(DESTDIR)/$(GDB_DATADIR_PATH)/python
+	rm -rf $(DESTDIR)/$(GDB_PYTHONDIR_PATH)/python
+	files='$(PY_FILES)'; for file in $$files; do \
+	  dir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
+	  rm -f $(DESTDIR)$(GDB_PYTHONDIR_PATH)/$$file; \
+	  while test "x$$file" != "x$$dir"; do \
+	    rmdir 2>/dev/null "$(DESTDIR)$(GDB_PYTHONDIR_PATH)/$$dir"; \
+	    file="$$dir"; \
+	    dir=`echo "$$file" | sed 's,/[^/]*$$,,'`; \
+	  done \
+	done
 # Dependency tracking.  Most of this is conditional on GNU Make being
diff --git a/gdb/ b/gdb/
index 3ef5bbd..1cfb12b 100644
--- a/gdb/
+++ b/gdb/
@@ -66,6 +66,9 @@
 /* Define to the default OS ABI for this configuration. */
+/* Base directory for GDB Python modules. */
 /* Define to 1 if you have `alloca', as a function or macro. */
diff --git a/gdb/ b/gdb/
index 5892c59..857a7cd 100644
--- a/gdb/
+++ b/gdb/
@@ -617,6 +617,7 @@ AC_ARG_WITH(python,
 AC_MSG_CHECKING([whether to use python])
 if test "${with_python}" = no; then
   AC_MSG_WARN([python support disabled; some features may be unavailable.])
@@ -659,7 +660,11 @@ else
       AC_DEFINE(HAVE_LIBPYTHON2_4, 1, [Define if Python 2.4 is being used.])
-  if test ${have_libpython} = no; then
+  if test ${have_libpython} != no; then
+    GDB_PYTHONDIR_PATH="`python -c "from distutils.sysconfig import get_python_lib; print get_python_lib();"`"
+		  [Base directory for GDB Python modules.])
+  else
     case "${with_python}" in
       AC_MSG_ERROR([python is missing or unusable])
@@ -675,7 +680,9 @@ else
 if test "${have_libpython}" = yes; then
   AC_DEFINE(HAVE_PYTHON, 1, [Define if Python interpreter is being linked in.])
diff --git a/gdb/python/python.c b/gdb/python/python.c
index a38ea92..18578f0 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1768,8 +1768,6 @@ Enables or disables auto-loading of Python code when an object is opened."),
   PyModule_AddStringConstant (gdb_module, "VERSION", (char*) version);
   PyModule_AddStringConstant (gdb_module, "HOST_CONFIG", (char*) host_name);
   PyModule_AddStringConstant (gdb_module, "TARGET_CONFIG", (char*) target_name);
-  if (gdb_datadir)
-    PyModule_AddStringConstant (gdb_module, "datadir", gdb_datadir);
   gdbpy_initialize_values ();
   gdbpy_initialize_breakpoints ();
@@ -1821,14 +1819,13 @@ class GdbOutputFile:\n\
 sys.stderr = GdbOutputFile()\n\
 sys.stdout = GdbOutputFile()\n\
-if hasattr (gdb, 'datadir'):\n\
-  gdb.pythonlibdir = gdb.datadir + '/python'\n\
-  sys.path.insert(0, gdb.pythonlibdir)\n\
-  gdb.__path__ = [gdb.pythonlibdir + '/gdb']\n\
-  from os.path import exists\n\
-  ipy = gdb.pythonlibdir + '/gdb/'\n\
-  if exists (ipy):\n\
-    execfile (ipy)\n\
+# FIXME: gdb.pythonlibdir is deprecated as it is just the standard libdir.\n\
+gdb.pythonlibdir = '" GDB_PYTHONDIR_PATH "'\n\
+gdb.__path__ = [gdb.pythonlibdir + '/gdb']\n\
+from os.path import exists\n\
+ipy = gdb.pythonlibdir + '/gdb/'\n\
+if exists (ipy):\n\
+  execfile (ipy)\n\
   /* Release the GIL while gdb runs.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]