Repository: pypa/wheel

Issue:
"and extra" breaks environment marker logic
In pypa/setuptools#1242, we discovered that wheel is allegedly simply appending ` and extra=="..."`, which will break the logic when the existing environment marker contains or expressions.

Comments:

Patch:
diff --git a/CHANGES.txt b/CHANGES.txt
index 5c3ceee..a182ed7 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,6 +1,7 @@
 Unreleased
 ==========
 - Fixed displaying of errors on Python 3
+- Fixed single digit versions in wheel files not being properly recognized
 
 0.30.0
 ======
diff --git a/wheel/install.py b/wheel/install.py
index 5c3e3d9..3d71d3d 100644
--- a/wheel/install.py
+++ b/wheel/install.py
@@ -34,9 +34,8 @@ VERSION_TOO_HIGH = (1, 0)
 # Non-greedy matching of an optional build number may be too clever (more
 # invalid wheel filenames will match). Separate regex for .dist-info?
 WHEEL_INFO_RE = re.compile(
-    r"""^(?P<namever>(?P<name>.+?)(-(?P<ver>\d.+?))?)
-    ((-(?P<build>\d.*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
-    \.whl|\.dist-info)$""",
+    r"""^(?P<namever>(?P<name>.+?)-(?P<ver>\d.*?))(-(?P<build>\d.*?))?
+     -(?P<pyver>[a-z].+?)-(?P<abi>.+?)-(?P<plat>.+?)(\.whl|\.dist-info)$""",
     re.VERBOSE).match
 
 
diff --git a/wheel/metadata.py b/wheel/metadata.py
index 29638e7..75dce67 100644
--- a/wheel/metadata.py
+++ b/wheel/metadata.py
@@ -255,7 +255,7 @@ def generate_requirements(extras_require):
         if extra:
             yield ('Provides-Extra', extra)
             if condition:
-                condition += " and "
+                condition = "(" + condition + ") and "
             condition += "extra == '%s'" % extra
         if condition:
             condition = '; ' + condition


Test patch:
diff --git a/tests/test_install.py b/tests/test_install.py
index 60b04e8..42db4f0 100644
--- a/tests/test_install.py
+++ b/tests/test_install.py
@@ -100,3 +100,9 @@ def test_install():
 def test_install_tool():
     """Slightly improve coverage of wheel.install"""
     wheel.tool.install([TESTWHEEL], force=True, dry_run=True)
+
+
+def test_wheelfile_re():
+    # Regression test for #208
+    wf = WheelFile('foo-2-py3-none-any.whl')
+    assert wf.distinfo_name == 'foo-2.dist-info'
diff --git a/tests/test_metadata.py b/tests/test_metadata.py
new file mode 100644
index 0000000..842d1d3
--- /dev/null
+++ b/tests/test_metadata.py
@@ -0,0 +1,25 @@
+from wheel.metadata import generate_requirements
+
+
+def test_generate_requirements():
+    extras_require = {
+        'test': ['ipykernel', 'ipython', 'mock'],
+        'test:python_version == "3.3"': ['pytest<3.3.0'],
+        'test:python_version >= "3.4" or python_version == "2.7"': ['pytest'],
+    }
+    expected_metadata = [
+        ('Provides-Extra',
+         'test'),
+        ('Requires-Dist',
+         "ipykernel; extra == 'test'"),
+        ('Requires-Dist',
+         "ipython; extra == 'test'"),
+        ('Requires-Dist',
+         "mock; extra == 'test'"),
+        ('Requires-Dist',
+         'pytest (<3.3.0); (python_version == "3.3") and extra == \'test\''),
+        ('Requires-Dist',
+         'pytest; (python_version >= "3.4" or python_version == "2.7") and extra == \'test\''),
+    ]
+    generated_metadata = sorted(set(generate_requirements(extras_require)))
+    assert generated_metadata == expected_metadata