GithubHelp home page GithubHelp logo

vip's Introduction

Build Status

vip is a simple library that makes your python and pip aware of existing virtualenv underneath. In its design, it is inspired by Git and its way of handling its repositories.

Philosophy

In its concept vip is similar to git. It assumes that your virtualenv is located in .vip directory, somewhere in the directory structure of your project.

In addition to the .vip directory, requirements.txt file is created, which lists all installed packages. Presence of this file allows to recreate virtualenv later. It is highly recommended to be included in source control.

The requirements.txt file is updated anytime you install a package in environment.

No need to source bin/activate any more!

Usage

Note that some of the features described here are not implmented yet (see Issues for details)

Initialization of a brand new virtual environment is as simple as typing:

vip --init [directory]

In addition, init command automatically detects presence of requirements.txt file and installs all packages listed inside, which is useful, when you checkout a new repository somewhere, and you want to recreate the environment.

When you want to use Python interpreter from your environment, just prefix it with vip:

vip python -c "print 'Hi!'"

pip command is available in the same way:

vip pip install requests fabric -i http://example.my.pypi/simple

In fact any command located in .vip/bin is available simply by prefixing its name with vip. vip searches for .vip directory along the path up to the root, and if it does find it, it delegates all command-line arguments to desired executable inside bin directory.

You can find out where your environment is by typing:

vip --locate

which is useful for locating Python interpreter, and running it from shell:

time `vip --locate`/bin/python script.py

In this case, performance of interpreter execution will not be affected at all.

You can get rid of a virtual environment by typing:

vip --purge   # equivalent of rm -rf .vip

Updating requirements.txt file

In most common case dependency listing is updated automatically, so whenever you run vip pip (un)install or vip easy_install command, requirements.txt file is updated on successful completion.

In case your dependencies changed in some other way, you can update dependency listing by typing:

vip --update   # which is roughly equivalent to
               #   vip pip freeze > requirements.txt

Do not forget to include this file in next commit!

Too much typing?

You can alias most frequently used commands to stop prefixing them constantly with vip. Add this to your ~/.bashrc file:

alias python="`vip -l`/bin/python"
alias pip="`vip -l`/bin/pip"

Note, that it will fail when there will be no .vip directory up to the root.

Use-cases

No root privileges

You can type vip --init in your home directory, add aliases to your ~/.bashrc file and enjoy the new way of working with python and pip in a shell, where you cannot install packages globally in the system.

rvm does the same thing.

Self-contained projects

requirements.txt file allows to recreate environment when the project location changes, which is a simple workaround for experimental --relocatable option for virtualenv.

In addition, You can actually use requirements.txt file as your install requirements source for setup.py script.

Limitations

To keep things simple, vip does not allow for user interactions with a child process, so you cannot use interactive Python shell.

Simple workaround:

`vip -l`/bin/python

Also, any pip uninstallations will fail, because user has to confirm deletion. You can bypass this issue simply adding -y switch to uninstall command:

vip pip uninstall -y tornado

Installation

Simply type the following command into terminal to install the latest released version:

pip install vip

Contribution

Feel free to file a bug report, or send a pull request. I will try my best to look into it and merge your changes.

vip's People

Contributors

dejw avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

juntalis

vip's Issues

Smart install command

Install (now --ini) can be smart enough to install only those requirement files that matches interpreter version, eg:

for Python 2.6 install can install *requirements.txt, *requirements.2.txt and *requirements.26.txt.

In that case one can create a set of requirement files, each for certain interpreter version.

Also install could update environment to reflect changes in those files, e.g uninstall removed dependencies.

Implement updating requirements.txt

There are two options:

  • automatically update requirements.txt file after each (un)install command
  • let the developer to update the file and call vip --update each time (s)he does this

In favor of (1) is the reason to keep everything simple, but explicit is better than implicit.

Option (2) is explicit which is good. In addition to (2), requirements.txt.lock can be created in order to list all used packages (similar how bundler does in Ruby).

Sometimes SIGINT is not propagated correctly

I tried to install some package using vip pip install package and hit Control-C.

After a while I saw:

Operation cancelled by user
Storing complete log in ~/.pip/pip.log

which means that signal was not propagated correctly.

Add support for --system-site-packages flag for virtualenv

I found myself in a situation when I had non pip dependency, installed system-wide (pynotify in this example).

In this case I had to run virtualenv --system-site-packages .vip command manually. In this case it is obvious that some flags should be propagated to virtualenv command. Maybe all?

Hangs on Windows

Hey,

Noticed an issue where trying to initialize a new vip environment on Windows would result in the script hanging forever. It appears to be caused by line 59 in the vip/core.py file. Making the following change to that line seems to make it work fine on Windows.

    while directory != "/" or head:

to

    while (directory != "/" and directory[1:] != ':\\' and directory[1:] != ':/') or head:

Was debating forking and doing a pull request, but I figured this would be easier.

Status code is not propagated

Exit status of executed command is not propagated too the shell, e.g. when running vip pep8 and having some errors, status code is still 0.

Think of a better interface

Since I used vip only to install (update, or remove) libraries and run something using installed Python, interface can be on even higher level than it is now.

Example:
vip install - create a virtualenv and update its state - install, update, remove libraries listed in requirements.txt file
vip test [filename] - to run tests, using nose, py.test, unittest2 or simply executing python interpreter on given files
vip locate [binary] - to locate binaries inside the virtualenv underneath

Integration test required

An integration test is required that will test vip.main behavior in an end-user maner:

cd some-directory
echo 'some-package` > requirements.txt
...
vip --init
vip pip install
vip pip freeze > pckgs.txt

assert 'some-package' in pckgs.txt

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.