Browse Source

Merge remote-tracking branch 'upstream/master'

Adrien Ferrand 6 years ago
parent
commit
bace15300e
4 changed files with 50 additions and 17 deletions
  1. 2 0
      doc/faq.rst
  2. 16 0
      doc/releasenotes.rst
  3. 14 15
      nsist/pypi.py
  4. 18 2
      nsist/tests/test_pypi.py

+ 2 - 0
doc/faq.rst

@@ -65,6 +65,8 @@ application (``sys.modules['__main__'].__file__``).
 
        writable_file = os.path.join(os.environ['LOCALAPPDATA'], 'MyApp', 'file.dat')
 
+.. _faq-tkinter:
+
 Packaging with tkinter
 ----------------------
 

+ 16 - 0
doc/releasenotes.rst

@@ -1,6 +1,22 @@
 Release notes
 =============
 
+Version 2.2
+-----------
+
+* The ``exclude`` option now works to exclude files extracted from wheels
+  (:ghpull:`147`).
+* ``exclude`` patterns work with either slash ``/`` or backslash ``\`` as
+  separators, independent of the platform on which you build the installer
+  (:ghpull:`148`).
+* Destination paths for the ``files`` include option now work with slashes
+  as well as backslashes (:ghpull:`158`).
+* ``extra_preamble`` for start menu shortcuts can now use the ``installdir``
+  variable to get the installation directory. This was already available for
+  commands, so the change makes it easier to use a single preamble for both
+  (:ghpull:`149`).
+* New FAQ entry on :ref:`faq-tkinter` (:ghpull:`146`).
+
 Version 2.1
 -----------
 

+ 14 - 15
nsist/pypi.py

@@ -1,12 +1,8 @@
-from distutils.version import LooseVersion
-import errno
+"""Find, download and unpack wheels."""
 import fnmatch
 import hashlib
 import logging
-try:
-    from pathlib import Path
-except ImportError:
-    from pathlib2 import Path  # Backport
+from pathlib import Path
 import re
 import shutil
 from tempfile import mkdtemp
@@ -20,13 +16,6 @@ from .util import get_cache_dir, normalize_path
 
 logger = logging.getLogger(__name__)
 
-def find_pypi_release(requirement):
-    if '==' in requirement:
-        name, version = requirement.split('==', 1)
-        return yarg.get(name).release(version)
-    else:
-        return yarg.get(requirement).latest_release
-
 class NoWheelError(Exception): pass
 
 class WheelLocator(object):
@@ -130,7 +119,17 @@ class WheelLocator(object):
         Downloads to the cache directory and returns the destination as a Path.
         Raises NoWheelError if no compatible wheel is found.
         """
-        release_list = yarg.get(self.name).release(self.version)
+        try:
+            pypi_pkg = yarg.get(self.name)
+        except yarg.HTTPError as e:
+            if e.status_code == 404:
+                raise NoWheelError("No package named {} found on PyPI".format(self.name))
+            raise
+
+        release_list = pypi_pkg.release(self.version)
+        if release_list is None:
+            raise NoWheelError("No release {0.version} for package {0.name}".format(self))
+
         preferred_release = self.pick_best_wheel(release_list)
         if preferred_release is None:
             raise NoWheelError('No compatible wheels found for {0.name} {0.version}'.format(self))
@@ -230,7 +229,7 @@ def extract_wheel(whl_file, target_dir, exclude=None):
     target = Path(target_dir)
     copied_something = False
     for p in td.iterdir():
-        if p.suffix not in {'.data', '.dist-info'}:
+        if p.suffix not in {'.data'}:
             if p.is_dir():
                 # If the dst directory already exists, this will combine them.
                 # shutil.copytree will not combine them.

+ 18 - 2
nsist/tests/test_pypi.py

@@ -4,7 +4,9 @@ from pathlib import Path
 from testpath import assert_isfile, assert_isdir
 from testpath.tempdir import TemporaryDirectory
 
-from nsist.pypi import WheelLocator, extract_wheel, CachedRelease, merge_dir_to
+from nsist.pypi import (
+    WheelLocator, extract_wheel, CachedRelease, merge_dir_to, NoWheelError,
+)
 
 def test_download():
     wd = WheelLocator("astsearch==0.1.2", "3.5.1", 64)
@@ -14,9 +16,23 @@ def test_download():
     with TemporaryDirectory() as td:
         extract_wheel(wheel, target_dir=td)
         assert_isfile(pjoin(td, 'astsearch.py'))
+        assert_isfile(pjoin(td, 'astsearch-0.1.2.dist-info', 'METADATA'))
 
-# To exclude this, run:  nosetests -a '!network'
+def test_bad_name():
+    # Packages can't be named after stdlib modules like os
+    wl = WheelLocator("os==1.0", "3.5.1", 64)
+    with assert_raises(NoWheelError):
+        wl.get_from_pypi()
+
+def test_bad_version():
+    wl = WheelLocator("pynsist==0.99.99", "3.5.1", 64)
+    with assert_raises(NoWheelError):
+        wl.get_from_pypi()
+
+# To exclude these, run:  nosetests -a '!network'
 test_download.network = 1
+test_bad_name.network = 1
+test_bad_version.network = 1
 
 def test_extra_sources():
     with TemporaryDirectory() as td: