Browse Source

Add include_msvcrt option

Thomas Kluyver 8 năm trước cách đây
mục cha
commit
e224aa9535
3 tập tin đã thay đổi với 34 bổ sung7 xóa
  1. 22 4
      doc/cfgfile.rst
  2. 11 3
      nsist/__init__.py
  3. 1 0
      nsist/configreader.py

+ 22 - 4
doc/cfgfile.rst

@@ -152,13 +152,32 @@ Python section
   - ``bundled`` includes an embeddable Python build, which will be installed as
     part of your application. This is available for Python 3.5 and above.
 
+.. describe:: include_msvcrt (optional)
+
+  This option is only relevant with ``format = bundled``. The default is ``true``,
+  which will include an app-local copy of the Microsoft Visual C++ Runtime,
+  required for Python to run. The installer will only install this if it doesn't
+  detect a system installation of the runtime.
+
+  Setting this to ``false`` will not include the C++ Runtime. Your application may
+  not run for all users until they install it manually (`download from Microsoft
+  <https://www.microsoft.com/en-us/download/details.aspx?id=48145>`__). You may
+  prefer to do this for security reasons: the separately installed runtime will
+  get updates through Windows Update, but app-local copies will not.
+
+  Users on Windows 10 should already have the runtime installed systemwide, so
+  this does won't affect them. Users on Windows Vista, 7, 8 or 8.1 *may* already
+  have it, depending on what else is installed.
+
+  .. versionadded:: 1.9
+
 .. _python_bundled:
 
 Bundled Python
 ~~~~~~~~~~~~~~
 
 .. versionadded:: 1.6
-   Experimental support for bundling Python into the application.
+   Support for bundling Python into the application.
 
 Using ``format = bundled``, an embeddable Python build will be downloaded at
 build time and packaged along with the application. When the installer runs, it
@@ -172,9 +191,8 @@ limitations:
 - This option is only available for Python 3.5 and above. These versions of
   Python have dropped support for Windows XP, so your application will only work
   on Windows Vista and newer.
-- Installing in Windows Vista to 8.1 (inclusive) may need an internet connection
-  to download the necessary `Visual C++ runtime
-  <http://www.microsoft.com/en-us/download/details.aspx?id=48145>`__. This isn't
+- Installing in Windows Vista to 8.1 (inclusive) may install an app-local copy
+  of the Visual C++ runtime (see above). This isn't
   needed on Windows 10, which includes the necessary files.
 - The embeddable Python builds don't include ``tkinter``, to save space.
   Applications with a tkinter GUI can't easily use bundled Python. Workarounds

+ 11 - 3
nsist/__init__.py

@@ -84,6 +84,8 @@ class InstallerBuilder(object):
     :param str py_version: Full version of Python to bundle
     :param int py_bitness: Bitness of bundled Python (32 or 64)
     :param str py_format: 'installer' or 'bundled'
+    :param bool inc_msvcrt: True to include the Microsoft C runtime with 'bundled'
+            Python. Ignored when py_format='installer'.
     :param str build_dir: Directory to run the build in
     :param str installer_name: Filename of the installer to produce
     :param str nsi_template: Path to a template NSI file to use
@@ -91,7 +93,7 @@ class InstallerBuilder(object):
     def __init__(self, appname, version, shortcuts, icon=DEFAULT_ICON,
                 packages=None, extra_files=None, py_version=DEFAULT_PY_VERSION,
                 py_bitness=DEFAULT_BITNESS, py_format='installer',
-                build_dir=DEFAULT_BUILD_DIR,
+                inc_msvcrt=True, build_dir=DEFAULT_BUILD_DIR,
                 installer_name=None, nsi_template=None,
                 exclude=None, pypi_wheel_reqs=None, commands=None):
         self.appname = appname
@@ -123,6 +125,7 @@ class InstallerBuilder(object):
         else:
             if py_format != 'installer':
                 raise InputError('py_format', py_format, "installer (for Python < 3.5)")
+        self.inc_msvcrt = inc_msvcrt
 
         # Build details
         self.build_dir = build_dir
@@ -130,7 +133,10 @@ class InstallerBuilder(object):
         self.nsi_template = nsi_template
         if self.nsi_template is None:
             if self.py_format == 'bundled':
-                self.nsi_template = 'pyapp_msvcrt.nsi'
+                if self.inc_msvcrt:
+                    self.nsi_template = 'pyapp_msvcrt.nsi'
+                else:
+                    self.nsi_template = 'pyapp.nsi'
             elif self.py_version_tuple < (3, 3):
                 self.nsi_template = 'pyapp_w_pylauncher.nsi'
             else:
@@ -463,7 +469,8 @@ if __name__ == '__main__':
 
         if self.py_format == 'bundled':
             self.fetch_python_embeddable()
-            self.prepare_msvcrt()
+            if self.inc_msvcrt:
+                self.prepare_msvcrt()
         else:
             self.fetch_python()
             if self.py_version < '3.3':
@@ -533,6 +540,7 @@ def main(argv=None):
             py_version = cfg.get('Python', 'version', fallback=DEFAULT_PY_VERSION),
             py_bitness = cfg.getint('Python', 'bitness', fallback=DEFAULT_BITNESS),
             py_format = cfg.get('Python', 'format', fallback='installer'),
+            inc_msvcrt = cfg.getboolean('Python', 'include_msvcrt', fallback=True),
             build_dir = cfg.get('Build', 'directory', fallback=DEFAULT_BUILD_DIR),
             installer_name = cfg.get('Build', 'installer_name', fallback=None),
             nsi_template = cfg.get('Build', 'nsi_template', fallback=None),

+ 1 - 0
nsist/configreader.py

@@ -77,6 +77,7 @@ CONFIG_VALIDATORS = {
         ('version', False),
         ('bitness', False),
         ('format', False),
+        ('include_msvcrt', False),
     ]),
     'Shortcut': SectionValidator([
         ('entry_point', False),