<commit_before>import os

import fabric.api
import fabric.colors

from fab_deploy.file import link

def virtualenv_create(dir='/srv/active/',site_packages=True):
	""" 
	Create a virtual environment in the /<dir>/env/ directory
	"""
	if site_packages:
		fabric.api.run('virtualenv %s' % os.path.join(dir,'env/'))
	else:
		fabric.api.run('virtualenv --no-site-packages %s' % os.path.join(dir,'env/'))
	link('env/bin/activate',do_unlink=True,silent=True)

def virtualenv(dir='/srv/active/'):
	"""
	Context manager. Use it to perform actions inside virtualenv::

		with virtualenv():
			# virtualenv is active here
	
	"""
	fabric.api.puts(fabric.colors.green('source %s' % os.path.join(dir,'env/bin/activate')))
	return fabric.api.prefix('source %s' % os.path.join(dir,'env/bin/activate'))

def pip(dir='/srv/active/',commands=''):
	""" Runs pip command """
	with virtualenv(dir):
   		fabric.api.run('pip %s' % commands)

def pip_install(dir='/srv/active/',what='requirements', options=''):
	""" Installs pip requirements listed in ``deploy/<file>.txt`` file. """
	pip(dir,commands='install %s -r %s/deploy/%s.txt' % (options,dir,what))

def pip_update(dir='/srv/active/',what='requirements', options=''):
	""" Updates pip requirements listed in ``deploy/<file>.txt`` file. """
   	pip(dir,commands='install %s -U -r %s/deploy/%s.txt' % (options,dir,what))

<commit_msg>Added legacy code to support both repos with deploy/requirements/base.txt and (old-style) deploy/requirements.txt<commit_after>import os

import fabric.api
import fabric.colors

from fab_deploy.file import link

def virtualenv_create(dir='/srv/active/',site_packages=True):
	""" 
	Create a virtual environment in the /<dir>/env/ directory
	"""
	if site_packages:
		fabric.api.run('virtualenv %s' % os.path.join(dir,'env/'))
	else:
		fabric.api.run('virtualenv --no-site-packages %s' % os.path.join(dir,'env/'))
	link('env/bin/activate',do_unlink=True,silent=True)

def virtualenv(dir='/srv/active/'):
	"""
	Context manager. Use it to perform actions inside virtualenv::

		with virtualenv():
			# virtualenv is active here
	
	"""
	fabric.api.puts(fabric.colors.green('source %s' % os.path.join(dir,'env/bin/activate')))
	return fabric.api.prefix('source %s' % os.path.join(dir,'env/bin/activate'))

def pip(dir='/srv/active/',commands=''):
	""" Runs pip command """
	with virtualenv(dir):
   		fabric.api.run('pip %s' % commands)

def pip_install(dir='/srv/active/',what='requirements', options=''):
	""" Installs pip requirements listed in ``deploy/<file>.txt`` file. """
	# Basic requirements used to be in requirements.txt but are now in
	# requirements/base.txt. The next line provides legacy support
	if(what=='requirements' and not fabric.contrib.files.exists(dir + '/deploy/' + '/requirements.txt') and fabric.contrib.files.exists(dir + '/deploy/' + '/requirements/base.txt')):
		what = 'requirements/base'
	pip(dir,commands='install %s -r %s/deploy/%s.txt' % (options,dir,what))

def pip_update(dir='/srv/active/',what='requirements', options=''):
	""" Updates pip requirements listed in ``deploy/<file>.txt`` file. """
   	pip(dir,commands='install %s -U -r %s/deploy/%s.txt' % (options,dir,what))


{'fraction_non_alphanumeric': 0.1858267716535433, 'fraction_numerical': 0.0, 'mean_word_length': 4.903345724907063, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6684591', 'n_tokens_mistral': 1131, 'n_tokens_neox': 1080, 'n_words': 233}