google/importlab

Improve the default value of the --python-version option

rchen152 opened this issue · 5 comments

EDIT: this post now demonstrates how easy it is to forget to set -V.

Repro:

echo "import django" > foo.py
echo "import jinja2" > bar.py
virtualenv --python=python3.5 .venv
source .venv/bin/activate
pip install importlab django jinja2
importlab --tree foo.py
importlab --tree bar.py

Neither dependency is found. Replace python3.5 with python3.6, and both are found.

importlab defaults to 3.6 if no version is passed. with -V 3.5 foo works, though bar still has some issue

$ importlab --tree -V 3.5 foo.py

works, but

$ importlab --tree -V 3.5 bar.py
Reading 1 files
Source tree:
+ bar.py

Unreadable files:
  /home/mdemello/github/importlab/.venv/lib/python3.5/site-packages/jinja2/__init__.py

Oh, right. D'oh.

i've made that mistake too :) perhaps we should remove the default and insist on -V being passed.

Another possibility would be to default to the host Python version; apparently that's almost always the sensible default for open source projects (according to Thomas).

google/pytype#192 for a similar pytype issue.

Based on the discussion on the pytype bug, I think my original report was entirely wrong - importlab finds the pip-installed modules just fine with -V3.5, but the 3.6 default is confusing. We could either remove the default, as you suggested, or change it something more sensible, perhaps the host version.

As an aside, Brian mentioned that jinja2 loads different files depending on sys.platform, so that may be the cause of the unparseability.