Bläddra i källkod

Use license_file and minor refactoring in light of code review.

Nicholas H.Tollervey 7 år sedan
förälder
incheckning
0c39e2e94f
5 ändrade filer med 24 tillägg och 20 borttagningar
  1. 1 1
      doc/cfgfile.rst
  2. 15 11
      nsist/__init__.py
  3. 2 2
      nsist/configreader.py
  4. 4 4
      nsist/nsiswriter.py
  5. 2 2
      nsist/pyapp.nsi

+ 1 - 1
doc/cfgfile.rst

@@ -81,7 +81,7 @@ Application section
    If you use the Python API, this parameter can also be passed as a file-like
    object, such as :class:`io.StringIO`.
 
-.. describe:: license (optional)
+.. describe:: license_file (optional)
 
   Path to a text file containing the license under which your software is to
   be distributed. If given, an extra step before installation will check the

+ 15 - 11
nsist/__init__.py

@@ -96,7 +96,7 @@ class InstallerBuilder(object):
                 py_format='bundled', inc_msvcrt=True, build_dir=DEFAULT_BUILD_DIR,
                 installer_name=None, nsi_template=None,
                 exclude=None, pypi_wheel_reqs=None, extra_wheel_sources=None,
-                commands=None, license=None):
+                commands=None, license_file=None):
         self.appname = appname
         self.version = version
         self.publisher = publisher
@@ -108,7 +108,7 @@ class InstallerBuilder(object):
         self.pypi_wheel_reqs = pypi_wheel_reqs or []
         self.extra_wheel_sources = extra_wheel_sources or []
         self.commands = commands or {}
-        self.license = license
+        self.license_file = license_file
 
         # Python options
         self.py_version = py_version
@@ -202,9 +202,7 @@ class InstallerBuilder(object):
             z.extractall(python_dir)
 
         # Manipulate any *._pth files so the default paths AND pkgs directory
-        # ends up in sys.path. Please see:
-        # https://docs.python.org/3/using/windows.html#finding-modules
-        # for more information.
+        # ends up in sys.path.
         pth_files = [f for f in os.listdir(python_dir)
                      if os.path.isfile(pjoin(python_dir, f))
                      and f.endswith('._pth')]
@@ -283,7 +281,7 @@ if __name__ == '__main__':
         copy to the build directory. Prepare target and parameters for these
         shortcuts.
 
-        Also copies shortcut icons, and, if specified, the license file.
+        Also copies shortcut icons.
         """
         files = set()
         for scname, sc in self.shortcuts.items():
@@ -315,14 +313,18 @@ if __name__ == '__main__':
             shutil.copy2(sc['icon'], self.build_dir)
             sc['icon'] = os.path.basename(sc['icon'])
             files.add(sc['icon'])
+        self.install_files.extend([(f, '$INSTDIR') for f in files])
 
-        # Copy license
-        if self.license:
-            shutil.copy2(self.license, self.build_dir)
-            license_file_name = os.path.basename(self.license)
+    def copy_license(self):
+        """
+        If a license file has been specified, ensure it's copied into the
+        install directory and added to the install_files list.
+        """
+        if self.license_file:
+            shutil.copy2(self.license_file, self.build_dir)
+            license_file_name = os.path.basename(self.license_file)
             self.install_files.append((license_file_name, '$INSTDIR'))
 
-        self.install_files.extend([(f, '$INSTDIR') for f in files])
 
     def prepare_packages(self):
         """Move requested packages into the build directory.
@@ -455,6 +457,8 @@ if __name__ == '__main__':
 
         self.prepare_shortcuts()
 
+        self.copy_license()
+
         if self.commands:
             self.prepare_commands()
 

+ 2 - 2
nsist/configreader.py

@@ -63,7 +63,7 @@ CONFIG_VALIDATORS = {
         ('icon', False),
         ('console', False),
         ('extra_preamble', False),
-        ('license', False),
+        ('license_file', False),
     ]),
     'Build': SectionValidator([
         ('directory', False),
@@ -221,7 +221,7 @@ def get_installer_builder_args(config):
     args['commands'] = read_commands_config(config)
     args['publisher'] = appcfg.get('publisher', None)
     args['icon'] = appcfg.get('icon', DEFAULT_ICON)
-    args['license'] = appcfg.get('license', None)
+    args['license_file'] = appcfg.get('license_file', None)
     args['packages'] = config.get('Include', 'packages', fallback='').strip().splitlines()
     args['pypi_wheel_reqs'] = config.get('Include', 'pypi_wheels', fallback='').strip().splitlines()
     args['extra_wheel_sources'] = [Path(p) for p in

+ 4 - 4
nsist/nsiswriter.py

@@ -46,9 +46,9 @@ class NSISFileWriter(object):
         grouped_files = [(dest, [x[0] for x in group]) for (dest, group) in
             itertools.groupby(self.installerbuilder.install_files, itemgetter(1))
                 ]
-        license = None
-        if installerbuilder.license:
-            license = os.path.basename(installerbuilder.license)
+        license_file = None
+        if installerbuilder.license_file:
+            license_file = os.path.basename(installerbuilder.license_file)
         self.namespace = {
             'ib': installerbuilder,
             'grouped_files': grouped_files,
@@ -59,7 +59,7 @@ class NSISFileWriter(object):
             'pynsist_pkg_dir': _PKGDIR,
             'has_commands': len(installerbuilder.commands) > 0,
             'python': '"$INSTDIR\\Python\\python"',
-            'license': license,
+            'license_file': license_file,
         }
 
     def write(self, target):

+ 2 - 2
nsist/pyapp.nsi

@@ -32,8 +32,8 @@ SetCompressor lzma
 ; UI pages
 [% block ui_pages %]
 !insertmacro MUI_PAGE_WELCOME
-[% if license %]
-!insertmacro MUI_PAGE_LICENSE [[license]]
+[% if license_file %]
+!insertmacro MUI_PAGE_LICENSE [[license_file]]
 [% endif %]
 !insertmacro MULTIUSER_PAGE_INSTALLMODE
 !insertmacro MUI_PAGE_DIRECTORY