Repository: pex-tool/pex

Issue:
Issue with MarkupSafe
```
pex: Validated MarkupSafe-1.0.tar.gz (sha256=a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665)
pex: Target package EggPackage('file:///tmp/tmpal18pifn/MarkupSafe-1.0-py3.6-linux-x86_64.egg') is not compatible with [('cp36', 'cp36m', 'manylinux1_x86_64'), ('cp36', 'cp36m', 'linux_x86_64'), ('cp36', 'abi3', 'manylinux1_x86_64'), ('cp36', 'abi3', 'linux_x86_64'), ('cp36', 'none', 'manylinux1_x86_64'), ('cp36', 'none', 'linux_x86_64'), ('py3', 'none', 'manylinux1_x86_64'), ('py3', 'none', 'linux_x86_64'), ('cp36', 'none', 'any'), ('cp3', 'none', 'any'), ('py36', 'none', 'any'), ('py3', 'none', 'any')]
Traceback (most recent call last):
  File "setup.py", line 58, in <module>
    packages=['promcon', 'promcon.cli', 'promcon.configs', 'promcon.wrapper'],
  File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
    dist.run_commands()
  File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
    self.run_command(cmd)
  File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
    cmd_obj.run()
  File "/home/cchary/dev/prometheus-configuration/venv/lib/python3.6/site-packages/pex/commands/bdist_pex.py", line 89, in run
    pex_builder = build_pex(reqs, options, options_builder)
  File "/home/cchary/dev/prometheus-configuration/venv/lib/python3.6/site-packages/pex/bin/pex.py", line 624, in build_pex
    for dist in resolveds:
  File "/home/cchary/dev/prometheus-configuration/venv/lib/python3.6/site-packages/pex/resolver.py", line 525, in resolve_multi
    use_manylinux=use_manylinux):
  File "/home/cchary/dev/prometheus-configuration/venv/lib/python3.6/site-packages/pex/resolver.py", line 451, in resolve
    return resolver.resolve(resolvables_from_iterable(requirements, builder))
  File "/home/cchary/dev/prometheus-configuration/venv/lib/python3.6/site-packages/pex/resolver.py", line 248, in resolve
    dist = self.build(package, resolvable.options)
  File "/home/cchary/dev/prometheus-configuration/venv/lib/python3.6/site-packages/pex/resolver.py", line 206, in build
    raise Untranslateable('Package %s is not translateable by %s' % (package, translator))
pex.resolver.Untranslateable: Package SourcePackage('https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz#sha256=a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665') is not translateable by ChainedTranslator(EggTranslator, SourceTranslator)
```


Discussion:
Works with 1.3.2, broken with 1.4.0
Also complains with Pluggy
any chance you can provide a minimal repro that I can confirm a fix against? seems like this is specific to egg resolution vs MarkupSafe?
```
$ virtualenv -p python3 venv
$ source venv/bin/activate
$ pip install pex
Collecting pex
  Downloading https://files.pythonhosted.org/packages/c1/48/78c6888038948d2e61f69ca412d04931a6e51eec739de757baad75914933/pex-1.4.0-py2.py3-none-any.whl (126kB)
    100% |████████████████████████████████| 133kB 10.8MB/s 
Collecting setuptools<34.0,>=20.3 (from pex)
  Using cached https://files.pythonhosted.org/packages/e5/53/92a8ac9d252ec170d9197dcf988f07e02305a06078d7e83a41ba4e3ed65b/setuptools-33.1.1-py2.py3-none-any.whl
Collecting wheel<0.30.0,>=0.26.0 (from pex)
  Using cached https://files.pythonhosted.org/packages/8a/e9/8468cd68b582b06ef554be0b96b59f59779627131aad48f8a5bce4b13450/wheel-0.29.0-py2.py3-none-any.whl
Installing collected packages: setuptools, wheel, pex
  Found existing installation: setuptools 39.1.0
    Uninstalling setuptools-39.1.0:
      Successfully uninstalled setuptools-39.1.0
  Found existing installation: wheel 0.31.1
    Uninstalling wheel-0.31.1:
      Successfully uninstalled wheel-0.31.1
Successfully installed pex-1.4.0 setuptools-33.1.1 wheel-0.29.0

$ pex MarkupSafe --disable-cache --no-wheel -vvv -o test.pex 
pex: Warning, using a UrllibContext which is known to be flaky.                            
pex: Please build pex with the requests module for more reliable downloads.
pex: crawling link i=0 link=Link('https://pypi.python.org/simple/markupsafe/') follow_links=False
pex: Building pex :: Resolving distributions :: Fetching https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz#sha256=a6be69091dac236eapex: Building pex :: Resolving distributions :: Fetching https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz#sha256=a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665 :: Fetching https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz#sha256=a6be69091dac23pex: Building pex :: Resolving distributions :: Translating /tmp/tmpba94dbh0/MarkupSafe-1.0.tar.gz into distribution                                                                                                                                                                                                                                                                                                                pex: Target package EggPackage('file:///tmp/tmpqcilxii8/MarkupSafe-1.0-py3.6-linux-x86_64.egg') is not compatible with [('cp36', 'cp36m', 'manylinux1_x86_64'), ('cp36', 'cp36m', 'linux_x86_64'), ('cp36', 'abi3', 'manylinux1_x86_64'), ('cp36', 'abi3', 'linux_x86_64'), ('cp36', 'none', 'manylinux1_x86_64'), ('cp36', 'none', 'linux_x86_64'), ('py3', 'none', 'manylinux1_x86_64'), ('py3', 'none', 'linux_x86_64'), ('cp36', 'none', 'any'), ('cp3', 'none', 'any'), ('py36', 'none', 'any'), ('py3', 'none', 'any')]
Traceback (most recent call last):
  File "/tmp/venv/bin/pex", line 11, in <module>
    sys.exit(main())
  File "/tmp/venv/lib/python3.6/site-packages/pex/bin/pex.py", line 694, in main
    pex_builder = build_pex(reqs, options, resolver_options_builder)
  File "/tmp/venv/lib/python3.6/site-packages/pex/bin/pex.py", line 624, in build_pex
    for dist in resolveds:
  File "/tmp/venv/lib/python3.6/site-packages/pex/resolver.py", line 525, in resolve_multi
    use_manylinux=use_manylinux):
  File "/tmp/venv/lib/python3.6/site-packages/pex/resolver.py", line 451, in resolve
    return resolver.resolve(resolvables_from_iterable(requirements, builder))
  File "/tmp/venv/lib/python3.6/site-packages/pex/resolver.py", line 248, in resolve
    dist = self.build(package, resolvable.options)
  File "/tmp/venv/lib/python3.6/site-packages/pex/resolver.py", line 206, in build
    raise Untranslateable('Package %s is not translateable by %s' % (package, translator))
pex.resolver.Untranslateable: Package SourcePackage('https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz#sha256=a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665') is not translateable by ChainedTranslator(EggTranslator, SourceTranslator)
```

Now with pex 1.3.2
```
$ pip install pex==1.3.2
Collecting pex==1.3.2
  Using cached https://files.pythonhosted.org/packages/3f/9b/f51ef7c7b11cca294aae13151aef81721a1ae965ab252c3656bf8f385356/pex-1.3.2-py2.py3-none-any.whl
Requirement already satisfied: wheel<0.30.0,>=0.26.0 in ./venv/lib/python3.6/site-packages (from pex==1.3.2) (0.29.0)
Requirement already satisfied: setuptools<34.0,>=20.3 in ./venv/lib/python3.6/site-packages (from pex==1.3.2) (33.1.1)
Installing collected packages: pex
  Found existing installation: pex 1.4.0
    Uninstalling pex-1.4.0:
      Successfully uninstalled pex-1.4.0
Successfully installed pex-1.3.2

$ pex MarkupSafe --disable-cache --no-wheel -vvv -o test.pex 
pex: Warning, using a UrllibContext which is known to be flaky.                            
pex: Please build pex with the requests module for more reliable downloads.
pex: crawling link i=0 link=Link('https://pypi.python.org/simple/MarkupSafe/') follow_links=False
pex: Building pex :: Resolving distributions :: Fetching https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz#sha256=a6be69091dac236eapex: Building pex :: Resolving distributions :: Fetching https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz#sha256=a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665 :: Fetching https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz#sha256=a6be69091dac23pex: Building pex :: Resolving distributions :: Translating /tmp/tmpmgz27k07/MarkupSafe-1.0.tar.gz into distribution                                                                                                                                                                                                                                                                                                                  MarkupSafe 1.0x :: Resolving distributions :: Translating /tmp/tmpmgz27k07/MarkupSafe-1.0.tar.gz into distribution :: Packaging MarkupSafe :: Installing /tmp/tmpm8qyvnr9
pex: Building pex: 494.6ms                                                                                                                                                 
pex:   Resolving interpreters: 0.6ms
pex:     Setting up interpreter /tmp/venv/bin/python3: 0.6ms
pex:   Resolving distributions: 493.3ms
pex:     Fetching https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz#sha256=a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665: 58.0ms
pex:       Fetching https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/MarkupSafe-1.0.tar.gz#sha256=a6be69091dac236ea9c6bc7d012beab42010fa914c459791d627dad4910eb665: 57.6ms
pex:     Translating /tmp/tmpmgz27k07/MarkupSafe-1.0.tar.gz into distribution: 326.6ms
pex:       Packaging MarkupSafe: 322.4ms
pex:         Installing /tmp/tmpm8qyvnr9: 320.5ms
Saving PEX file to test.pex
```


thanks!

Resolving patch:
diff --git a/pex/package.py b/pex/package.py
--- a/pex/package.py
+++ b/pex/package.py
@@ -155,15 +155,20 @@ def __init__(self, url, **kw):
       raise self.InvalidPackage('Could not match egg: %s' % filename)
 
     self._name, self._raw_version, self._py_version, self._platform = matcher.group(
-        'name', 'ver', 'pyver', 'plat')
+        'name', 'ver', 'pyver', 'plat'
+    )
 
     if self._raw_version is None or self._py_version is None:
       raise self.InvalidPackage('url with .egg extension but bad name: %s' % url)
 
+    impl = 'py' + self._py_version.replace('.', '')
     abi_tag = 'none'
-    tag_platform = self._platform or 'any'
-    self._supported_tags = set()
-    self._supported_tags.add(('py' + self._py_version.replace('.', ''), abi_tag, tag_platform))
+    tag_platform = (self._platform or 'any').replace('-', '_')
+
+    self._supported_tags = set([(impl, abi_tag, tag_platform)])
+    if tag_platform != 'any':
+      self._supported_tags.add((impl, abi_tag, 'any'))
+
     # Work around PyPy versions being weird in pep425tags.get_supported
     if self.py_version == '2.7':
       self._supported_tags.add(('pp2', abi_tag, tag_platform))


Test patch:
diff --git a/pex/testing.py b/pex/testing.py
--- a/pex/testing.py
+++ b/pex/testing.py
@@ -27,6 +27,7 @@
 IS_LINUX = "platform.system() == 'Linux'"
 IS_NOT_LINUX = "platform.system() != 'Linux'"
 NOT_CPYTHON27_OR_OSX = "%s or %s" % (NOT_CPYTHON27, IS_NOT_LINUX)
+NOT_CPYTHON27_OR_LINUX = "%s or %s" % (NOT_CPYTHON27, IS_LINUX)
 NOT_CPYTHON36_OR_LINUX = "%s or %s" % (NOT_CPYTHON36, IS_LINUX)
 
 
diff --git a/tests/test_integration.py b/tests/test_integration.py
--- a/tests/test_integration.py
+++ b/tests/test_integration.py
@@ -17,6 +17,7 @@
 from pex.pex_bootstrapper import get_pex_info
 from pex.testing import (
     IS_PYPY,
+    NOT_CPYTHON27,
     NOT_CPYTHON27_OR_OSX,
     NOT_CPYTHON36,
     NOT_CPYTHON36_OR_LINUX,
@@ -830,3 +831,14 @@ def test_pex_manylinux_runtime():
 
     out = subprocess.check_output([pex_path, tester_path])
     assert out.strip() == '[1, 2, 3]'
+
+
+@pytest.mark.skipif(NOT_CPYTHON27)
+def test_platform_specific_egg_resolution():
+  with temporary_dir() as td:
+    pex_out_path = os.path.join(td, 'pex.pex')
+    res = run_pex_command(['--disable-cache',
+                           '--no-wheel',
+                           'MarkupSafe==1.0',
+                           '-o', pex_out_path])
+    res.assert_success()