diff --git a/CHANGES b/CHANGES index 56e84d4..9bf789f 100644 --- a/CHANGES +++ b/CHANGES @@ -4,6 +4,10 @@ Nodeenv changelog Version [unreleased] -------------------- +- The default configuration dump and README example omit options without + defaults, such as `mirror`, so they can be copied into a config file + without selecting a mirror named `None` + `#422 `_ - Require Python 3.10 or later, matching the minimum version tested in CI. Update package classifiers and wheel tags, and remove the unused Python 2 compatibility paths. Old Node.js source builds still require Python 2.7 @@ -35,8 +39,8 @@ Version [unreleased] text files (npm 8) and whose workspaces are missing (npm >= 9); the default `--npm=latest` no longer ends in a 404 there `#310 `_ -- Quoted values in the config file, as the README shows them, are read - without the quotes, and `user:password@` in the `--mirror` URL is sent to +- Quoted values in the config file are read without the quotes, and + `user:password@` in the `--mirror` URL is sent to the mirror with HTTP Basic authentication instead of being taken for a part of the host; the password stays out of error messages and redirects `#321 `_ diff --git a/README.rst b/README.rst index 21761eb..04a4f31 100644 --- a/README.rst +++ b/README.rst @@ -480,22 +480,25 @@ 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' + node = latest + npm = latest with_npm = False - jobs = '2' + jobs = 2 without_ssl = False debug = False profile = False - make = 'make' + make = make prebuilt = True ignore_ssl_certs = False with_certifi = False - mirror = None prefer_system = False isolate_npm = False clean_src = True +Options without a default, such as ``mirror``, can be omitted. Do not use +``mirror = None``: INI values are strings, so that would select a mirror +named ``None`` instead of using nodeenv's default download source. + Alternatives ------------ diff --git a/nodeenv.py b/nodeenv.py index 7177ae1..644c97e 100644 --- a/nodeenv.py +++ b/nodeenv.py @@ -132,7 +132,7 @@ def _dump(cls): print(" [nodeenv]") print(" " + "\n ".join( "%s = %s" % (k, v) for k, v in sorted(vars(cls).items()) - if not k.startswith('_'))) + if not k.startswith('_') and v is not None)) Config._default = dict( diff --git a/tests/test_config_dump.py b/tests/test_config_dump.py new file mode 100644 index 0000000..10934df --- /dev/null +++ b/tests/test_config_dump.py @@ -0,0 +1,34 @@ +import os +import re + +import pytest + +import nodeenv + + +@pytest.fixture +def default_config(monkeypatch, tmpdir): + for name, value in nodeenv.Config._default.items(): + monkeypatch.setattr(nodeenv.Config, name, value) + monkeypatch.chdir(str(tmpdir)) + + +def _load_defaults(text, tmpdir): + config = tmpdir.join('nodeenvrc') + config.write(text) + nodeenv.Config._load([str(config)]) + assert {name: getattr(nodeenv.Config, name) + for name in nodeenv.Config._default} == nodeenv.Config._default + + +def test_dumped_configuration_roundtrips(default_config, capsys, tmpdir): + nodeenv.Config._dump() + _load_defaults(capsys.readouterr().out, tmpdir) + + +def test_readme_configuration_roundtrips(default_config, tmpdir): + readme = os.path.join(os.path.dirname(__file__), '..', 'README.rst') + with open(readme) as stream: + block = re.search(r' \[nodeenv\]\n(?: .*\n)+', + stream.read()).group(0) + _load_defaults('\n'.join(line[4:] for line in block.splitlines()), tmpdir)