Ensure stdlib check uses normalized paths.

Review Request #2693 - Created Aug. 24, 2015 and submitted

Information
John Sirois
pants
jsirois/python-checkstyle/fix-stdlib-detection
2005, 2054, 2059
31bafb0...
Reviewers
pants-reviews
molsen
Previously, it was observed that the python __file__ might point to a
symlinked path whereas the `sysconfig.get_python_lib(standard_lib=1)`
path might be to the real path.  This led to mis-categorization of
stdlib imports as third party.  This fix ensures all paths are realpaths
to remove any ambiguity.

Also remove the unused PLAT_SPECIFIC_PATH.

 src/python/pants/backend/python/tasks/checkstyle/import_order.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Before the fix got errors like:

$ ./pants test tests/python/pants_test/backend/python/tasks/checkstyle -- -vktest_classify_import
...
   def test_classify_import():
     for index, (import_type, chunk) in enumerate(IMPORT_CHUNKS.items()):
       io = ImportOrder(PythonFile(chunk))
       import_chunks = list(io.iter_import_chunks())
       assert len(import_chunks) == 1
       module_types, chunk_errors = io.classify_imports(import_chunks[0])
       assert len(module_types) == 1
>       assert module_types.pop() == import_type, print('>>> [{}] type: {} chunk: {}'.format(index, import_type, chunk))
E       AssertionError: None
E       assert 5 == 1
E        +  where 5 = <built-in method pop of set object at 0x7ff8cf8814d8>()
E        +    where <built-in method pop of set object at 0x7ff8cf8814d8> = set([]).pop

This was on arch linux where:

$ ls -l /usr/lib64
lrwxrwxrwx 1 root root 3 Feb 15  2015 /usr/lib64 -> lib

And debug prints revealed:

>>> iter: 0 type: 1 chunk:
import ast
from collections import namedtuple
import io
>>> __file__: /usr/lib64/python2.7/ast.pyc stdlib: /usr/lib/python2.7
>>> __file__: /usr/lib64/python2.7/collections.pyc stdlib: /usr/lib/python2.7
>>> __file__: /usr/lib64/python2.7/io.pyc stdlib: /usr/lib/python2.7

CI went green here:
https://travis-ci.org/pantsbuild/pants/builds/77063786

Matt Olsen
John Sirois
John Sirois
John Sirois
Review request changed

Status: Closed (submitted)

Loading...