mitsuhiko / pipsi

pip script installer
Other
2k stars 133 forks source link

pyenv integration #141

Open jamesstidard opened 6 years ago

jamesstidard commented 6 years ago

I currently use pyenv and pipenv on my machine to manage python versions and package dependencies - I assume people that use pipsi are quite likely to do the same. I feel like it would be nice to build the virtual environment for installed packages using pipenv - if it's present on the system.

pipenv already has an integration with pyenv where it'll download the python interpreter via pyenv, if it's not already. Currently you can specify a specific python interpreter with --python, but before this you need to:

  1. Check on the application you're installing which versions of python it supports from it's setup.py/Pipfile/pypi listing
  2. Download one of those versions in pyenv
  3. Set that as the global python or hand it's path as the --python argument

I think by using pipenv to create the virtual environment on install and update pipsi could remove those steps as well as automatically upgrade python interpreters for each application as a package owner depreciates them.

Would there be anything inherently sinful about this feature? I'm happy to have a go at implementing this if this seems like a feature pipsi would benefit from.

digitalresistor commented 6 years ago

Doesn't pipenv suggest the use of pipsi to do its installation? Isn't that a bit like a chicken and egg problem?

Also pipenv is all for developers and managing dependencies, whereas pipsi is about installing a tool and making it available in a stable bin path with managed virtualenvs. You don't need 90% of what pipenv provides in pipsi.

jamesstidard commented 6 years ago

@bertjwregeer that's a good point. Now you mention it, I think I got carried away getting to pipenv. It would really only be a pyenv integration that would be needed to do what I was after - selecting/installing the right interpreter for the tool and making the virtual environment as normal.

Does that sound a little more sensible?

Code0x58 commented 6 years ago

I just came across this thinking that I'd be able to type/think less in the future if pipsi realised that I don't have a python that matches the requirements of black (3.6) so went ahead and installed/used on in the virtualenv it made for it. Maybe I should just use containers for everting :thinking:

gwerbin commented 6 years ago

@bertjwregeer @jamesstidard I don't think it's a chicken/egg problem.

  1. Install some version of Python system-wide using your system package manager
  2. Bootstrap-install Pipsi under the system Python (ideally also using your system package manager)
  3. Install Pyenv using your system package manager
  4. Install Pipenv using your system package manager
  5. Use Pipsi to install additional system-wide packages, making use of Pipenv
  6. Use Pipenv to manually create environments for projects
  7. rm -rf ~/.anaconda3

I personally think Pyenv, Pipsi, and Pipenv serve different purposes and should be installed as "siblings". One manages Python installations, another is a secondary package manager for system-wide Python applications, and the third is a virtual environment manager. All three are "top-level" in my mind, just below the system package manager in terms of management authority.

RonnyPfannschmidt commented 6 years ago

pyenv integration is tricky - it needs support in both the package and the installer + a new release - im not familiar with pyenv myself and dont use it

gwerbin commented 6 years ago

it needs support in both the package and the installer + a new release

@RonnyPfannschmidt what do you mean by that?

Currently you have: https://github.com/mitsuhiko/pipsi/blob/16b6820c02ea84ffbbf1d48a6773829831308359/pipsi/__init__.py#L310-L316

In this case you would change it to something like

if isinstance(python, int):
    python_version = python
    python_exe = get_executable_name(python_version)
    python = get_executable_path(python_exe)
    if not python:
        raise ValueError('Can not find {} in PATH'.format(python_exe))
elif python == 'auto':
    python_version = get_minimum_python_version(package)
    executable_name = get_executable_name(python_version)
    python = get_executable_path(executable_name)
elif python and PYENV_INSTALLED:
    pyenv = Pyenv()
    pyenv_installed = pyenv.list_installed()
    if not check_if_in_path(python) and python not in pyenv_installed:
        pyenv.install(python, ask_confirmation=True)
        python = pyenv_installed[python].get_path()
else:
    python = sys.executable

Pyenv is just shell scripts. The hardest part would be writing wrapper methods to that parse its output.

RonnyPfannschmidt commented 6 years ago

i wouldn't change it at all since i'm not at all fluent in pyenv and dont use it myself - this has to come from someone that knows the details enough not to make a broken mess

gwerbin commented 6 years ago

That's fine. When I have some more time maybe I can experiment with this.

I will have to figure out testing, I've never written any tests for a piece of software like this before.