Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ Version [unreleased]
- `-p` accepts an optional virtualenv directory and prefers the activated
`VIRTUAL_ENV` over the virtualenv nodeenv itself is installed in
`#156 <https://github.com/ekalinin/nodeenv/issues/156>`_
- The "src" directory is now removed after installation by default, which
halves the size of an environment. Added `--no-clean-src` to keep it: with
`--source` that is what lets a repeated `--force` build reuse the
downloaded source tree
`#205 <https://github.com/ekalinin/nodeenv/issues/205>`_

Version 1.3.1
-------------
Expand Down
7 changes: 6 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,11 @@ Installation options
Set mirror server of nodejs.org to download from.

``-c, --clean-src``
Remove "src" directory after installation.
Remove "src" directory after installation. This is the default.

``--no-clean-src``
Keep "src" directory after installation. With ``--source`` it holds the
downloaded source tree, so a repeated ``--force`` build reuses it.

NPM options
^^^^^^^^^^^
Expand Down Expand Up @@ -407,6 +411,7 @@ These are the available options and their defaults::
mirror = None
prefer_system = False
isolate_npm = False
clean_src = True

Alternatives
------------
Expand Down
10 changes: 8 additions & 2 deletions nodeenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class Config(object):
mirror = None
prefer_system = False
isolate_npm = False
clean_src = True

@classmethod
def _load(cls, configfiles, verbose=False):
Expand Down Expand Up @@ -572,8 +573,13 @@ def make_parser():

parser.add_argument(
'--clean-src', '-c', dest='clean_src',
action='store_true', default=False,
help='Remove "src" directory after installation')
action='store_true', default=Config.clean_src,
help='Remove "src" directory after installation (default)')

parser.add_argument(
'--no-clean-src', dest='clean_src',
action='store_false',
help='Keep "src" directory after installation')

parser.add_argument(
'--force', dest='force',
Expand Down
47 changes: 47 additions & 0 deletions tests/nodeenv_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,53 @@ def test_parse_args_isolate_npm():
assert nodeenv.parse_args().isolate_npm is False


def test_clean_src_default():
assert nodeenv.Config._default['clean_src'] is True


def test_clean_src_is_configurable(tmpdir):
rc = tmpdir.join('nodeenvrc')
rc.write('[nodeenv]\nclean_src = false\n')
try:
nodeenv.Config._load([str(rc)])
assert nodeenv.Config.clean_src is False
finally:
nodeenv.Config.clean_src = True


def test_parse_args_clean_src():
with mock.patch.object(sys, 'argv', ['nodeenv', 'env']):
assert nodeenv.parse_args().clean_src is True
# still accepted, pre-commit passes it explicitly
with mock.patch.object(sys, 'argv', ['nodeenv', '-c', 'env']):
assert nodeenv.parse_args().clean_src is True
with mock.patch.object(sys, 'argv', ['nodeenv', '--no-clean-src', 'env']):
assert nodeenv.parse_args().clean_src is False


def _run_create_environment(tmpdir, extra):
"""
Run create_environment() in tmpdir without installing anything
"""
argv = ['nodeenv', '--node', '26.9.0', '-p'] + extra
with mock.patch.object(sys, 'argv', argv):
args = nodeenv.parse_args()
with mock.patch.object(nodeenv, 'install_node'), \
mock.patch.object(nodeenv, 'install_activate'), \
mock.patch.object(nodeenv, 'set_predeactivate_hook'):
nodeenv.create_environment(str(tmpdir), args)


def test_create_environment_cleans_src_by_default(tmpdir):
_run_create_environment(tmpdir, [])
assert not tmpdir.join('src').check()


def test_create_environment_keeps_src_when_asked(tmpdir):
_run_create_environment(tmpdir, ['--no-clean-src'])
assert tmpdir.join('src').check(dir=True)


@pytest.mark.skipif(nodeenv.is_WIN, reason='-n system is posix only')
@pytest.mark.usefixtures('mock_host_platform')
def test_main_prefer_system_uses_system_node(cap_logging_info):
Expand Down
Loading