2016-03-28 17 views
1

Anlaşılır yürütme kitabındaki virtualenv öğesine project ve lib dizinini eklemem gerekiyor. Böyle bağımlılıkları yüklüyorum: Ben ile yapabilirsiniz geliştirme makinesindeansible: virtualenv'ye bir projeye özel yol eklenmesi

- pip: 
    name: virtualenv 

- pip: 
    requirements: "{{project_dir}}requirements/development.txt" 
    virtualenv: "{{ virtualenv_path }}" 
    state: latest 

:

$ add2virtualenv project 
$ add2virtualenv lib 

ama sunucuda virtualenvwrapper yüklemek için wan't yoktur. Yani, sanalenv'i bu durumda düzgün şekilde kurmak için deyimsel yol nedir?

cevap

0

yerine add2virtualenvdoing this Bunun aşağıdaki shell script kullanabilirsiniz:

anda aktif virtualenv için Python yoluna belirtilen dizinleri ekler.

dizimi:

add2virtualenv dizin1 dizin2 ...

Bazen sistem site paketleri dizin değildir ve her virtualenv kurulmamalıdır hangi yüklü paketleri paylaşmak için arzu edilir. Olası bir çözüm, kaynak site-paketleri dizinine kaynağını bağlamaktır, ancak add2virtualenv kullanarak site paketleri içinde .pth dosyasına dahil ederek PYTHONPATH'a ek dizinler eklemek de kolaydır.

Check out the source for a big project, such as Django. 
Run: add2virtualenv path_to_source. 
Run: add2virtualenv. 
A usage message and list of current “extra” paths is printed. 

dizin adları _virtualenv_path_extensions.pth ortamı için site paketleri dizininde içine adında bir yol dosyaya eklenir.

Kabuk komut dosyası:

# Path management for packages outside of the virtual env. 
# Based on a contribution from James Bennett and Jannis Leidel. 
# 
# add2virtualenv directory1 directory2 ... 
# 
# Adds the specified directories to the Python path for the 
# currently-active virtualenv. This will be done by placing the 
# directory names in a path file named 
# "virtualenv_path_extensions.pth" inside the virtualenv's 
# site-packages directory; if this file does not exist, it will be 
# created first. 
# 
#:help:add2virtualenv: add directory to the import path 
function add2virtualenv { 
    virtualenvwrapper_verify_workon_home || return 1 
    virtualenvwrapper_verify_active_environment || return 1 

    site_packages="`virtualenvwrapper_get_site_packages_dir`" 

    if [ ! -d "${site_packages}" ] 
    then 
     echo "ERROR: currently-active virtualenv does not appear to have a site-packages directory" >&2 
     return 1 
    fi 

    # Prefix with _ to ensure we are loaded as early as possible, 
    # and at least before easy_install.pth. 
    path_file="$site_packages/_virtualenv_path_extensions.pth" 

    if [ "$*" = "" ] 
    then 
     echo "Usage: add2virtualenv dir [dir ...]" 
     if [ -f "$path_file" ] 
     then 
      echo 
      echo "Existing paths:" 
      cat "$path_file" | grep -v "^import" 
     fi 
     return 1 
    fi 

    remove=0 
    if [ "$1" = "-d" ] 
    then 
     remove=1 
     shift 
    fi 

    if [ ! -f "$path_file" ] 
    then 
     echo "import sys; sys.__plen = len(sys.path)" > "$path_file" || return 1 
     echo "import sys; new=sys.path[sys.__plen:]; del sys.path[sys.__plen:]; p=getattr(sys,'__egginsert',0); sys.path[p:p]=new; sys.__egginsert = p+len(new)" >> "$path_file" || return 1 
    fi 

    for pydir in "[email protected]" 
    do 
     absolute_path="$(virtualenvwrapper_absolutepath "$pydir")" 
     if [ "$absolute_path" != "$pydir" ] 
     then 
      echo "Warning: Converting \"$pydir\" to \"$absolute_path\"" 1>&2 
     fi 

     if [ $remove -eq 1 ] 
     then 
      sed -i.tmp "\:^$absolute_path$: d" "$path_file" 
     else 
      sed -i.tmp '1 a\ 
'"$absolute_path"' 
' "$path_file" 
     fi 
     rm -f "${path_file}.tmp" 
    done 
    return 0 
}