Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create_environment():
dest_dir = os.path.join(DIRNAME, CONFIG['virtualenv']['dest_dir'])
dest_dir = os.path.abspath(dest_dir)
# Create new virtual environment
print('Step 1. Create new virtual environment')
if not os.path.isdir(dest_dir) or CONFIG['virtualenv']['clear']:
kwargs = copy.copy(CONFIG['virtualenv'])
kwargs['home_dir'] = kwargs['dest_dir']
verbosity = int(kwargs['verbose']) - int(kwargs['quiet'])
logger = virtualenv.Logger([
(virtualenv.Logger.level_for_integer(2 - verbosity), sys.stdout),
])
del kwargs['dest_dir'], kwargs['quiet'], kwargs['verbose']
virtualenv.logger = logger
virtualenv.create_environment(**kwargs)
else:
print('Virtual environment %r already exists.' % \
CONFIG['virtualenv']['dest_dir'])
def create(self):
# Create new virtual environment
print('\nStep 1. Create new virtual environment')
if not os.path.isdir(self.dest_dir) or CONFIG['virtualenv']['clear']:
kwargs = copy.copy(CONFIG['virtualenv'])
kwargs['home_dir'] = self.dest_dir
verbosity = int(kwargs['verbose']) - int(kwargs['quiet'])
logger = virtualenv.Logger([
(virtualenv.Logger.level_for_integer(2 - verbosity),
sys.stdout),
])
del kwargs['dest_dir'], kwargs['quiet'], kwargs['verbose']
virtualenv.logger = logger
virtualenv.create_environment(**kwargs)
else:
print('Virtual environment %r already exists.' % self.dest_dir)
)
if "extend_parser" in globals():
# noinspection PyUnresolvedReferences
extend_parser(parser) # noqa: F821
options, args = parser.parse_args()
global logger
if "adjust_options" in globals():
# noinspection PyUnresolvedReferences
adjust_options(options, args) # noqa: F821
verbosity = options.verbose - options.quiet
logger = Logger([(Logger.level_for_integer(2 - verbosity), sys.stdout)])
def should_reinvoke(options):
"""Do we need to reinvoke ourself?"""
# Did the user specify the --python option?
if options.python and not os.environ.get("VIRTUALENV_INTERPRETER_RUNNING"):
interpreter = resolve_interpreter(options.python)
if interpreter != sys.executable:
# The user specified a different interpreter, so we have to reinvoke.
return interpreter
# At this point, we know the user wants to use sys.executable to create the
# virtual environment. But on Windows, sys.executable may be a venv redirector,
# in which case we still need to locate the underlying actual interpreter, and
# reinvoke using that.
if IS_WIN:
# OK. Now things get really fun...
def filter_install_output(line):
if line.strip().startswith("running"):
return Logger.INFO
return Logger.DEBUG
def reset_python_environment(self):
"""
Reset the python environment.
"""
path = self.root_path
if not exists(path):
return False
virtualenv.logger = virtualenv.Logger(
[(virtualenv.Logger.level_for_integer(2), sys.stdout)])
virtualenv.create_environment(path, site_packages=False)
return True
else:
return level >= consumer_level
@classmethod
def level_for_integer(cls, level):
levels = cls.LEVELS
if level < 0:
return levels[0]
if level >= len(levels):
return levels[-1]
return levels[level]
# create a silent logger just to prevent this from being undefined
# will be overridden with requested verbosity main() is called.
logger = Logger([(Logger.LEVELS[-1], sys.stdout)])
def mkdir(at_path):
if not os.path.exists(at_path):
logger.info("Creating %s", at_path)
os.makedirs(at_path)
else:
logger.info("Directory %s already exists", at_path)
def copy_file_or_folder(src, dest, symlink=True):
if os.path.isdir(src):
shutil.copytree(src, dest, symlink)
else:
shutil.copy2(src, dest)
else:
return level >= consumer_level
@classmethod
def level_for_integer(cls, level):
levels = cls.LEVELS
if level < 0:
return levels[0]
if level >= len(levels):
return levels[-1]
return levels[level]
# create a silent logger just to prevent this from being undefined
# will be overridden with requested verbosity main() is called.
logger = Logger([(Logger.LEVELS[-1], sys.stdout)])
def mkdir(path):
if not os.path.exists(path):
logger.info("Creating %s", path)
os.makedirs(path)
else:
logger.info("Directory %s already exists", path)
def copyfileordir(src, dest, symlink=True):
if os.path.isdir(src):
shutil.copytree(src, dest, symlink)
else:
shutil.copy2(src, dest)
virtualenv_globals['main']()
finally:
sys.argv[:] = orig_argv
else:
try:
import virtualenv
except ImportError:
raise errors.DistutilsModuleError(
'The virtualenv module must be available if no virtualenv '
'bootstrap script is given: {0}'.format(bootstrap))
self.logger.info(
'Setting up a isolated Python with module: '
'{0}.create_environment({1} {2})'.format(
virtualenv, repr(home_dir), ' '.join(
'{0}={1}'.format(item) for item in opts.items())))
virtualenv.logger = virtualenv.Logger([(
virtualenv.Logger.level_for_integer(2 - self.verbose),
sys.stdout)])
virtualenv.create_environment(home_dir, **opts)
return os.path.join(
sysconfig.get_path('scripts', vars=dict(base=home_dir)),
'python' + sysconfig.get_config_var('EXE'))