Code Monkey home page Code Monkey logo

nodeenv's Introduction

Node.js virtual environment

nodeenv (node.js virtual environment) is a tool to create isolated node.js environments.

It creates an environment that has its own installation directories, that doesn't share libraries with other node.js virtual environments.

Also the new environment can be integrated with the environment which was built by virtualenv (python).

If you use nodeenv feel free to add your project on wiki: Who-Uses-Nodeenv.

https://travis-ci.org/ekalinin/nodeenv.svg?branch=master

You can install nodeenv globally with easy_install:

$ sudo easy_install nodeenv

or with pip:

$ sudo pip install nodeenv

or on Debian using dpkg:

$ ln -s debian-upstream debian
$ dpkg-buildpackage -uc -us -b
$ sudo dpkg -i $(ls -1rt ../nodeenv_*.deb | tail -n1)

If you're using virtualenv then you can install nodeenv via pip/easy_install inside any virtual environment built with virtualenv:

$ virtualenv env
$ . env/bin/activate
(env) $ pip install nodeenv
(env) $ nodeenv --version
0.6.5

If you want to work with the latest version of the nodeenv you can install it from the github repository:

$ git clone https://github.com/ekalinin/nodeenv.git
$ ./nodeenv/nodeenv.py --help

or with pip:

$ pip install -e git+https://github.com/ekalinin/nodeenv.git#egg=nodeenv
  • python (2.6+, 3.5+, or pypy)
  • make
  • tail
  • libssl-dev

Create new environment:

$ nodeenv env

Activate new environment:

$ . env/bin/activate

Check versions of main packages:

(env) $ node -v
v0.10.26

(env) $ npm -v
1.4.3

Deactivate environment:

(env) $ deactivate_node

Get available node.js versions:

$ nodeenv --list
0.0.1   0.0.2   0.0.3   0.0.4   0.0.5   0.0.6   0.1.0
0.1.2   0.1.3   0.1.4   0.1.5   0.1.6   0.1.7   0.1.8
0.1.10  0.1.11  0.1.12  0.1.13  0.1.14  0.1.15  0.1.16
0.1.18  0.1.19  0.1.20  0.1.21  0.1.22  0.1.23  0.1.24
0.1.26  0.1.27  0.1.28  0.1.29  0.1.30  0.1.31  0.1.32
0.1.90  0.1.91  0.1.92  0.1.93  0.1.94  0.1.95  0.1.96
0.1.98  0.1.99  0.1.100 0.1.101 0.1.102 0.1.103 0.1.104
0.2.1   0.2.2   0.2.3   0.2.4   0.2.5   0.2.6   0.3.0
0.3.2   0.3.3   0.3.4   0.3.5   0.3.6   0.3.7   0.3.8
0.4.1   0.4.2   0.4.3   0.4.4   0.4.5   0.4.6

Install node.js "0.4.3" without ssl support with 4 parallel commands for compilation and npm.js "0.3.17":

$ nodeenv --without-ssl --node=0.4.3 --npm=0.3.17 --with-npm --jobs=4 env-4.3

Install node.js from the source:

$ nodeenv --node=0.10.25 --source env-0.10.25

Install node.js from a mirror:

$ nodeenv --node=10.19.0 --mirror=https://npm.taobao.org/mirrors/node

It's much faster to install from the prebuilt package than Install & compile node.js from source:

$ time nodeenv --node=0.10.25 --prebuilt env-0.10.25-prebuilt
 + Install node.js (0.10.25) ... done.

real    0m6.928s
user    0m0.408s
sys     0m1.144s

$ time nodeenv --node=0.10.25 --source env-0.10.25-src
 + Install node.js (0.10.25) ... done.

real    4m12.602s
user    6m34.112s
sys     0m30.524s

Create a new environment with the system-wide node.js:

$ nodeenv --node=system

Saving the versions of all installed packages to a file:

$ . env-4.3/bin/activate
(env-4.3)$ npm install -g express
(env-4.3)$ npm install -g jade
(env-4.3)$ freeze ../prod-requirements.txt

If you want to list locally installed packages use -l option:

(env-4.3)$ freeze -l ../prod-requirements.txt

Create an environment from a requirements file:

$ nodeenv --requirements=../prod-requirements.txt --jobs=4 env-copy

Requirements files are plain text files that contain a list of packages to be installed. These text files allow you to create repeatable installations. Requirements file example:

$ cat ../prod-requirements.txt
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

If you already have the python virtualenv tool, and want to use nodeenv and virtualenv in conjunction, then you should create (or activate) the python virtual environment:

# in case of using virtualenv_wrapper
$ mkvirtualenv my_env

# in case of using virtualenv
$ . my_env/bin/activate

and add a node virtual environment to this existing new_venv:

$ nodeenv -p

If you need to set the path to make used to build node:

$ nodeenv -m /usr/local/bin/gmake ENV

That's all. Now, all your node.js modules will be installed into your virtual environment:

$ workon my_env
$ npm install -g coffee-script
$ command -v coffee
/home/monty/virtualenvs/my_env/bin/coffee

Creating a virtual environment with a custom prompt:

$ nodeenv --node=12.18.2 --prompt="(myenv)" nodeenv

If environment's directory already exists then you can use --force option:

$ nodeenv --requirements=requirements.txt --jobs=4 --force env

If you already have an environment and want to update packages from requirements file you can use --update option:

$ . env-4.3/bin/activate
(env-4.3)$ nodeenv --requirements=requirements.txt --update env-4.3

If you want to call node from environment without activation then you should use shim script:

$ ./env-4.3/bin/shim --version
v0.4.3

You can use the INI-style file ~/.nodeenvrc to set default values for many options, the keys in that file are the long command-line option names.

These are the available options and their defaults:

[nodeenv]
node = 'latest'
npm = 'latest'
with_npm = False
jobs = '2'
without_ssl = False
debug = False
profile = False
make = 'make'
prebuilt = True
ignore_ssl_certs = False
mirror = None

There are several alternatives that create isolated environments:

  • nave - Virtual Environments for Node. Nave stores all environments in one directory ~/.nave. Can create per node version environments using nave use envname versionname. Can not pass additional arguments into configure (for example --without-ssl) Can't run on windows because it relies on bash.
  • nvm - Node Version Manager. It is necessarily to do nvm sync for caching available node.js version. Can not pass additional arguments into configure (for example --without-ssl)
  • virtualenv - Virtual Python Environment builder. For python only.

LICENSE

BSD / LICENSE

nodeenv's People

Contributors

0xellos avatar a16bitsysop avatar adamchainz avatar andmis avatar asottile avatar avimitin avatar cclauss avatar ceremcem avatar chuwy-bot avatar e-nomem avatar ekalinin avatar eliask avatar fedalto avatar ivan-hilckov avatar jhermann avatar kylepdavis avatar lispython avatar lucas-c avatar luord avatar nicoddemus avatar puckbag avatar rschwebel avatar smileychris avatar softwaredoug avatar srathbun avatar syndbg avatar tchaikov avatar techtonik avatar vincentbernat avatar vlevit avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nodeenv's Issues

Freeze Regex sometimes extracts incorrect module & version number

Hey, great project. Love it. I just started using it and I noticed an issue with the freeze command. Specifically if I run this initial part of the freeze regex:

npm ls -g | grep -E '^.{4}\w{1}'

I'll get reasonable top-level packages:

├─┬ [email protected]
├─┬ [email protected]
├─┬ [email protected]
├─┬ [email protected]
├─┬ [email protected]
├─┬ [email protected]
├─┬ [email protected]
├── [email protected]
├─┬ [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
├── [email protected]
├── [email protected]
├─┬ [email protected]
├─┬ [email protected]
├── [email protected]
├─┬ [email protected]
└─┬ [email protected]

Once I add the regex that gets the version numbers:

npm ls -g | grep -E '^.{4}\w{1}' | grep -o -E '[a-zA-Z0-9\-]+@[0-9]+\.[0-9]+\.[0-9]+'

Notice what happens to "socket.io" as well as the phantomjs version number

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]   # -6 stripped
[email protected]
[email protected]  #socket stripped
[email protected]

Then trying to reuse this requirements file in another venv causes 404s. The workaround is to manually edit the requirements file after performing a freeze.

Perhaps a simpler regex should be used that simply splits on the @ character? I don't know enough about npm versions to comment on an appropriate fix.

Issue: Update nodeenv from 0.9.4 to 0.9.5

My CI script fails after update to 0.9.5:

$ [foo.app01.local] out: nodeenv --requirement=requirements/node/base.txt --python-virtualenv --jobs=4 --quiet

fails with:

[foo.app01.local] out:   File "/home/foo/.virtualenvs/foo/lib/python3.4/site-packages/nodeenv.py", line 665, in main
[foo.app01.local] out:     create_environment(env_dir, opt)
[foo.app01.local] out:   File "/home/foo/.virtualenvs/foo/lib/python3.4/site-packages/nodeenv.py", line 593, in create_environment
[foo.app01.local] out:     install_activate(env_dir, opt)
[foo.app01.local] out:   File "/home/foo/.virtualenvs/foo/lib/python3.4/site-packages/nodeenv.py", line 570, in install_activate
[foo.app01.local] out:     os.symlink("node", join(bin_dir, "nodejs"))
[foo.app01.local] out: FileExistsError: [Errno 17] File exists: 'node' -> '/home/foo/.virtualenvs/foo/bin/nodejs'
[foo.app01.local] out: make: *** [prod_env] Error 1
[foo.app01.local] out: 

Reverting to 0.9.4:

[foo.app01.local] out: nodeenv --requirement=requirements/node/base.txt --python-virtualenv --jobs=4 --quiet
[foo.app01.local] out:  * Install node.js (0.10.29.b'/usr/bin/python2'
[foo.app01.local] out: .. done.
[foo.app01.local] out:  * Overwriting /home/foo/.virtualenvs/foo/bin/shim with new content
[foo.app01.local] out:  * Appending nodeenv settings to /home/foo/.virtualenvs/foo/bin/activate
[foo.app01.local] out:  * Install node.js packages ... done.
[foo.app01.local] out: 

works fine

Remove the `src` directory

Hi again!

Upon completion of the new environment, the src directory is kept. For most people, I think this directory is useless and takes a lot of disk space. Please, save beavers and remove it when build is done. :)

logging fails with unicode chars

Error traceback (last part):

File "/data/webadmin/.virtualenvs/ui/lib/python2.7/site-packages/nodeenv.py", line 144, in emit
self.stream.write(fs % msg)
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2018' in position 42: ordinal not in range(128)

Since the encode/decode functions always confused me since I started using python, not sure what the best way would be to fix this.

What worked for me was:

self.stream.write(fs % msg.encode('utf8'))

But this will fail if msg is of type 'str'

Python 3 'ConfigParser' has no attribute 'RawConfigParser'

$ nodeenv -p
Traceback (most recent call last):
File "/home/sbrown/workspace/homesite/bin/nodeenv", line 9, in
load_entry_point('nodeenv==0.6.6', 'console_scripts', 'nodeenv')()
File "/home/sbrown/workspace/homesite/lib/python3.3/site-packages/nodeenv.py", line 519, in main
create_environment(env_dir, opt)
File "/home/sbrown/workspace/homesite/lib/python3.3/site-packages/nodeenv.py", line 433, in create_environment
save_env_options(env_dir, opt)
File "/home/sbrown/workspace/homesite/lib/python3.3/site-packages/nodeenv.py", line 492, in save_env_options
config = ConfigParser.RawConfigParser()
AttributeError: type object 'ConfigParser' has no attribute 'RawConfigParser'

$ python -V
Python 3.3.2

It appears that ConfigParser has changed further in Python 3.3+ or so and line 492 should look like -

config = configparser.RawConfigParser()

but I don't know what that would do for Python 2 compatibility.

http://docs.python.org/3/library/configparser.html#legacy-api-examples
http://docs.python.org/3/library/configparser.html#rawconfigparser-objects

npm does not work when using --prebuilt

[kyle:~/testing_prebuilt] [testing_prebuilt] $ npm -v

module.js:340
    throw err;
          ^
Error: Cannot find module 'npmlog'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at /Users/kyle/c9/testing_prebuilt/bin/npm:19:11
    at Object.<anonymous> (/Users/kyle/c9/testing_prebuilt/bin/npm:87:3)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)

why "freeze" command only outputs global packages?

Hi. I'm trying to understand the rationale on the freeze command only freezing globally installed modules.
I get that nodeenv is useful mainly for installing packages in a virtual node environment in a global fashion. But what about packages installed locally (in a node_modules/) folder?

I'm fairly new to all things virtualenv/nodeenv, so there may be a good reason for only listing global packages when using the nodeenv "freeze" command, but on the other hand, I think I may find it useful to be able to freeze locally installed requirements.

Using --prebuilt writes top-level files (from source doesn't)

I'm trying to use nodeenv --prebuilt --python-virtualenv but it writes the following files to the top-level directory:

  • ChangeLog
  • LICENSE
  • README.md

This is a problem for me because it is overwriting files in my project.

Can we exclude those? Or maybe only write but don't overwrite?

Symlink local module tree to the (virtualized) global one?

In the nodeenv, having the difference betwen local (./node_modules) and global (./lib/node_modules) npm installation is pretty much pointless. Thus, adding a symlink "node_modules → lib/node_modules" might make sense.

It certainly would make installation of things like gulp easier, which you have to install both globally and locally (for whatever reason).

nodenv -p fails while using python3.3

[16:14]$ /usr/local/bin/virtualenv --version
1.10.1
[16:14]$ nodeenv --version
0.6.6
[16:14]$ python3.3 --version
Python 3.3.2
[16:14]$ /usr/local/bin/virtualenv --python=python3.3 pyenv
Running virtualenv with interpreter /usr/bin/python3.3
Using base prefix '/usr'
New python executable in pyenv/bin/python3.3
Also creating executable in pyenv/bin/python
Installing
...
done.
[16:14]$ source pyenv/bin/activate
(pyenv)[16:15]$ nodeenv -p

  • Install node.js (0.10.20) .Traceback (most recent call last):
    File "/usr/local/bin/nodeenv", line 9, in
    load_entry_point('nodeenv==0.6.6', 'console_scripts', 'nodeenv')()
    File "/usr/local/lib/python2.7/dist-packages/nodeenv.py", line 515, in main
    create_environment(env_dir, opt)
    File "/usr/local/lib/python2.7/dist-packages/nodeenv.py", line 431, in create_environment
    install_node(env_dir, src_dir, opt)
    File "/usr/local/lib/python2.7/dist-packages/nodeenv.py", line 350, in install_node
    callit(conf_cmd, opt.verbose, True, node_src_dir, env)
    File "/usr/local/lib/python2.7/dist-packages/nodeenv.py", line 267, in callit
    % (cmd_desc, proc.returncode))
    OSError: Command ./configure --prefix=/home/lukas...ace/e-commerce/pyenv failed with error code 1

bug in 'freeze'

Last nodeenv version:

But:

$ npm ls -g
├─┬ [email protected] 
│ ├── [email protected] 
│ ├── [email protected] 
│ └── [email protected] 
├── [email protected] 
└─┬ [email protected] 
  ├── [email protected] 
  ├── [email protected] 
  ├── [email protected] 
  └── [email protected] 

There are several bugs in freeze output:

Use prebuilt Node.js binaries instead of compiling

First, thank you for nodeenv. This is an awesome package and I just successfully integrated it into a deployment workflow which now contains python and npm packages.

What do you think if for those platforms there are nodejs prebuilt binaries available, nodeenv can just download them instead of building node from source? Mac OS X, Linux and Windows are supported.

Readme: Local installation

I don't know if you know, but to get a fully editable git clone into you venv with distutils wpappers and all the usual bells and whistles, you can use

pip install -e git+https://github.com/ekalinin/nodeenv.git#egg=nodeenv

nodeenv -p fails with OSError

Hi,
I have installed nodeenv 0.6.0 via pip , which did give me a strange message but still appears to have installed, as nodeenv --version shows 0.6.0. Here is the message from install:

In the tar file /tmp/pip-fcVyjZ-unpack/nodeenv-0.6.0.tar.gz the member nodeenv-0.6.0/README is invalid: 'NoneType' object has no attribute 'isreg'

Anyways, I installed nodeenv within a virtualenv. Trying to nodeenv -p give me another error:

  • Install node.js (0.8.20) ... done.
    • Appending nodeenv settings to /home/dmarr/.virtualenvs/tet/bin/activate
    • Install npm.js (latest) ... Traceback (most recent call last):
      File "/home/dmarr/.virtualenvs/tet/bin/nodeenv", line 9, in
      load_entry_point('nodeenv==0.6.0', 'console_scripts', 'nodeenv')()
      File "/home/dmarr/.virtualenvs/tet/lib/python2.6/site-packages/nodeenv.py", line 494, in main
      create_environment(env_dir, opt)
      File "/home/dmarr/.virtualenvs/tet/lib/python2.6/site-packages/nodeenv.py", line 416, in create_environment
      install_npm(env_dir, src_dir, opt)
      File "/home/dmarr/.virtualenvs/tet/lib/python2.6/site-packages/nodeenv.py", line 351, in install_npm
      callit(cmd, opt.verbose, True)
      File "/home/dmarr/.virtualenvs/tet/lib/python2.6/site-packages/nodeenv.py", line 263, in callit
      % (cmd_desc, proc.returncode))
      OSError: Command ". /home/dmarr/.virtu...h && deactivate_node" failed with error code 50

Anyone know what the problem could be?

--node=system won't work if there's already a compiled node on the virtualenv

This may not be a bug per-se, but I've found this: on a virtualenv, if you first run nodeenv -p, it will download, compile and install a copy of node on ~/.virtualenvs/myproject/bin. So far, so good.

But later, if you decide to use the system-wide node install, running nodeenv -p --node=system won't help you (nor running nodeenv--node=system, without the -p option).
The standard output will tell you that some changes are applied to ~/.virtualenvs/myproject/bin/activate and it may even install npm, but the compiled node will be still there in ~/.virtualenvs/myproject/bin/, and a which node will tell you that that's the node that will be used.

In other words, the --node=system didn't take any effect, and one could say that it "failed silently".

BTW, as a side-effect of running nodeenv -p a few times, I noticed that the same lines are n-plicated inside ~/.virtualenvs/myproject/bin/activate. I don't know if there is a "cure" for that, but just letting you know. I manually cleaned the n-plicated lines.

Error: no suport windows 8

File "C:\Users\Gladson\Desktop\Teste\env_nodeenv\lib\site-packages\nodeenv.py", line 299, in callit % (cmd_desc, proc.returncode)) OSError: Command curl --silent -L http://nodejs.org/dist/node-v-RC1.tar.gz | tar xzf - -C "'C:\Users\Gladson\De...este\env_node\src'" failed with error code 255

Have to install all dependencies:
https://github.com/ekalinin/nodeenv#dependency

It would be better if there were not so many dependencies.

Use system node

Hi!

Compiling node.js for each environment can be quite long. Please, add an option to use the system-wide node (or nodejs on Debian) binary. This is how the original virtualenv work (but in this case, it uses python-X.Y).

Creating a new nodeenv inside a virtualenv results in a doubled prompt

Currently, creating a new nodeenv inside a python virtualev doubles the command prompt.

The following code will result in a doubled prompt like so: (doubled)(doubled):~$

mkvirtualenv doubled
pip install virtualenv
nodeenv -p
deactivate
workon doubled

Here's what I'm working with as far as virtualenv versions are concerned:

:~$ pip freeze | grep virtualenv
Warning: cannot find svn location for distribute==0.6.24dev-r0
virtualenv==1.8.2
virtualenv-clone==0.2.4
virtualenvwrapper==3.6

Everything else is installed inside of the virtualenv

`nodeenv -n system` exits `0` when curl is not found

$ nodeenv -n system nenv2
/bin/sh: 1: curl: not found
 * Install npm.js (latest) ... done.
(venv)asottile@asottile-VirtualBox:/tmp/foo$ echo $?
0

Interestingly it returns a nonzero code without -n system:

$ nodeenv nenv3
/bin/sh: 1: curl: not found
 * Install node.js (-RC1) Traceback (most recent call last):
  File "/tmp/foo/venv/bin/nodeenv", line 9, in <module>
    load_entry_point('nodeenv==0.8.0', 'console_scripts', 'nodeenv')()
  File "/tmp/foo/venv/local/lib/python2.7/site-packages/nodeenv.py", line 596, in main
    create_environment(env_dir, opt)
  File "/tmp/foo/venv/local/lib/python2.7/site-packages/nodeenv.py", line 516, in create_environment
    install_node(env_dir, src_dir, opt)
  File "/tmp/foo/venv/local/lib/python2.7/site-packages/nodeenv.py", line 378, in install_node
    download_node(node_url, src_dir, env_dir, opt)
  File "/tmp/foo/venv/local/lib/python2.7/site-packages/nodeenv.py", line 347, in download_node
    callit(cmd, opt.verbose, True, env_dir)
  File "/tmp/foo/venv/local/lib/python2.7/site-packages/nodeenv.py", line 309, in callit
    % (cmd_desc, proc.returncode))
OSError: Command curl --silent -L http://nodejs.org/dist/node-v-RC1.tar.gz | tar xzf - -C /tmp/foo/nenv3/src failed with error code 2
(venv)asottile@asottile-VirtualBox:/tmp/foo$ echo $?
1

Yes I realize I'm probably the only person who has a linux installation that has yet to install curl. To be fair this is a relatively new install :D

Cannot install from PyPI

setup.py references the README, but there's no MANIFEST.in to tell setuptools to include the README in the package.

TypeError: expected bytes, bytearray or buffer compatible object

Running nodeenv into a virtualenv targeting Python 3.3.2 dies with the following:

$ nodeenv --version
Traceback (most recent call last):
File "/home/sbrown/workspace/homesite/bin/nodeenv", line 9, in
load_entry_point('nodeenv==0.6.6', 'console_scripts', 'nodeenv')()
File "/home/sbrown/workspace/homesite/lib/python3.3/site-packages/nodeenv.py", line 501, in main
opt, args = parse_args()
File "/home/sbrown/workspace/homesite/lib/python3.3/site-packages/nodeenv.py", line 79, in parse_args
metavar='NODE_VER', default=get_last_stable_node_version(),
File "/home/sbrown/workspace/homesite/lib/python3.3/site-packages/nodeenv.py", line 480, in get_last_stable_node_version
return p.stdout.readline().replace("\n", "")
TypeError: expected bytes, bytearray or buffer compatible object

$ python -V
Python 3.3.2

update PIP (npm install fails due to 301 redirect)

As mentioned in #54 on PIP there is version of nodeenv that do not follow 301 redirect from npmjs.org, for 'now' I use:

pip install git+git://github.com/ekalinin/nodeenv.git@24a5432ad1de08b4dbca78217fc52e0b3691db3c

Fish support

It would be great if the --python-virtualenv option could also append the appropriate node commands to the env/bin/activate.fish as well as the plain activate script, so those using the fish shell could also benefit from a virtualenv + nodeenv combination.

I'm still in the midst of learning the fish language myself, or this would come with a pull request, but wanted to enter it as an issue just in case it's something you could easily do. If not, I may come back in time with the code in hand.

Grunt doesnt work

I installed grunt-cli and grunt, and doesnt work, dont run my task..seems like dont recognize a grunt package installed on nodeenv

~/.npm and ~/tmp permissions for non sudo installs (e.g.: virtualenv)

I ran into permission issues when trying to install this using virtualenv but found out what it was.

I got this error

OSError: Command ". nenv1/bin/activate...h && deactivate_node" failed with error code 3

When I ran it with --verbose, it turned out that it failed to write to my ~/.npm directory and ~/tmp directories. both were owned by root. for example the expanded error for the latter was:

..
npm ERR! addLocal Could not install .
npm ERR! Error: EACCES, mkdir '/home/yuvilio/tmp/npm-9739'
npm ERR! { [Error: EACCES, mkdir '/home/yuvilio/tmp/npm-9739'] errno: 3, code: 'EACCES', path: '/home/yuvilio/
tmp/npm-9739' }

..

I think this was because I had a node install from Ubuntu and ran sudo npm install which made those directories not accessible. When I switched to virtualenv and ran nodeenv, the npm install was blocked.

The fix was to make ~/.npm and ~/tmp writable. I went recursive (-R) for extra assurance:

sudo chown -fR myusername:myusername ~/.npm ~/tmp

The install then went through. Might be worth noting in the documentation somewhere.

new(?) npm install script breaking nodeenv

I noticed that initializing a new nodeenv was failing. When I ran with --verbose, I saw that this was because the npm install script is asking

This script will find and eliminate any shims, symbolic
links, and other cruft that was installed by npm 0.x.

Is this OK? enter 'yes' or 'no' 

and nodenv wasn't answering. The user can manually enter yes, but piping yes | nodeenv ... doesn't work.

Environment creation fails with non-ASCII chars in path

Creating a new environment with a non-ASCII path fails. For example, when I execute the following command in the path /work/öäü on my Linux system:

$ nodeenv env

it fails with

 * Install node.js (0.10.24Traceback (most recent call last):
  File "/usr/lib/python-exec/python2.7/nodeenv", line 9, in <module>
    load_entry_point('nodeenv==0.7.2', 'console_scripts', 'nodeenv')()
  File "/usr/lib64/python2.7/site-packages/nodeenv.py", line 546, in main
    create_environment(env_dir, opt)
  File "/usr/lib64/python2.7/site-packages/nodeenv.py", line 472, in create_environment
    install_node(env_dir, src_dir, opt)
  File "/usr/lib64/python2.7/site-packages/nodeenv.py", line 353, in install_node
    node_src_dir = join(src_dir, node_name)
  File "/usr/lib64/python2.7/posixpath.py", line 80, in join
    path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 6: ordinal not in range(128)

Several fixes for a silar problem in virtualenv have been proposed, e.g. pypa/virtualenv#457

Python 2.6 issue

Thank you for your work on this wonderful tool. I just discovered it and it has made my life easier in countless ways! (I can finally have Node.js and Django code side-by-side for web projects without pulling my hair out.)

My shop standardizes on RHEL 6.4, which still uses Python 2.6 (we're moving to Python 2.7 as soon as RHEL 7 is available). Python 2.6 still uses a Tuple for sys.version_info, which causes a failure at line 414 of nodeenv.py. This can be fixed by using a getattr and supplying a default. See the code below (line 414):

...
if getattr(sys.version_info, 'major', sys.version_info[0]) > 2:
...

virtualenv and nodeenv interfere with each other

If a Python virtualenv is active and then you activate a nodeenv, you lose the virtualenv. This can be especially confusing if you installed the nodeenv python script into a Python virtualenv.

I think the problem is that nodeenv's activate script uses the same shell variable names as the Python virtualenv.

Cannot create a nodeenv with --node=system in virtualenv

Related to #43, except mine is a fresh virtualenv with no previously installed node. I'm simply running nodeenv -p --node=system right after installing nodeenv. This is what I get (on Marjaro Linux, an Arch derivative, with node 0.10.26 installed system-wide):

* Appending nodeenv settings to /home/roman/.virtualenvs/myproject/bin/activate
 * Install npm.js (latest) ... Traceback (most recent call last):
  File "/home/me/.virtualenvs/myproject/bin/nodeenv", line 9, in <module>
    load_entry_point('nodeenv==0.7.2', 'console_scripts', 'nodeenv')()
  File "/home/me/.virtualenvs/myproject/lib/python2.7/site-packages/nodeenv-0.7.2-py2.7.egg/nodeenv.py", line 546, in main
    create_environment(env_dir, opt)
  File "/home/me/.virtualenvs/myproject/lib/python2.7/site-packages/nodeenv-0.7.2-py2.7.egg/nodeenv.py", line 482, in create_environment
    install_npm(env_dir, src_dir, opt)
  File "/home/me/.virtualenvs/myproject/lib/python2.7/site-packages/nodeenv-0.7.2-py2.7.egg/nodeenv.py", line 409, in install_npm
    callit(cmd, opt.verbose, True)
  File "/home/me/.virtualenvs/myproject/lib/python2.7/site-packages/nodeenv-0.7.2-py2.7.egg/nodeenv.py", line 299, in callit
    % (cmd_desc, proc.returncode))
OSError: Command ". /home/me/.virtu...h && deactivate_node" failed with error code 2

Don't use `--insecure` with curl

Hi!

You use curl --insecure to download npm. The certificate of https://npmjs.org seems quite legit. On my system, I don't need --insecure for the download to succeed. It also would be nice to be able to download node from an HTTPS location but nodejs.org does not seem to answer on HTTPS.

Allow creation of new nodeenv in pre-existing directory

Is it possible to allow installation of a nodeenv within an existing directory? My use-case seems common -- to be able to git clone some Node project, cd into its directory, and create a nodeenv to start working in a clean, self-contained environment.

My current workaround is piggy-back on a Python virtualenv with:

virtualenv .
. ./bin/activate
nodeenv -p

which works, but it would be nice to be able to run nodeenv . and avoid the need to create a Python virtualenv.

repeated lines added to bin/activate

I've mentioned this as a footnote on issue #43.
If for some reason, you run nodeenv more than once, then you end up with duplicated (or triplicated, or...) code on bin/activate, once for each time you ran the command.
At least, that's what happens when you create the nodeenv inside virtualenv (which, as far as I understand, in that case, both virtualenv and nodeenv share the same file for activate command). Not sure if this issue happens when creating a nodeenv outside a virtualenv.

Could it be a solution to keep the nodeenv code in a activate_nodeenv file and then source it inside virtualenv's activate?

Warn about prefx in .npmrc

I've just spent a little while getting confused about why my npm install -g commands where installing to another virtualenv despite being in a nodeenv enabled virtualenv. It turns out I had a .npmrc file with a prefix entry pointing at another virtualenv. I suspect it was my solution before I found nodeenv.

I realise that nodeenv code doesn't run during a general npm install -g but maybe when doing the nodeenv -p (which I re-did in an attempt to clean out and start again) it could warn about a prefix value in your .npmrc if that is going to disrupt the expected behaviour of the nodeenv setup?

Just a thought, thanks for an excellent project. I'm new to the node.js world and, being more familiar with Python, I was happy to see nodeenv :)

Michael

freeze does not work properly for packges installed without --global mode

Following example is presented in README:

$ . env-4.3/bin/activate
(env-4.3)$ npm install express
(env-4.3)$ npm install jade
(env-4.3)$ freeze ../prod-requirements.txt

Although it doesn't work. freeze command returns empty line.
It seems that only packages installed with -g option are recognized by freeze
I'm using version 0.6.5 of nodeenv and npm=1.2.18

nodeenv installation of desired version ends with bad (404) url

nodeenv -p -n v0.8.11 won't work since it is building an invalid url. May be because nodejs moved all the versions into directories. This is what I get.

$ nodeenv --version
0.8.0
(envname)username@computername:~/code$ nodeenv -p -n v0.8.11
 * Install node.js (v0.8.11-RC1) Traceback (most recent call last):
  File "/home/username/.virtualenvs/envname/bin/nodeenv", line 9, in <module>
    load_entry_point('nodeenv==0.8.0', 'console_scripts', 'nodeenv')()
  File "/home/username/.virtualenvs/envname/local/lib/python2.7/site-packages/nodeenv.py", line 596, in main
    create_environment(env_dir, opt)
  File "/home/username/.virtualenvs/envname/local/lib/python2.7/site-packages/nodeenv.py", line 516, in create_environment
    install_node(env_dir, src_dir, opt)
  File "/home/username/.virtualenvs/envname/local/lib/python2.7/site-packages/nodeenv.py", line 378, in install_node
    download_node(node_url, src_dir, env_dir, opt)
  File "/home/username/.virtualenvs/envname/local/lib/python2.7/site-packages/nodeenv.py", line 347, in download_node
    callit(cmd, opt.verbose, True, env_dir)
  File "/home/username/.virtualenvs/envname/local/lib/python2.7/site-packages/nodeenv.py", line 309, in callit
    % (cmd_desc, proc.returncode))
OSError: Command curl --silent -L http://nodejs.org/di...-vv0.8.11-RC1.tar.gz | tar xzf - -C /home/username/.virtualenvs/envname/src failed with error code 2

Broken for latest node.js release 0.10.0

The problem is this if block in get_node_src_url:

if version > "0.5.0":
    node_url = 'http://nodejs.org/dist/v%s/%s' % (version, tar_name)
else:
    node_url = 'http://nodejs.org/dist/%s' % (tar_name)

The above evaluates to False for 0.10.0. A better option might be to use parse_version from pkg_resources (distutils) and change this to

if parse_version(version) > parse_version("0.5.0"):
    node_url = 'http://nodejs.org/dist/v%s/%s' % (version, tar_name)
else:
    node_url = 'http://nodejs.org/dist/%s' % (tar_name)

as per this stackoverflow answer: http://stackoverflow.com/a/6972866

Add flag to specify npm version

Hi. I use nodeenv the makefile for one of my projects, and it would be useful to me to be able to specify a version on npm using a command-line argument. I see that this is probably possible using a requirements file, but it would be nice if that weren't necessary.

Currently my makefile has gone from working to broken because of #2, which wouldn't happen if it hadn't started using the latest version of npm automatically.

Thanks for your consideration.

Incomplete package names using freeze

This is how to reproduce the problem:

I have some installed packages.

$ freeze
[email protected]
[email protected]
[email protected]
[email protected]

Now I want to install log4js package.

$ npm install -g log4js
$ freeze
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

It is obvious that only characters following the "log4" string gets included into freeze outuput. I guess this is general problem in freeze and packages that contains numeral character in their name.

npm fails if $HOME is not set properly

Running as a user without a home directory "npm install" fails.

I'm using a python virtualenv for a server I wrote. Now the need for nodejs arose, to build an optimized version of my javascripts using requirejs and uglyfyjs.
The user of the virtualenv at the production box is "myserver". "myserver" has no home directory at /home/myserver or elsewhere.

I installed nodejs in the python virtualenv using nodeenv as documented. This worked well.

But npm install failed:

$ npm install -g requirejs
npm ERR! Error: Attempt to unlock requirejs, which hasn't been locked
... a lot more text ...

$HOME is set to /nonexistent

$ echo $HOME
/nonexistent

My fix was to set the $HOME var (as the user myserver):

$ mkdir /path/to/virtualenv/home
$ HOME=/path/to/virtualenv/home

npm install now works.

Maybe the need for a home directory could be documented somwhere.

node -n system hangs indefinitely (0.9.1)

(venv)[anthony@anthony-VirtualBox](why_is_my_build_slower)]$ nodeenv --version
0.9.1
(venv[anthony@anthony-VirtualBox](why_is_my_build_slower)]$ node --version
v0.10.28
(venv)[anthony@anthony-VirtualBox](why_is_my_build_slower)]$ nodeenv -n system nenv
(venv)[anthony@anthony-VirtualBox](why_is_my_build_slower)]$ source nenv/bin/activate 
(nenv)(venv)[anthony@anthony-VirtualBox](why_is_my_build_slower)]$ node --version
# hangs indefinitely.  Looking at top there's a process that laternates between `bash` and `node` that is pegging a processor

I originally noticed this when my builds were timing out: https://travis-ci.org/pre-commit/pre-commit/jobs/25208998

This was working with 0.8.1

TypeError: object of type 'int' has no len() when running nodeenv -p

Hi!

I'm having problems creating a nodeenv in my current virtualenv, using the function: noveenv -p

The error i get:

$ nodeenv -p
 * Install node.js (0.10.1) .Traceback (most recent call last):
  File "/usr/local/bin/nodeenv", line 9, in <module>
    load_entry_point('nodeenv==0.6.2', 'console_scripts', 'nodeenv')()
  File "/Library/Python/2.7/site-packages/nodeenv-0.6.2-py2.7.egg/nodeenv.py", line 499, in main
    create_environment(env_dir, opt)
  File "/Library/Python/2.7/site-packages/nodeenv-0.6.2-py2.7.egg/nodeenv.py", line 415, in create_environment
    install_node(env_dir, src_dir, opt)
  File "/Library/Python/2.7/site-packages/nodeenv-0.6.2-py2.7.egg/nodeenv.py", line 323, in install_node
    if value is not None ]
TypeError: object of type 'int' has no len()

Specs:
Mac OS X Mountain Lion
nodeenv==0.6.2
node==0.8.2 and also 0.10.1
python==2.7.2

all dependencies listed on your wiki are also installed.

Create node executable shim in nodeenv's bin/ in case system node is used

Hi,

some of our people prefer using virtualenv without activating environment with activate script — by adjusting PATH env var or by referencing executables directly in venv's bin/.

I think this is worth supporting and currently I do this via putting the following script into bin/ during creating nodeenv:

#!/bin/sh
export NODE_PATH=/path/to/nodeenv/lib/node_modules
export NPM_CONFIG_PREFIX=/path/to/nodeenv
exec /path/to/system/installed/node $*

What do you think of this?

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.