<commit_before>
import os
import copy
import json

class ApplicationEnvironment(object):
	@staticmethod
	def get_instance_environment(configuration, version):
		"""
		Fetch only the instance environment that is not node specific.
		Intended only to capture data that can be seralized and passed to
		a different node.
		"""
		environment = {}

		# Services first.
		credentials = version.get_service_credentials()
		environment['PM_SERVICES'] = json.dumps(credentials)

		# And the rest is rolled up into a single environment variable.
		meta = {}

		# Workspace parameters.
		meta['workspace'] = version.application.workspace.tags

		environment['PM_METADATA'] = json.dumps(meta)

		return environment

	@staticmethod
	def merge_local_environment(configuration, other_environment):
		"""
		Merge an application's environment with this nodes environment -
		that means this nodes's tags and local environment.
		"""
		environment = copy.deepcopy(other_environment)

		# Add in our nodes tags.
		meta = json.loads(environment['PM_METADATA'])
		meta['node'] = configuration['tags']
		environment['PM_METADATA'] = json.dumps(meta)

		# Finally, add in environment from the current process.
		for key, value in os.environ.iteritems():
			environment[key] = value

		return environment

	@staticmethod
	def get_environment(configuration, version):
		"""
		Get the entire environment required for a version, including the local
		environment. The results of this function are for use only on the
		calling node, and should not be sent to another node.
		"""
		# Helper to get the instance environment and our local environment in one go.
		environment = ApplicationEnvironment.get_instance_environment(configuration, version)
		environment = ApplicationEnvironment.merge_local_environment(configuration, environment)

		return environment<commit_msg>Updated the application environment builder to not require the configuration object.<commit_after>
import os
import copy
import json

class ApplicationEnvironment(object):
	@staticmethod
	def get_instance_environment(version):
		"""
		Fetch only the instance environment that is not node specific.
		Intended only to capture data that can be seralized and passed to
		a different node.
		"""
		environment = {}

		# Services first.
		credentials = version.get_service_credentials()
		environment['PM_SERVICES'] = json.dumps(credentials)

		# And the rest is rolled up into a single environment variable.
		meta = {}

		# Workspace parameters.
		meta['workspace'] = version.application.workspace.tags

		environment['PM_METADATA'] = json.dumps(meta)

		return environment

	@staticmethod
	def merge_local_environment(configuration, other_environment):
		"""
		Merge an application's environment with this nodes environment -
		that means this nodes's tags and local environment.
		"""
		environment = copy.deepcopy(other_environment)

		# Add in our nodes tags.
		meta = json.loads(environment['PM_METADATA'])
		meta['node'] = configuration['tags']
		environment['PM_METADATA'] = json.dumps(meta)

		# Finally, add in environment from the current process.
		for key, value in os.environ.iteritems():
			environment[key] = value

		return environment

	@staticmethod
	def get_environment(configuration, version):
		"""
		Get the entire environment required for a version, including the local
		environment. The results of this function are for use only on the
		calling node, and should not be sent to another node.
		"""
		# Helper to get the instance environment and our local environment in one go.
		environment = ApplicationEnvironment.get_instance_environment(version)
		environment = ApplicationEnvironment.merge_local_environment(configuration, environment)

		return environment
{'fraction_non_alphanumeric': 0.07696433360150175, 'fraction_numerical': 0.0, 'mean_word_length': 4.773993808049536, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4218881', 'n_tokens_mistral': 1059, 'n_tokens_neox': 952, 'n_words': 353}