Details
-
Improvement
-
Status: Closed
-
Minor
-
Resolution: Won't Fix
-
0.20
-
None
-
None
-
Py2exe build for windows
Description
The data files in .../qpid-python/python/qpid/specs (i.e. amqp-0-10.dtd, amqp-0-8.xml, amqp-0-9.xml) are accessed using a base path of _file_, which is not available if byte compiled into a py2exe (or pyInstaller) executable. The patch below works around this issue.
I thought this might be useful for others ...
--Matt Hughes
Index: specs_config.py
===================================================================
— specs_config.py (revision 47091)
+++ specs_config.py (revision 47092)
@@ -18,8 +18,20 @@
#
import os
+import imp
+import sys
-AMQP_SPEC_DIR=os.path.join(os.path.dirname(os.path.abspath(_file_)), "specs")
+def is_frozen():
+ return (hasattr(sys, "frozen") or # new py2exe
+ hasattr(sys, "importers") # old py2exe
+ or imp.is_frozen("_main_")) # tools/freeze
+
+if is_frozen:
+ basepath = os.path.dirname(os.path.abspath(sys.executable))
+else:
+ basepath = os.path.dirname(os.path.abspath(_file_))
+
+AMQP_SPEC_DIR=os.path.join(basepath, "specs")
amqp_spec = os.path.join(AMQP_SPEC_DIR, "amqp-0-10-qpid-errata.xml")
amqp_spec_0_8 = os.path.join(AMQP_SPEC_DIR, "amqp-0-8.xml")
amqp_spec_0_9 = os.path.join(AMQP_SPEC_DIR, "amqp-0-9.xml")