Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asdf integration + handling shims? #35

Closed
AlJohri opened this issue Nov 9, 2018 · 25 comments
Closed

asdf integration + handling shims? #35

AlJohri opened this issue Nov 9, 2018 · 25 comments
Labels
enhancement New feature or request

Comments

@AlJohri
Copy link
Contributor

AlJohri commented Nov 9, 2018

Hi, I recently switched over from pyenv to asdf which is a cross-language replacement. Now I don't need pyenv, rbenv, nodenv all installed separately.

asdf uses python-build internally and installs everything into ~/.asdf/installs/python/.

$ ls -1 ~/.asdf/installs/python/
2.7.15
3.6.7
3.7.1/
  1. I was wondering if the pyenv integration was generic enough to be able to work with asdf as well

    The binaries are located at ~/.asdf/installs/python/3.7.1/bin/python for example which I think is identical to pyenv.

    I was thinking if I set PYENV_ROOT=$HOME/.asdf/installs/python/ it might work out?

  2. I didn't have much success testing since the shims were getting in the way. I imagine this issue would be identical in pyenv or asdf. If my global version is set to 3.7.1, a shim would exist for pyhon3.6 and it would not be "active". For example, running the python3.6 shim while python3.7 is global would result in an error message like:

    $ asdf global python 3.7.1 # set global version to 3.7.1
    $ python3.6
    No such command in 3.7.1 of python

    So it has to go straight to PYENV_ROOT for the binaries and skip the shims. I think Pyenv shims break all attempted executions for pythons not in versions list #27 addesses this but wasn't sure if it would work generically enough for asdf as well.

    EDIT: Looks like the shim path for asdf is $HOME/.asdf/shims so setting PYENV_ROOT as I did above would not work.

Thanks!

@techalchemy
Copy link
Member

To be honest I stopped using pyenv's shims because they break everything, but this should be relatively easy to port without pretending to have pyenv

IMO we should just add a specific adapter for asdf -- pyenv uses it's own finder type which gets registered here and we can just perform a similar check for asdf.

That said, honestly it might work anyway because like I mentioned I ignore pyenv shims now anyway, they are terrible.

@techalchemy techalchemy added the enhancement New feature or request label Nov 9, 2018
@techalchemy
Copy link
Member

When I say it might work anyway, I mean pyfinder --find 3.6 might work if you use the workaround you were trying

@uranusjr
Copy link
Member

uranusjr commented Nov 9, 2018

I’m thinking maybe we can introduce our own environment variable, so people can set to

PYTHONFINDER_ROOTS=~/.pyenv/versions:~/.asdf/installs/python

This would have a sensitive default as well. Does asdf expose an environment variable similar to PYENV_ROOT? It would be quite simple to interface if it does.

@AlJohri
Copy link
Contributor Author

AlJohri commented Nov 10, 2018

thanks @techalchemy, let me try that out

@uranusjr yes it does have an equivalent variable. the only thing different is where the pythons are located

  • root: PYENV_ROOT=$HOME/.pyenv vs ASDF_DATA_DIR=$HOME/.pyenv
  • shims: $PYENV_ROOT/shims vs $ASDF_DATA_DIR/shims
  • pythons: $PYENV_ROOT/versions vs $ASDF_DATA_DIR/installs/python

techalchemy added a commit that referenced this issue Nov 13, 2018
- Fixes #35

Signed-off-by: Dan Ryan <dan@danryan.co>
@techalchemy
Copy link
Member

PR is up, let me know if it works for you

@AlJohri
Copy link
Contributor Author

AlJohri commented Nov 13, 2018

@techalchemy that was super fast, thanks! I tried giving it a shot just now by replacing the vendored pythonfinder in pipenv but ran into an import error.

Traceback (most recent call last):
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/bin/pipenv", line 11, in <module>
    load_entry_point('pipenv==2018.10.13', 'console_scripts', 'pipenv')()
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/cli/command.py", line 249, in install
    editable_packages=state.installstate.editables,
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/core.py", line 1724, in do_install
    pypi_mirror=pypi_mirror,
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/core.py", line 565, in ensure_project
    pypi_mirror=pypi_mirror,
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/core.py", line 488, in ensure_virtualenv
    python = ensure_python(three=three, python=python)
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/core.py", line 401, in ensure_python
    path_to_python = find_a_system_python(python)
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/core.py", line 354, in find_a_system_python
    from .vendor.pythonfinder import Finder
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/__init__.py", line 14, in <module>
    from .pythonfinder import Finder
  File "/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 7, in <module>
    from vistir.compat import lru_cache
ImportError: cannot import name 'lru_cache' from 'vistir.compat' (/usr/local/Cellar/pipenv/2018.10.13_1/libexec/lib/python3.7/site-packages/pipenv/vendor/vistir/compat.py)

is there a better way to test?

@techalchemy
Copy link
Member

techalchemy commented Nov 13, 2018

you have two options -- you can install pythonfinder directly:

$ pip install -e git+https://github.com/sarugaku/pythonfinder.git@feature/asdf-support#egg=pythonfinder
$ pyfinder --findall

or you can install the working branch I already ported this to (bearing in mind the pipenv repo is massive):

pip intsall -e git+https://github.com/pypa/pipenv.git@update-vendor#egg=pipenv

@AlJohri
Copy link
Contributor Author

AlJohri commented Nov 13, 2018

let me give that a shot. in the mean time, just ran into this pypa/pipenv#3214 while trying to install via pipenv

@AlJohri
Copy link
Contributor Author

AlJohri commented Nov 13, 2018

I got this error (which has to do with shims)

Traceback (most recent call last):
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/bin/pyfinder", line 11, in <module>
    load_entry_point('pythonfinder', 'console_scripts', 'pyfinder')()
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/cli.py", line 33, in cli
    versions = [v for v in finder.find_all_python_versions()]
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/pythonfinder.py", line 121, in find_all_python_versions
    python_version_dict = getattr(self.system_path, "python_version_dict")
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/pythonfinder.py", line 53, in system_path
    ignore_unsupported=self.ignore_unsupported,
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 419, in create
    for p in _path_objects
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 419, in <dictcomp>
    for p in _path_objects
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 539, in create
    _new = cls(**creation_args)
  File "<attrs generated init 118615c65267bfc1863cbf5e6f1d4854e12c3322>", line 20, in __init__
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 495, in get_pythons
    for path, entry in self.children.items():
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/cached_property.py", line 35, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 469, in children
    for child_key, child_val in self._gen_children():
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 462, in _gen_children
    yield (child.as_posix(), PathEntry.create(path=child, **pass_args))
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 539, in create
    _new = cls(**creation_args)
  File "<attrs generated init 118615c65267bfc1863cbf5e6f1d4854e12c3322>", line 16, in __init__
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 485, in get_py_version
    py_version = PythonVersion.from_path(path=self, name=self.name)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/python.py", line 203, in from_path
    instance_dict = cls.parse(py_version)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/python.py", line 151, in parse
    raise ValueError("Not a valid python version: %r" % version)
ValueError: Not a valid python version: <LegacyVersion('No such command in 3.7.1 2.7.15 of python')>

The error might be confusing because my global python is set to both 3.7.1 2.7.15. Basically, it's trying to run a python that is not currently active via its shim (likely 3.6.7) in my case.

do you need to add: self._remove_path(os.path.join(ASDF_DATA_DIR, "shims")) ?

@techalchemy
Copy link
Member

no it's just parsing your global file poorly...

@techalchemy
Copy link
Member

@AlJohri can you give me the output of ls -al ~/.asdf/.pyenv and ~/.asdf/python/?

@AlJohri
Copy link
Contributor Author

AlJohri commented Nov 13, 2018

I appreciate you taking the time out to figure this out!

cat $HOME/.tool-versions
python 3.7.1 2.7.15
nodejs 11.1.0
ruby 2.5.3

Those two paths don't exist. I think you're looking for?

ls -al ~/.asdf/installs/python
total 0
drwxr-xr-x  5 johria  1978051377  160 Nov  9 02:58 ./
drwxr-xr-x  5 johria  1978051377  160 Nov  7 16:56 ../
drwxr-xr-x  6 johria  1978051377  192 Nov  7 18:13 2.7.15/
drwxr-xr-x  6 johria  1978051377  192 Nov  9 03:00 3.6.7/
drwxr-xr-x  6 johria  1978051377  192 Nov  7 16:52 3.7.1/

Here's a broader view of the tree structure if that helps:

tree -L 3 -I "bin|shims|test|repository|lib" .asdf
.asdf
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── VERSION
├── Vagrantfile
├── asdf.fish
├── asdf.sh
├── ballad-of-asdf.md
├── completions
│   ├── asdf.bash
│   └── asdf.fish
├── defaults
├── docs
│   ├── creating-plugins.md
│   └── uninstall.md
├── help.txt
├── installs
│   ├── nodejs
│   │   └── 11.1.0
│   ├── python
│   │   ├── 2.7.15
│   │   ├── 3.6.7
│   │   └── 3.7.1
│   └── ruby
│       └── 2.5.3
├── lint.sh
├── plugins
│   ├── nodejs
│   │   ├── LICENSE
│   │   ├── README.md
│   │   └── npm-hooks
│   ├── python
│   │   ├── LICENSE
│   │   ├── README.md
│   │   ├── pyenv
│   │   └── pyenv_last_update
│   └── ruby
│       ├── LICENSE
│       ├── README.md
│       ├── ruby-build
│       └── rubygems-plugin
├── release.sh
└── tmp
    └── repo-updated

20 directories, 25 files

pyenv is installed at ~/.asdf/plugins/python/pyenv although I'm not sure there's anything useful in there for pythonfinder?

the actual pythons are at:

  • ~/.asdf/installs/python/3.7.1/bin/python
  • ~/.asdf/installs/python/3.6.7/bin/python
  • etc.

and of course, the shims are at ~/.asdf/shims

@techalchemy
Copy link
Member

Ah yep exactly what I need. The file is a bit different. The pipenv issue is fixed on that branch also now

@techalchemy
Copy link
Member

Will handle this in the morning hopefully before I cut a release, assuming tests pass before that

@techalchemy
Copy link
Member

ok i think the new version will work... if you dont mind, it would be helpful if you could try it out

@AlJohri
Copy link
Contributor Author

AlJohri commented Nov 13, 2018

sure, giving it a shot

@AlJohri
Copy link
Contributor Author

AlJohri commented Nov 13, 2018

I tried with the same installation command as above, from the PR branch.

with my global version set as before (3.7.1 2.7.15), I got:

Traceback (most recent call last):
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/bin/pyfinder", line 11, in <module>
    load_entry_point('pythonfinder', 'console_scripts', 'pyfinder')()
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/cli.py", line 33, in cli
    versions = [v for v in finder.find_all_python_versions()]
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/pythonfinder.py", line 121, in find_all_python_versions
    python_version_dict = getattr(self.system_path, "python_version_dict")
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/pythonfinder.py", line 53, in system_path
    ignore_unsupported=self.ignore_unsupported,
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 434, in create
    for p in _path_objects
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 434, in <dictcomp>
    for p in _path_objects
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 557, in create
    _new = cls(**creation_args)
  File "<attrs generated init 313b4fb5ec2257cb014a89624edb99c53f074594>", line 20, in __init__
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 513, in get_pythons
    for path, entry in self.children.items():
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/cached_property.py", line 35, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 484, in children
    for child_key, child_val in self._gen_children():
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 477, in _gen_children
    yield (child.as_posix(), PathEntry.create(path=child, **pass_args))
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 557, in create
    _new = cls(**creation_args)
  File "<attrs generated init 313b4fb5ec2257cb014a89624edb99c53f074594>", line 16, in __init__
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 500, in get_py_version
    py_version = PythonVersion.from_path(path=self, name=self.name)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/python.py", line 418, in from_path
    instance_dict = cls.parse(py_version)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/python.py", line 366, in parse
    raise ValueError("Not a valid python version: %r" % version)
ValueError: Not a valid python version: <LegacyVersion('No such command in 3.7.1 2.7.15 of python')>

in case it was related to that, I tried to set my global version to just one python (3.7.1) but I got the same error again:

Traceback (most recent call last):
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/bin/pyfinder", line 11, in <module>
    load_entry_point('pythonfinder', 'console_scripts', 'pyfinder')()
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/cli.py", line 33, in cli
    versions = [v for v in finder.find_all_python_versions()]
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/pythonfinder.py", line 121, in find_all_python_versions
    python_version_dict = getattr(self.system_path, "python_version_dict")
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/pythonfinder.py", line 53, in system_path
    ignore_unsupported=self.ignore_unsupported,
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 434, in create
    for p in _path_objects
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 434, in <dictcomp>
    for p in _path_objects
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 557, in create
    _new = cls(**creation_args)
  File "<attrs generated init 2665ebec158bcaee679ac71471c44977d17a6fac>", line 20, in __init__
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 513, in get_pythons
    for path, entry in self.children.items():
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/lib/python3.7/site-packages/cached_property.py", line 35, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 484, in children
    for child_key, child_val in self._gen_children():
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 477, in _gen_children
    yield (child.as_posix(), PathEntry.create(path=child, **pass_args))
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 557, in create
    _new = cls(**creation_args)
  File "<attrs generated init 2665ebec158bcaee679ac71471c44977d17a6fac>", line 16, in __init__
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/path.py", line 500, in get_py_version
    py_version = PythonVersion.from_path(path=self, name=self.name)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/python.py", line 418, in from_path
    instance_dict = cls.parse(py_version)
  File "/Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/src/pythonfinder/src/pythonfinder/models/python.py", line 366, in parse
    raise ValueError("Not a valid python version: %r" % version)
ValueError: Not a valid python version: <LegacyVersion('No such command in 3.7.1 of python')>

If you've spent too much time on this @techalchemy and need to cut a release, I can debug this over the weekend for a follow up release?

@AlJohri
Copy link
Contributor Author

AlJohri commented Nov 13, 2018

Also, I set my global python to all three (asdf global python 3.7.1 3.6.7 2.7.15) and made it work:

python3: 3.7.1 (None) @ /Users/johria/.local/share/virtualenvs/newproject-pYEZLETE/bin/python3
python3: 3.7.1 (None) @ /Users/johria/.asdf/shims/python3
python: 3.7.1 (None) @ /Users/johria/.asdf/shims/python
python3.7m: 3.7.1 (None) @ /Users/johria/.asdf/shims/python3.7m
python3.7: 3.7.1 (None) @ /Users/johria/.asdf/shims/python3.7
python3: 3.7.1 (None) @ /usr/local/bin/python3
python3.7m: 3.7.1 (None) @ /usr/local/bin/python3.7m
python3.6: 3.6.7 (None) @ /Users/johria/.asdf/shims/python3.6
python3.6m: 3.6.7 (None) @ /Users/johria/.asdf/shims/python3.6m
python2: 2.7.15 (None) @ /Users/johria/.asdf/shims/python2
python2.7: 2.7.15 (None) @ /Users/johria/.asdf/shims/python2.7
python: 2.7.15 (None) @ /usr/local/bin/python
pythonw: 2.7.15 (None) @ /usr/local/bin/pythonw
python: 2.7.10 (None) @ /usr/bin/python
pythonw: 2.7.10 (None) @ /usr/bin/pythonw
python2.7: 2.7.10 (None) @ /usr/bin/python2.7

@AlJohri
Copy link
Contributor Author

AlJohri commented Nov 13, 2018

Note how all the pythons are pointing to shims instead of the true binaries though

@techalchemy
Copy link
Member

What's interesting is:

        py_version = get_python_version(path.path.absolute().as_posix())
        instance_dict = cls.parse(py_version.strip())

This code is failing in the error -- I just swapped it to turn the path into an absolute path -- but then it raises this:

        if not isinstance(instance_dict.get("version"), Version) and not IGNORE_UNSUPPORTED:
            raise ValueError("Not a valid python path: %s" % path.path)
            return

What's weird is it literally shouuld invoke every python it encounters on your path. I'm going to do two things -- remove the asdf shims and also double check the asdf version file -- is it actually located in ~/.tool-versions or whatever? the function I'm using to parse it now is:

def parse_asdf_version_order(filename=".tool-versions"):
    version_order_file = normalize_path(os.path.join("~", filename))
    if os.path.exists(version_order_file) and os.path.isfile(version_order_file):
        with io.open(version_order_file, encoding="utf-8") as fh:
            contents = fh.read()
        python_section = next(iter(
            line for line in contents.splitlines() if line.startswith("python")
        ), None)
        if python_section:
            python_key, versions = python_section.partition()
            if versions:
                return versions.split()

Which I've just realized has no variable expansion so that may be the issue, let me push up the changes and we can see if that helps

@techalchemy
Copy link
Member

ok, branch pushed back up

@AlJohri
Copy link
Contributor Author

AlJohri commented Nov 16, 2018

just installed the latest pipenv via homebrew and it seems like it was unable to find my asdf pythons? no errors though!

screen shot 2018-11-16 at 11 51 13 am

$ pyfinder --version
pyfinder, version 1.1.9.post1
$ pyfinder --findall
python3: 3.7.1 (None) @ /usr/local/bin/python3
python3.7m: 3.7.1 (None) @ /usr/local/bin/python3.7m
python: 2.7.15 (None) @ /usr/local/bin/python
pythonw: 2.7.15 (None) @ /usr/local/bin/pythonw
python: 2.7.10 (None) @ /usr/bin/python
pythonw: 2.7.10 (None) @ /usr/bin/pythonw
python2.7: 2.7.10 (None) @ /usr/bin/python2.7

I'm just relieved those pesky shims are gone though 😂

@AlJohri
Copy link
Contributor Author

AlJohri commented Nov 16, 2018

I think I know what might be the issue.... the env var name might be wrong. The README of asdf says ASDF_DATA_DIR but on my computer it is:

screen shot 2018-11-16 at 11 58 14 am

@AlJohri
Copy link
Contributor Author

AlJohri commented Nov 16, 2018

Yes! That worked!

$ export ASDF_DATA_DIR=$ASDF_DIR
$ pyfinder --findall
3.7.1: 3.7.1 (None) @ /Users/johria/.asdf/installs/python/3.7.1/bin/python3
3.7.1: 3.7.1 (None) @ /Users/johria/.asdf/installs/python/3.7.1/bin/python3.7m
python3: 3.7.1 (None) @ /usr/local/bin/python3
python3.7m: 3.7.1 (None) @ /usr/local/bin/python3.7m
3.6.7: 3.6.7 (None) @ /Users/johria/.asdf/installs/python/3.6.7/bin/python3
3.6.7: 3.6.7 (None) @ /Users/johria/.asdf/installs/python/3.6.7/bin/python3.6m
2.7.15: 2.7.15 (None) @ /Users/johria/.asdf/installs/python/2.7.15/bin/python
python: 2.7.15 (None) @ /usr/local/bin/python
pythonw: 2.7.15 (None) @ /usr/local/bin/pythonw
python: 2.7.10 (None) @ /usr/bin/python
pythonw: 2.7.10 (None) @ /usr/bin/pythonw
python2.7: 2.7.10 (None) @ /usr/bin/python2.7

I will track down what's the canonical name env var name here asdf-vm/asdf#405

@AlJohri
Copy link
Contributor Author

AlJohri commented Nov 16, 2018

I got feedback from adsf on which env vars to rely on- I'll submit a PR with a fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants