Commits

Ronald Oussoren committed 26f3ad1

Issue #70: use 'rU' to open script files, otherwise launching won't work with python 2.6

Fixes issue #70.

  • Participants
  • Parent commits e086b80
  • Branches branch-0.7
  • Tags py2app-0.7.1

Comments (0)

Files changed (6)

doc/changelog.rst

   application was not on "sys.path", which resulted in launch failures
   when using an extension that is not in the stdlib.
 
+- Issue #70: application fails to launch when script uses Windows line endings
+
+  Reported by Luc Jean.
+
 py2app 0.7
 ------------
 

py2app/bootstrap/boot_aliasapp.py

     script = SCRIPT_MAP.get(argv0, DEFAULT_SCRIPT)
 
     sys.argv[0] = __file__ = script
-    with open(script) as fp:
+    with open(script, 'rU') as fp:
         source = fp.read() + "\n"
 
     exec(compile(source, script, 'exec'), globals(), globals())

py2app/bootstrap/boot_aliasplugin.py

     script = SCRIPT_MAP.get(argv0, DEFAULT_SCRIPT)
 
     sys.argv[0] = __file__ = script
-    with open(script) as fp:
+    with open(script, 'rU') as fp:
         source = fp.read() + "\n"
 
     exec(compile(source, script, 'exec'), globals(), globals())

py2app/bootstrap/boot_app.py

 
     path = os.path.join(base, script)
     sys.argv[0] = __file__ = path
-    with open(path) as fp:
+    with open(path, 'rU') as fp:
         source = fp.read() + "\n"
     exec(compile(source, path, 'exec'), globals(), globals())

py2app/bootstrap/boot_plugin.py

 
     path = os.path.join(base, script)
     __file__ = path
-    with open(path) as fp:
+    with open(path, 'rU') as fp:
         source = fp.read()
     exec(compile(source, path, 'exec'), globals(), globals())
 

py2app_tests/test_basic_app.py

 class TestBasicSemiStandaloneApp (TestBasicApp):
     py2app_args = [ '--semi-standalone', ]
 
+class TestBasicAppWindowsLineEnd (TestBasicApp):
+    app_dir = os.path.join(DIR_NAME, 'basic_app_winle')
+
+    @classmethod
+    def setUpClass(cls):
+        try:
+            if os.path.exists(cls.app_dir):
+                shutil.rmtree(cls.app_dir)
+
+            assert not os.path.exists(cls.app_dir)
+            shutil.copytree(TestBasicApp.app_dir, cls.app_dir)
+
+            # Convert python files to Windows line endings
+            for fn in os.listdir(cls.app_dir):
+                if not fn.endswith('.py'): continue
+
+                path = os.path.join(cls.app_dir, fn)
+                with open(path, 'rb') as fp:
+                    data_in = fp.read()
+
+                data_out = data_in.replace(b'\n', b'\r\n')
+                if data_out == data_in:
+                    raise AssertionError("Data not changed")
+                with open(path, 'wb') as fp:
+                    fp.write(data_out)
+
+            super(TestBasicAppWindowsLineEnd, cls).setUpClass()
+
+        except:
+            if os.path.exists(cls.app_dir):
+                shutil.rmtree(cls.app_dir)
+
+            raise
+
+    @classmethod
+    def tearDownClass(cls):
+        if os.path.exists(cls.app_dir):
+            shutil.rmtree(cls.app_dir)
+
+class TestBasicAliasAppWindowsLineEnd (TestBasicAppWindowsLineEnd):
+    py2app_args = [ '--alias', ]
+
+class TestBasicSemiStandaloneAppWindowsLineEnd (TestBasicAppWindowsLineEnd):
+    py2app_args = [ '--semi-standalone', ]
+
+
 
 class TestBasicAppUnicodePath (TestBasicApp):
     if sys.version_info[0] == 2: