def test_get_info_uses_hook_path(self, tmp_path): magic = tmp_path / "magic{}".format( os.path.splitext(sys.executable)[1]) wrapper = ( "#!{executable}\n" "import subprocess\n" "import sys\n" 'sys.exit(subprocess.call(["{executable}"] + sys.argv[1:]))\n' ).format(executable=sys.executable) magic.write_text(wrapper) magic.chmod(magic.stat().st_mode | stat.S_IEXEC) class MockHook: def tox_get_python_executable(self, envconfig): return str(magic) class envconfig: basepython = sys.executable envname = "magicpy" # Check that the wrapper is working first. # If it isn't, the default is to return the passed path anyway. subprocess.check_call([str(magic), "--help"]) interpreters = Interpreters(hook=MockHook()) info = interpreters.get_info(envconfig) assert info.executable == str(magic)
def parseconfig(args, plugins=()): """Parse the configuration file and create a Config object. :param plugins: :param list[str] args: list of arguments. :rtype: :class:`Config` :raise SystemExit: toxinit file is not found """ pm = get_plugin_manager(plugins) # prepare command line options parser = Parser() pm.hook.tox_addoption(parser=parser) # parse command line options option = parser._parse_args(args) interpreters = Interpreters(hook=pm.hook) config = Config(pluginmanager=pm, option=option, interpreters=interpreters) config._parser = parser config._testenv_attr = parser._testenv_attr if config.option.version: print(get_version_info(pm)) raise SystemExit(0) # parse ini file basename = config.option.configfile if os.path.isfile(basename): inipath = py.path.local(basename) elif os.path.isdir(basename): # Assume 'tox.ini' filename if directory was passed inipath = py.path.local(os.path.join(basename, "tox.ini")) else: for path in py.path.local().parts(reverse=True): inipath = path.join(basename) if inipath.check(): break else: inipath = py.path.local().join("setup.cfg") if not inipath.check(): helpoptions = option.help or option.helpini feedback("toxini file {!r} not found".format(basename), sysexit=not helpoptions) if helpoptions: return config try: parseini(config, inipath) except tox.exception.InterpreterNotFound: exn = sys.exc_info()[1] # Use stdout to match test expectations print("ERROR: {}".format(exn)) # post process config object pm.hook.tox_configure(config=config) return config
def create_interpreters_instance(): pm = get_plugin_manager() return Interpreters(hook=pm.hook)
def interpreters(): pm = get_plugin_manager() return Interpreters(hook=pm.hook)
def __init__(self): self.envconfigs = {} self.invocationcwd = py.path.local() self.interpreters = Interpreters()