From c4a621d4a60e350b5cf0f73db6d2f5500ee361c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Wed, 12 Sep 2018 07:51:48 +0100 Subject: [PATCH] vimPlugins: run update script in empty environment --- pkgs/misc/vim-plugins/update.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/pkgs/misc/vim-plugins/update.py b/pkgs/misc/vim-plugins/update.py index 210f68d7d599..8128c12bce68 100755 --- a/pkgs/misc/vim-plugins/update.py +++ b/pkgs/misc/vim-plugins/update.py @@ -20,8 +20,9 @@ import xml.etree.ElementTree as ET from datetime import datetime from multiprocessing.dummy import Pool from pathlib import Path -from typing import Dict, List, Optional, Tuple, Union +from typing import Dict, List, Optional, Tuple, Union, Any from urllib.parse import urljoin, urlparse +from tempfile import NamedTemporaryFile ATOM_ENTRY = "{http://www.w3.org/2005/Atom}entry" ATOM_LINK = "{http://www.w3.org/2005/Atom}link" @@ -110,7 +111,7 @@ class Plugin: return copy -GET_PLUGINS = """(with import {}; +GET_PLUGINS = """(with import {}; let hasChecksum = value: lib.isAttrs value && lib.hasAttrByPath ["src" "outputHash"] value; getChecksum = name: value: @@ -123,8 +124,24 @@ let in lib.filterAttrs (n: v: v != null) checksums)""" +class CleanEnvironment(object): + def __enter__(self) -> None: + self.old_environ = os.environ.copy() + local_pkgs = str(ROOT.joinpath("../../..")) + os.environ["NIX_PATH"] = f"localpkgs={local_pkgs}" + self.empty_config = NamedTemporaryFile() + self.empty_config.write(b"{}") + self.empty_config.flush() + os.environ["NIXPKGS_CONFIG"] = self.empty_config.name + + def __exit__(self, exc_type: Any, exc_value: Any, traceback: Any) -> None: + os.environ.update(self.old_environ) + self.empty_config.close() + + def get_current_plugins() -> List[Plugin]: - out = subprocess.check_output(["nix", "eval", "--json", GET_PLUGINS]) + with CleanEnvironment(): + out = subprocess.check_output(["nix", "eval", "--json", GET_PLUGINS]) data = json.loads(out) plugins = [] for name, attr in data.items():