<commit_before>"""
Executes a set of implementations as a program.
"""

# Copyright (C) 2006, <NAME>
# See the README file for details, or visit http://0install.net.

import os, sys
from logging import debug, info

from zeroinstall.injector.model import Interface, SafeException, EnvironmentBinding, DistributionImplementation
from zeroinstall.injector.iface_cache import iface_cache

def do_env_binding(binding, path):
	os.environ[binding.name] = binding.get_value(path,
					os.environ.get(binding.name, None))
	info("%s=%s", binding.name, os.environ[binding.name])

def execute(policy, prog_args, dry_run = False, main = None, wrapper = None):
	"""Execute program. On success, doesn't return. On failure, raises an Exception.
	Returns normally only for a successful dry run.
	
	@precondition: C{policy.ready and policy.get_uncached_implementations() == []}
	"""
	iface = iface_cache.get_interface(policy.root)
		
	for needed_iface in policy.implementation:
		impl = policy.implementation[needed_iface]
		assert impl
		for dep in impl.requires:
			dep_iface = iface_cache.get_interface(dep.interface)
			for b in dep.bindings:
				if isinstance(b, EnvironmentBinding):
					dep_impl = policy.get_implementation(dep_iface)
					do_env_binding(b, policy.get_implementation_path(dep_impl))
	
	root_impl = policy.get_implementation(iface)
	_execute(root_impl, prog_args, dry_run, main, wrapper)

def _get_implementation_path(id):<commit_msg>When running, don't try to do environment bindings for dependencies which<commit_after>"""
Executes a set of implementations as a program.
"""

# Copyright (C) 2006, <NAME>
# See the README file for details, or visit http://0install.net.

import os, sys
from logging import debug, info

from zeroinstall.injector.model import Interface, SafeException, EnvironmentBinding, DistributionImplementation, ZeroInstallImplementation
from zeroinstall.injector.iface_cache import iface_cache

def do_env_binding(binding, path):
	os.environ[binding.name] = binding.get_value(path,
					os.environ.get(binding.name, None))
	info("%s=%s", binding.name, os.environ[binding.name])

def execute(policy, prog_args, dry_run = False, main = None, wrapper = None):
	"""Execute program. On success, doesn't return. On failure, raises an Exception.
	Returns normally only for a successful dry run.
	
	@precondition: C{policy.ready and policy.get_uncached_implementations() == []}
	"""
	iface = iface_cache.get_interface(policy.root)
		
	for needed_iface in policy.implementation:
		impl = policy.implementation[needed_iface]
		assert impl
		for dep in impl.requires:
			dep_iface = iface_cache.get_interface(dep.interface)
			for b in dep.bindings:
				if isinstance(b, EnvironmentBinding):
					dep_impl = policy.get_implementation(dep_iface)
					if isinstance(dep_impl, ZeroInstallImplementation):
						do_env_binding(b, policy.get_implementation_path(dep_impl))
					else:
						debug("Implementation %s is native; no binding needed", dep_impl)
	
	root_impl = policy.get_implementation(iface)
	_execute(root_impl, prog_args, dry_run, main, wrapper)

def _get_implementation_path(id):
{'fraction_non_alphanumeric': 0.09948486799742434, 'fraction_numerical': 0.003219575016097875, 'mean_word_length': 5.40618556701031, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5973786', 'n_tokens_mistral': 1025, 'n_tokens_neox': 940, 'n_words': 260}