From 573c06509e20d644c976f8bff0b663d895d1a9eb Mon Sep 17 00:00:00 2001 From: Eugene Kalinin Date: Tue, 13 May 2014 17:35:09 +0400 Subject: [PATCH] added 'shim' script. fixed #59 --- CHANGES | 6 ++++++ README.rst | 6 ++++++ nodeenv.py | 13 +++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index b685e92..526b34a 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,12 @@ Nodeenv changelog ================= +Version 0.9.0 +------------- +- Added `shim` script. See `# 59`_ + +.. _# 59: https://github.com/ekalinin/nodeenv/issues/59 + Version 0.8.2 ------------- - Fixed prebuilt installation: diff --git a/README.rst b/README.rst index de2140d..79877aa 100644 --- a/README.rst +++ b/README.rst @@ -196,6 +196,12 @@ file you can use ``--update`` option:: $ . env-4.3/bin/activate (env-4.3)$ nodeenv --update=./requirements.txt +If you whant to call node from environment without activation then you shoould +use `shim` script: + + $ ./env-4.3/bin/shim --version + v0.4.3 + Alternatives ------------ diff --git a/nodeenv.py b/nodeenv.py index a57f626..b83678e 100644 --- a/nodeenv.py +++ b/nodeenv.py @@ -10,7 +10,7 @@ :license: BSD, see LICENSE for more details. """ -nodeenv_version = '0.8.2' +nodeenv_version = '0.9.0' import sys import os @@ -502,18 +502,20 @@ def install_activate(env_dir, opt): """ Install virtual environment activation script """ - files = {'activate': ACTIVATE_SH} + files = {'activate': ACTIVATE_SH, 'shim': SHIM} bin_dir = join(env_dir, 'bin') mod_dir = join('lib', 'node_modules') prompt = opt.prompt or '(%s)' % os.path.basename(os.path.abspath(env_dir)) mode_0755 = (stat.S_IRWXU | stat.S_IXGRP | stat.S_IRGRP | stat.S_IROTH | stat.S_IXOTH) + shim_node = "`which node`" if opt.node == "system" else bin_dir for name, content in files.items(): file_path = join(bin_dir, name) content = content.replace('__NODE_VIRTUAL_PROMPT__', prompt) content = content.replace('__NODE_VIRTUAL_ENV__', os.path.abspath(env_dir)) + content = content.replace('__SHIM_NODE__', shim_node) content = content.replace('__BIN_NAME__', os.path.basename(bin_dir)) content = content.replace('__MOD_NAME__', mod_dir) writefile(file_path, content, append=opt.python_virtualenv) @@ -629,6 +631,13 @@ def main(): unset NODE_VIRTUAL_ENV_DISABLE_PROMPT """ +SHIM = """ +#!/bin/sh +export NODE_PATH=__NODE_VIRTUAL_ENV__/lib/node_modules +export NPM_CONFIG_PREFIX=__NODE_VIRTUAL_ENV__ +exec __SHIM_NODE__/node $* +""" + ACTIVATE_SH = """ # This file must be used with "source bin/activate" *from bash*