From f01c7d617cfb91a32103ad9b4f7d4628c7b5893d Mon Sep 17 00:00:00 2001 From: Tom Whitwell Date: Tue, 12 Oct 2021 12:55:22 +0100 Subject: [PATCH] Use version specified in `.node-version` if exists It's pretty common to have a file `.node-version` in a repo to specify the version of node to use. This will pick up the version specified in this file and use that as the default when `Config` is initialised. --- nodeenv.py | 5 +++++ 1 file changed, 5 insertions(+) mode change 100755 => 100644 nodeenv.py diff --git a/nodeenv.py b/nodeenv.py old mode 100755 new mode 100644 index 4465b04..ba64aa8 --- a/nodeenv.py +++ b/nodeenv.py @@ -106,6 +106,7 @@ def _load(cls, configfiles, verbose=False): """ Load configuration from the given files in reverse order, if they exist and have a [nodeenv] section. + Additionally, load version from .node-version if file exists. """ for configfile in reversed(configfiles): configfile = os.path.expanduser(configfile) @@ -133,6 +134,10 @@ def _load(cls, configfiles, verbose=False): os.path.basename(configfile), attr, val)) setattr(cls, attr, val) + if os.path.exists(".node-version"): + with open(".node-version", "r") as v_file: + setattr(cls, "node", v_file.readlines(1)[0].strip()) + @classmethod def _dump(cls): """