def fix_venv(path, python, python_path, force): # Default to local venv path in current directory if not path: path = LOCAL_VIRTUALENV_PATH path = os.path.abspath(path) # Make sure virtualenv path exists if not os.path.exists(path): log.error('Virtualenv path does not exist: %s' % path) return False # Validate either Python interpreter or Python path if not python and not python_path: log.error( 'Please specify either a Python interpreter (with --python) or Python path (with --python-path) to recreate the virtualenv with.' ) return False if python: data = virtualenvs.get_virtualenvs() python_path = virtualenvs.resolve_python_paths(python, data) if not python_path: log.error('No valid interpreter path found for %s.' % python) log.info('Valid interpreters: %s' % ', '.join(data.get('pythonPaths').keys())) return False # Confirmation prompt yes = input('Are you sure you want to fix the virtualenv at %s? [y/n] ' % path).upper() == 'Y' if not yes: log.info('Aborting.') return False # Remove all symlinks in the virtualenv log.info('Removing broken symlinks in virtualenv...') num_broken = 0 for dirpath, dirnames, filenames in os.walk(path): for filename in filenames: fullpath = os.path.join(dirpath, filename) # Find broken symlinks, or any symlink if -f is passed if os.path.islink(fullpath) and (force or not os.path.exists(fullpath)): log.debug('Removing symlink %s' % fullpath) os.unlink(fullpath) num_broken += 1 if num_broken == 0: log.error('No broken symlinks found. Aborting.') return False # Recreate virtualenv log.info('Recreating virtualenv using %s...' % python_path) env = VirtualEnvironment(path, python=python_path) env._create() log.success('Done!')
def setup_env(self): env_path = self.env_path if env_path is None: env_path = tempfile.mkdtemp("test_env") virt_env = VirtualEnvironment(env_path) virt_env._create() for pack in packages_for_pre_install: virt_env.install(pack) return env_path
def test_system_site_packages(self): """ test that creating a venv with system_site_packages=True results in a venv that does not contain the no-global-site-packages file """ venv = VirtualEnvironment(self.dir, system_site_packages=True) venv._create() expected = os.path.join(venv.path, self.no_global) self.assertTrue(not os.path.exists(expected))
def setup_env(self): env_path = self.env_path if env_path is None: env_path = tempfile.mkdtemp('test_env') virt_env = VirtualEnvironment(env_path) virt_env._create() for pack in packages_for_pre_install: virt_env.install(pack) return env_path
def test_system_site_packages(self): """ test that creating a venv with system_site_packages=True results in a venv that does not contain the no-global-site-packages file """ venv = VirtualEnvironment(self.dir, system_site_packages=True) venv._create() expected = os.path.join(venv.path, self.no_global) self.assertTrue( not os.path.exists(expected) )
def setup_env(self): env_path = self.env_path if env_path is None: # See: https://github.com/pypa/pip/issues/1773 This test may not be 100% accurate, tips on improving? # Windows and OSX have their own limits so this may not work 100% of the time long_path = "".join([random.choice(string.digits) for _ in range(0, 129)]) env_path = tempfile.mkdtemp('test_long_env-'+long_path) virt_env = VirtualEnvironment(env_path) virt_env._create() for pack in packages_for_pre_install: virt_env.install(pack) return env_path
def setup_env(self): env_path = self.env_path if env_path is None: # See: https://github.com/pypa/pip/issues/1773 This test may not be 100% accurate, tips on improving? # Windows and OSX have their own limits so this may not work 100% of the time long_path = "".join( [random.choice(string.digits) for _ in range(0, 129)]) env_path = tempfile.mkdtemp('test_long_env-' + long_path) virt_env = VirtualEnvironment(env_path) virt_env._create() for pack in packages_for_pre_install: virt_env.install(pack) return env_path