瀏覽代碼

Stylistic fixes

Johannes Baiter 11 年之前
父節點
當前提交
b9b372a011
共有 4 個文件被更改,包括 20 次插入19 次删除
  1. 7 10
      nsist/__init__.py
  2. 11 7
      nsist/copymodules.py
  3. 1 2
      nsist/nsiswriter.py
  4. 1 0
      setup.py

+ 7 - 10
nsist/__init__.py

@@ -13,6 +13,7 @@ if PY2:
     from urllib import urlretrieve
     from urllib import urlretrieve
 else:
 else:
     from urllib.request import urlretrieve
     from urllib.request import urlretrieve
+
 if os.name == 'nt' and PY2:
 if os.name == 'nt' and PY2:
     import _winreg as winreg
     import _winreg as winreg
 elif os.name == 'nt':
 elif os.name == 'nt':
@@ -138,12 +139,11 @@ def run_nsis(nsi_file):
         else:
         else:
             makensis = 'makensis'
             makensis = 'makensis'
         return call([makensis, nsi_file])
         return call([makensis, nsi_file])
-    except OSError:
-        # OSError catches both the registry lookup failing and call() not
-        # finding makensis
-        print("makensis was not found. Install NSIS and try again.")
-        print("http://nsis.sourceforge.net/Download")
-        return 1
+    except OSError as e:
+        if e.errno == errno.ENOENT or isinstance(e, WindowsError):
+            print("makensis was not found. Install NSIS and try again.")
+            print("http://nsis.sourceforge.net/Download")
+            return 1
 
 
 def all_steps(appname, version, script=None, entry_point=None, icon=DEFAULT_ICON, console=False,
 def all_steps(appname, version, script=None, entry_point=None, icon=DEFAULT_ICON, console=False,
                 packages=None, extra_files=None, py_version=DEFAULT_PY_VERSION,
                 packages=None, extra_files=None, py_version=DEFAULT_PY_VERSION,
@@ -159,10 +159,7 @@ def all_steps(appname, version, script=None, entry_point=None, icon=DEFAULT_ICON
     try:
     try:
         os.makedirs(build_dir)
         os.makedirs(build_dir)
     except OSError as e:
     except OSError as e:
-        if e.errno == errno.EEXIST:
-            # It's okay if the build directory already exists
-            pass
-        else:
+        if e.errno != errno.EEXIST:
             raise e
             raise e
     fetch_python(version=py_version, bitness=py_bitness, destination=build_dir)
     fetch_python(version=py_version, bitness=py_bitness, destination=build_dir)
     if PY2:
     if PY2:

+ 11 - 7
nsist/copymodules.py

@@ -28,7 +28,8 @@ if not PY2:
     class ModuleCopier:
     class ModuleCopier:
         """Finds and copies importable Python modules and packages.
         """Finds and copies importable Python modules and packages.
 
 
-        This uses importlib to locate modules.
+        This is the Python >3.3 version and uses the `importlib` package to
+        locate modules.
         """
         """
         def __init__(self, path=None):
         def __init__(self, path=None):
             self.path = path if (path is not None) else ([''] + sys.path)
             self.path = path if (path is not None) else ([''] + sys.path)
@@ -70,7 +71,8 @@ else:
     class ModuleCopier:
     class ModuleCopier:
         """Finds and copies importable Python modules and packages.
         """Finds and copies importable Python modules and packages.
 
 
-        This uses importlib to locate modules.
+        This is the Python 2.7 version and uses the `imp` package to locate
+        modules.
         """
         """
         def __init__(self, path=None):
         def __init__(self, path=None):
             self.path = path if (path is not None) else ([''] + sys.path)
             self.path = path if (path is not None) else ([''] + sys.path)
@@ -86,14 +88,16 @@ else:
             and extract modules and packages from appropriately structured zip
             and extract modules and packages from appropriately structured zip
             files.
             files.
             """
             """
-            modinfo = imp.find_module(modname, self.path)
+            info = imp.find_module(modname, self.path)
+            path = info[1]
+            modtype = info[2][2]
 
 
-            if modinfo[2][2] in (imp.PY_SOURCE, imp.C_EXTENSION):
-                shutil.copy2(modinfo[1], target)
+            if modtype in (imp.PY_SOURCE, imp.C_EXTENSION):
+                shutil.copy2(path, target)
 
 
-            elif modinfo[2][2] == imp.PKG_DIRECTORY:
+            elif modtype == imp.PKG_DIRECTORY:
                 dest = os.path.join(target, modname)
                 dest = os.path.join(target, modname)
-                shutil.copytree(modinfo[1], dest,
+                shutil.copytree(path, dest,
                                 ignore=shutil.ignore_patterns('*.pyc'))
                                 ignore=shutil.ignore_patterns('*.pyc'))
             else:
             else:
                 # Search all ZIP files in self.path for the module name
                 # Search all ZIP files in self.path for the module name

+ 1 - 2
nsist/nsiswriter.py

@@ -62,8 +62,7 @@ class NSISFileWriter(object):
     def write_pylauncher_install(self, f, indent):
     def write_pylauncher_install(self, f, indent):
         f.write(indent+"Section \"PyLauncher\" sec_pylauncher\n")
         f.write(indent+"Section \"PyLauncher\" sec_pylauncher\n")
         f.write(indent+"File \"launchwin${ARCH_TAG}.msi\"\n")
         f.write(indent+"File \"launchwin${ARCH_TAG}.msi\"\n")
-        f.write(indent+"ExecWait 'msiexec /i "
-                "\"$INSTDIR\launchwin${ARCH_TAG}.msi\" /qb ALLUSERS=1'\n")
+        f.write(indent+"ExecWait 'msiexec /i \"$INSTDIR\launchwin${ARCH_TAG}.msi\" /qb ALLUSERS=1'\n")
         f.write(indent+"Delete $INSTDIR\launchwin${ARCH_TAG}.msi\n")
         f.write(indent+"Delete $INSTDIR\launchwin${ARCH_TAG}.msi\n")
         f.write(indent+"SectionEnd\n")
         f.write(indent+"SectionEnd\n")
 
 

+ 1 - 0
setup.py

@@ -31,6 +31,7 @@ setup(name='pynsist',
           'License :: OSI Approved :: MIT License',
           'License :: OSI Approved :: MIT License',
           'Environment :: Win32 (MS Windows)',
           'Environment :: Win32 (MS Windows)',
           'Programming Language :: Python :: 3',
           'Programming Language :: Python :: 3',
+          'Programming Language :: Python :: 2.7',
           'Topic :: Software Development',
           'Topic :: Software Development',
           'Topic :: System :: Installation/Setup',
           'Topic :: System :: Installation/Setup',
           'Topic :: System :: Software Distribution',
           'Topic :: System :: Software Distribution',