PATCH: Eliminate QM_BUILD
Mark Mitchell
mark at codesourcery.com
Mon Sep 29 07:11:44 UTC 2003
This patch eliminates the use of the QM_BUILD environment variable --
one more step towards the vision of QMTest-as-library. The technical
details were inspirated by one of Stefan's patches.
--
Mark Mitchell <mark at codesourcery.com>
CodeSourcery, LLC
-------------- next part --------------
? TODO
? autom4te.cache
? foo
? results.qmr
? doc/index.html
? doc/qm
? qm/external/__init__.pyc
? qm/test/classes/variant_database.py
? share/dtds
? tests/regress/QMTest/regression_database.pyc
? tests/regress/QMTest/selftest.pyc
? tests/regress/tuple1/QMTest/tuple_test.pyc
? tests/results_files/QMTest/results_file_database.pyc
? tests/results_files/QMTest/results_file_test.pyc
Index: ChangeLog
===================================================================
RCS file: /home/sc/Repository/qm/ChangeLog,v
retrieving revision 1.560
diff -c -5 -p -r1.560 ChangeLog
*** ChangeLog 29 Sep 2003 00:49:29 -0000 1.560
--- ChangeLog 29 Sep 2003 07:02:41 -0000
***************
*** 1,7 ****
--- 1,29 ----
2003-09-28 Mark Mitchell <mark at codesourcery.com>
+ * GNUmakefile.in ($(SCRIPTS)): Don't set QM_BUILD.
+ * qm/__init__.py: Set common.is_installed.
+ * qm/common.py (get_share_directory): Don't use QM_BUILD.
+ (get_doc_directory): Likewise.
+ (is_installed): New variable.
+ * qm/diagnostic.py (__diagnostic_set): New variable.
+ (__help_set): Likewise.
+ (get_diagnostic_set): New function.
+ (get_help_set): Likewise.
+ (message): Use them.
+ (error): Likewise.
+ (warning): Likewise.
+ (load_messages): Likewise.
+ (__initialize_module): Remove.
+ (diagnostic_set): Likewise.
+ (help_set): Likewise.
+ * qm/qm.sh: Eliminate QM_BUILD.
+ * qm/web.py (make_help_link): Use diagnostic.get_help_set().
+ * qm/test/web/web.py (DefaultDtmlPage.__init__): Don't use
+ QM_BUILD.
+ * qmdist/command/install_data.py (install_data.run): Simplify.
+
* doc/qm-opl.xml: Remove Software Carpentry references.
* doc/manual/common-manual.xml: Likewise.
* qm/test/doc/manual.xml: Update version number.
* qm/test/doc/reference.xml: Remove documentation for non-existant
Index: GNUmakefile.in
===================================================================
RCS file: /home/sc/Repository/qm/GNUmakefile.in,v
retrieving revision 1.28
diff -c -5 -p -r1.28 GNUmakefile.in
*** GNUmakefile.in 29 Aug 2003 22:36:24 -0000 1.28
--- GNUmakefile.in 29 Sep 2003 07:02:41 -0000
*************** else
*** 169,179 ****
PYTHONEXE = `@PYTHON@ -c "import sys; print sys.prefix"`\\python
$(SCRIPTS): GNUmakefile
rm -rf $@
echo -e "@echo off\r" > $@
echo -e "set QM_HOME=C:\\progra~1\qm\r" >> $@
- echo -e "set QM_BUILD=0\r" >> $@
echo -e "set PYTHONPATH=%C:\\Program Files\\QM\\$(RELLIBDIR);%PYTHONPATH%\r" >> $@
echo -n "$(PYTHONEXE)" \
\"%QM_HOME%\\$(RELLIBDIR)\\$(subst /,\\,$(basename $@)).py\" \
>> $@
echo -e " %1 %2 %3 %4 %5 %6 %7 %8 %9\r" >> $@
--- 169,178 ----
Index: qm/__init__.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/__init__.py,v
retrieving revision 1.8
diff -c -5 -p -r1.8 __init__.py
*** qm/__init__.py 17 Sep 2003 19:15:52 -0000 1.8
--- qm/__init__.py 29 Sep 2003 07:02:41 -0000
***************
*** 16,38 ****
########################################################################
# imports
########################################################################
import string
try:
# The config file is created during "make install" by setup.py.
from qm.config import version
version_info = tuple(string.split(version, '.'))
"""The version of QM as a tuple of '(major, minor, release)'."""
except:
# If qm.config was not available, we are running out of the source tree.
from qm.__version import version, version_info
!
! from qm.common import *
! from qm.diagnostic import error, warning, message
!
########################################################################
# Local Variables:
# mode: python
# indent-tabs-mode: nil
# End:
--- 16,38 ----
########################################################################
# imports
########################################################################
import string
+ from qm.common import *
+ from qm.diagnostic import error, warning, message
try:
# The config file is created during "make install" by setup.py.
from qm.config import version
version_info = tuple(string.split(version, '.'))
"""The version of QM as a tuple of '(major, minor, release)'."""
except:
# If qm.config was not available, we are running out of the source tree.
+ common.is_installed = 0
from qm.__version import version, version_info
!
########################################################################
# Local Variables:
# mode: python
# indent-tabs-mode: nil
# End:
Index: qm/common.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/common.py,v
retrieving revision 1.73
diff -c -5 -p -r1.73 common.py
*** qm/common.py 20 Aug 2003 00:36:49 -0000 1.73
--- qm/common.py 29 Sep 2003 07:02:42 -0000
*************** class RcConfiguration(ConfigParser.Confi
*** 221,241 ****
def get_share_directory(*components):
"""Return the path to a file in the QM data file directory."""
home_dir = os.environ["QM_HOME"]
! if os.environ.get("QM_BUILD") == "1":
return os.path.join(home_dir, "share", *components)
else:
return os.path.join(home_dir, "share", "qm", *components)
def get_doc_directory(*components):
"""Return a path to a file in the QM documentation file directory."""
home_dir = os.environ["QM_HOME"]
! if os.environ.get("QM_BUILD") == "1":
return os.path.join(home_dir, "qm", *components)
else:
return os.path.join(home_dir, "share", "doc", "qm", *components)
--- 221,241 ----
def get_share_directory(*components):
"""Return the path to a file in the QM data file directory."""
home_dir = os.environ["QM_HOME"]
! if not is_installed:
return os.path.join(home_dir, "share", *components)
else:
return os.path.join(home_dir, "share", "qm", *components)
def get_doc_directory(*components):
"""Return a path to a file in the QM documentation file directory."""
home_dir = os.environ["QM_HOME"]
! if not is_installed:
return os.path.join(home_dir, "qm", *components)
else:
return os.path.join(home_dir, "share", "doc", "qm", *components)
*************** def read_assignments(file):
*** 829,838 ****
--- 829,844 ----
return assignments
########################################################################
# variables
########################################################################
+
+ is_installed = 1
+ """True if this application has been installed.
+
+ True if the application has been installed. False if the application is
+ running out of the source tree."""
rc = RcConfiguration()
"""The configuration stored in system and user rc files."""
# The next number to be used when handing out unqiue tag strings.
Index: qm/diagnostic.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/diagnostic.py,v
retrieving revision 1.9
diff -c -5 -p -r1.9 diagnostic.py
*** qm/diagnostic.py 28 May 2002 01:37:53 -0000 1.9
--- qm/diagnostic.py 29 Sep 2003 07:02:42 -0000
*************** class DiagnosticSet:
*** 125,218 ****
output.write("%s: %s: %s\n"
% (common.program_name, severity, message))
return message
########################################################################
# functions
########################################################################
def message(tag, **substitutions):
"""Generate a diagnostic message."""
! global diagnostic_set
! return apply(diagnostic_set.Generate,
(tag, "message", None),
substitutions)
def error(tag, output=None, **substitutions):
"""Generate or emit an error diagnostic."""
! global diagnostic_set
! return apply(diagnostic_set.Generate,
(tag, "error", output, ),
substitutions)
def warning(tag, output=None, **substitutions):
"""Generate or emit a warning diagnostic."""
! global diagnostic_set
! return apply(diagnostic_set.Generate,
(tag, "warning", output, ),
substitutions)
def load_messages(tool):
"""Read messages that apply to 'tool'.
'tool' -- A string giving the name of a QM tool."""
# Load diagnostics.
! if os.environ['QM_BUILD'] == '1':
diagnostic_file \
= qm.get_share_directory("..", "qm", tool, "share",
"messages", "diagnostics.txt")
else:
diagnostic_file \
= qm.get_share_directory("messages", tool, "diagnostics.txt")
! diagnostic_set.ReadFromFile(diagnostic_file)
# Load help messages.
! if os.environ['QM_BUILD'] == '1':
diagnostic_file \
= qm.get_share_directory("..", "qm", tool, "share",
"messages", "help.txt")
else:
diagnostic_file \
= qm.get_share_directory("messages", tool, "help.txt")
! help_set.ReadFromFile(diagnostic_file)
-
- ########################################################################
- # variables
- ########################################################################
-
- diagnostic_set = DiagnosticSet()
- """The 'DiagnosticSet' object from which diagnostics are generated."""
-
- help_set = DiagnosticSet()
- """The 'DiagnosticSet'object from which help text messages are
- generated."""
-
- ########################################################################
- # initialization
- ########################################################################
-
- def __initialize_module():
- # Load common diagnostics.
- diagnostic_file = qm.get_share_directory("diagnostics", "common.txt")
- diagnostic_set.ReadFromFile(diagnostic_file)
-
- # Load common help messages.
- help_file = qm.get_share_directory("diagnostics", "common-help.txt")
- help_set.ReadFromFile(help_file)
-
-
- __initialize_module()
-
########################################################################
# Local Variables:
# mode: python
# indent-tabs-mode: nil
# fill-column: 72
--- 125,225 ----
output.write("%s: %s: %s\n"
% (common.program_name, severity, message))
return message
+ ########################################################################
+ # Variables
+ ########################################################################
+
+ __diagnostic_set = None
+ """The 'DiagnosticSet' object from which diagnostics are generated."""
+
+ __help_set = None
+ """The 'DiagnosticSet'object from which help text messages are
+ generated."""
########################################################################
# functions
########################################################################
+ def get_diagnostic_set():
+ """Return the 'DiagnosticSet' containing warning/error messages.
+
+ returns -- The 'DiagnosticSet' containing warning/error messages."""
+
+ global __diagnostic_set
+ if __diagnostic_set is None:
+ __diagnostic_set = DiagnosticSet()
+ __diagnostic_set.ReadFromFile(qm.get_share_directory("diagnostics",
+ "common.txt"))
+
+ return __diagnostic_set
+
+
+ def get_help_set():
+ """Return the 'DiagnosticSet' for help messages.
+
+ returns -- The 'DiagnosticSet' containing help messages."""
+
+ global __help_set
+ if __help_set is None:
+ __help_set = DiagnosticSet()
+ __help_set.ReadFromFile(qm.get_share_directory("diagnostics",
+ "common-help.txt"))
+
+ return __help_set
+
+
def message(tag, **substitutions):
"""Generate a diagnostic message."""
! return apply(get_diagnostic_set().Generate,
(tag, "message", None),
substitutions)
def error(tag, output=None, **substitutions):
"""Generate or emit an error diagnostic."""
! return apply(get_diagnostic_set().Generate,
(tag, "error", output, ),
substitutions)
def warning(tag, output=None, **substitutions):
"""Generate or emit a warning diagnostic."""
! return apply(get_diagnostic_set().Generate,
(tag, "warning", output, ),
substitutions)
def load_messages(tool):
"""Read messages that apply to 'tool'.
'tool' -- A string giving the name of a QM tool."""
# Load diagnostics.
! if not qm.common.is_installed:
diagnostic_file \
= qm.get_share_directory("..", "qm", tool, "share",
"messages", "diagnostics.txt")
else:
diagnostic_file \
= qm.get_share_directory("messages", tool, "diagnostics.txt")
! get_diagnostic_set().ReadFromFile(diagnostic_file)
# Load help messages.
! if not qm.common.is_installed:
diagnostic_file \
= qm.get_share_directory("..", "qm", tool, "share",
"messages", "help.txt")
else:
diagnostic_file \
= qm.get_share_directory("messages", tool, "help.txt")
! get_help_set().ReadFromFile(diagnostic_file)
########################################################################
# Local Variables:
# mode: python
# indent-tabs-mode: nil
# fill-column: 72
Index: qm/qm.sh
===================================================================
RCS file: /home/sc/Repository/qm/qm/qm.sh,v
retrieving revision 1.15
diff -c -5 -p -r1.15 qm.sh
*** qm/qm.sh 6 Sep 2003 05:24:01 -0000 1.15
--- qm/qm.sh 29 Sep 2003 07:02:42 -0000
*************** qm_split_path() {
*** 98,116 ****
# installation. In the former case, we have found an installed QM;
# in the latter we have found a build directory where QM is being
# developed.
#
# After determining the root of the QM installation, set the QM_HOME
! # environment variable to that value. If we have found QM in the
! # build directory, set the QM_BUILD environment variable to 1.
! # Otherwise, set it to 0.
#
# Set QM_PATH to the path to this script.
- # Assume that QM is not running out of the build directory.
- QM_BUILD=${QM_BUILD:-0}
-
# Check to see if QM_HOME is set.
if test x"${QM_HOME}" = x; then
# Find the path to this script. Set qm_path to the absolute
# path to this script.
if qm_is_absolute_path "$0"; then
--- 98,111 ----
# installation. In the former case, we have found an installed QM;
# in the latter we have found a build directory where QM is being
# developed.
#
# After determining the root of the QM installation, set the QM_HOME
! # environment variable to that value.
#
# Set QM_PATH to the path to this script.
# Check to see if QM_HOME is set.
if test x"${QM_HOME}" = x; then
# Find the path to this script. Set qm_path to the absolute
# path to this script.
if qm_is_absolute_path "$0"; then
*************** if test x"${QM_HOME}" = x; then
*** 150,189 ****
break
fi
# Alternatively, if we have find a file called `qm/qm.sh',
# then we have found the root of the QM build directory.
if test -f "${QM_HOME}/qm/qm.sh"; then
- QM_BUILD=1
break
fi
# If we have reached the root directory, then we have run
# out of places to look.
if test "x${QM_HOME}" = x/; then
qm_could_not_find_qm
fi
# Go the next containing directory.
QM_HOME=`dirname "${QM_HOME}"`
done
else
! # The QM_HOME variable was set.
! if test ${QM_BUILD} -eq 0; then
! QM_PATH=$QM_HOME/bin/qmtest
! else
! QM_PATH=$QM_HOME/qm/test/qmtest
! fi
fi
# Export QM_HOME and QM_PATH so that we can find them from within Python.
export QM_HOME
export QM_PATH
- # Export QM_BUILD so that QM knows where to look for other modules.
- export QM_BUILD
# When running QMTest from the build environment, run Python without
# optimization. In a production environment, use optimization.
if test x"${QM_PYTHON_FLAGS}" = x; then
! if test ${QM_BUILD} -eq 1; then
QM_PYTHON_FLAGS=""
else
QM_PYTHON_FLAGS="-O"
fi
fi
--- 145,187 ----
break
fi
# Alternatively, if we have find a file called `qm/qm.sh',
# then we have found the root of the QM build directory.
if test -f "${QM_HOME}/qm/qm.sh"; then
break
fi
# If we have reached the root directory, then we have run
# out of places to look.
if test "x${QM_HOME}" = x/; then
qm_could_not_find_qm
fi
# Go the next containing directory.
QM_HOME=`dirname "${QM_HOME}"`
done
+ fi
+
+ # Figure out whether or not we are running out of the build directory.
+ if test -f "${QM_HOME}/qm/qm.sh"; then
+ qm_build=1
else
! qm_build=0
! fi
!
! if test ${qm_build} -eq 0; then
! QM_PATH=$QM_HOME/bin/qmtest
! else
! QM_PATH=$QM_HOME/qm/test/qmtest
fi
# Export QM_HOME and QM_PATH so that we can find them from within Python.
export QM_HOME
export QM_PATH
# When running QMTest from the build environment, run Python without
# optimization. In a production environment, use optimization.
if test x"${QM_PYTHON_FLAGS}" = x; then
! if test ${qm_build} -eq 1; then
QM_PYTHON_FLAGS=""
else
QM_PYTHON_FLAGS="-O"
fi
fi
*************** elif test -f "/usr/bin/python2"; then
*** 215,225 ****
else
qm_python="python"
fi
# Figure out where to find the main Python script.
! if test ${QM_BUILD} -eq 0; then
qm_libdir="${QM_HOME}/${qm_rel_libdir}"
else
qm_libdir="${QM_HOME}/qm"
fi
qm_script=`basename $0`
--- 213,223 ----
else
qm_python="python"
fi
# Figure out where to find the main Python script.
! if test ${qm_build} -eq 0; then
qm_libdir="${QM_HOME}/${qm_rel_libdir}"
else
qm_libdir="${QM_HOME}/qm"
fi
qm_script=`basename $0`
Index: qm/web.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/web.py,v
retrieving revision 1.75
diff -c -5 -p -r1.75 web.py
*** qm/web.py 30 Jul 2003 21:25:30 -0000 1.75
--- qm/web.py 29 Sep 2003 07:02:43 -0000
*************** def make_help_link(help_text_tag, label=
*** 2124,2134 ****
'label' -- The help link label.
'substitutions' -- Substitutions to the help diagnostic."""
# Construct the help text.
! help_text = apply(diagnostic.help_set.Generate,
(help_text_tag, "help", None),
substitutions)
# Convert it to HTML.
help_text = qm.structured_text.to_html(help_text)
# Make the link.
--- 2124,2134 ----
'label' -- The help link label.
'substitutions' -- Substitutions to the help diagnostic."""
# Construct the help text.
! help_text = apply(diagnostic.get_help_set().Generate,
(help_text_tag, "help", None),
substitutions)
# Convert it to HTML.
help_text = qm.structured_text.to_html(help_text)
# Make the link.
Index: qm/test/web/web.py
===================================================================
RCS file: /home/sc/Repository/qm/qm/test/web/web.py,v
retrieving revision 1.77
diff -c -5 -p -r1.77 web.py
*** qm/test/web/web.py 27 Aug 2003 16:03:26 -0000 1.77
--- qm/test/web/web.py 29 Sep 2003 07:02:44 -0000
*************** class DefaultDtmlPage(qm.web.DtmlPage):
*** 53,63 ****
'dtml_template' -- The file name of the DTML template, relative
to the DTML directory."""
# In the build tree, tool-specific DTML pages are in a different
# location.
! if (os.environ['QM_BUILD'] == '1'
and os.path.dirname(dtml_template) == "test"):
dtml_template \
= os.path.join("..", "..", "qm", "test", "share",
"dtml", os.path.basename(dtml_template))
--- 53,63 ----
'dtml_template' -- The file name of the DTML template, relative
to the DTML directory."""
# In the build tree, tool-specific DTML pages are in a different
# location.
! if (not qm.common.is_installed
and os.path.dirname(dtml_template) == "test"):
dtml_template \
= os.path.join("..", "..", "qm", "test", "share",
"dtml", os.path.basename(dtml_template))
Index: qmdist/command/install_data.py
===================================================================
RCS file: /home/sc/Repository/qm/qmdist/command/install_data.py,v
retrieving revision 1.2
diff -c -5 -p -r1.2 install_data.py
*** qmdist/command/install_data.py 17 Sep 2003 19:15:52 -0000 1.2
--- qmdist/command/install_data.py 29 Sep 2003 07:02:44 -0000
*************** class install_data(base.install_data):
*** 29,41 ****
il = self.distribution.get_command_obj('install_lib')
base.install_data.run(self)
config = os.path.join(il.install_dir, 'qm/config.py')
self.announce("generating %s" %(config))
outf = open(config, "w")
- outf.write("#the old way...\n")
- outf.write("import os\n")
- outf.write("os.environ['QM_BUILD']='0'\n")
- outf.write("#the new way...\n")
outf.write("version='%s'\n"%(self.distribution.get_version()))
outf.write("\n")
self.outfiles.append(config)
--- 29,37 ----
More information about the qmtest
mailing list