Skip to content

Commit

Permalink
added 'shim' script. fixed #59
Browse files Browse the repository at this point in the history
  • Loading branch information
ekalinin committed May 13, 2014
1 parent 087e610 commit 573c065
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------

Expand Down
13 changes: 11 additions & 2 deletions nodeenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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*
Expand Down

0 comments on commit 573c065

Please sign in to comment.