def test_basic_bootstrapping(self): ensurepip._main([]) if sys.platform == 'cli': args = [ "install", "--no-index", "--find-links", mock.ANY, "--no-compile", "setuptools", "pip", ] else: args = [ "install", "--no-index", "--find-links", mock.ANY, "setuptools", "pip", ] self.run_pip.assert_called_once_with( args, mock.ANY, ) additional_paths = self.run_pip.call_args[0][1] self.assertEqual(len(additional_paths), 2)
def test_bootstrap_version(self): with test.support.captured_stdout() as stdout: with self.assertRaises(SystemExit): ensurepip._main(["--version"]) result = stdout.getvalue().strip() self.assertEqual(result, EXPECTED_VERSION_OUTPUT) self.assertFalse(self.run_pip.called)
def test_basic_bootstrapping(self): ensurepip._main([]) self.run_pip.assert_called_once_with([ 'install', '--no-index', '--find-links', unittest.mock.ANY, 'setuptools', 'pip' ], unittest.mock.ANY) additional_paths = self.run_pip.call_args[0][1] self.assertEqual(len(additional_paths), 2)
def test_basic_bootstrapping(self): ensurepip._main([]) self.run_pip.assert_called_once_with( ["install", "--no-index", "--find-links", unittest.mock.ANY, "setuptools", "pip"], unittest.mock.ANY ) additional_paths = self.run_pip.call_args[0][1] self.assertEqual(len(additional_paths), 2)
def test_basic_bootstrapping(self): ensurepip._main([]) self.run_pip.assert_called_once_with( [ "install", "--no-index", "--find-links", unittest.mock.ANY, "setuptools", "pip", ], unittest.mock.ANY, ) additional_paths = self.run_pip.call_args[0][1] self.assertEqual(len(additional_paths), 2)
import ensurepip import sys if __name__ == "__main__": sys.exit(ensurepip._main())
def main(cont): # Sensors sensor = cont.sensors[0] if sensor.positive: # Other ext_exe = '.exe' if system() == 'Windows' else '' system_supported = system() in ['Windows', 'Linux'] # Paths path_current = Path('.').resolve() path_bgcython = Path( Path(__file__).resolve().parent.as_posix() + '/bgcython').resolve() path_blender = Path(sys.executable).resolve() path_python = None path_sitepkg = None # Set remaining path variables, walking through blender files structure for _path, _folders, _files in os.walk(path_blender.parent.as_posix()): # python/bin folder if _path.endswith('bin'): for _file in _files: _p = Path(_path + '/' + _file).resolve() # Check if file is a python executable if _file.startswith('python') and _file.endswith( ext_exe) and os.access(_p.as_posix(), os.X_OK): path_python = _p # Get folder site-packages from python library if _path.endswith('site-packages'): path_sitepkg = Path(_path).resolve() # Break loop to avoid reading unecessary files if path_python and path_sitepkg: break ### START ### ### Only continue if all paths exists ### if system_supported and path_bgcython.exists() and path_blender.exists( ) and path_python.exists() and path_sitepkg.exists(): # Change working directory to Python binaries directory os.chdir(path_python.parent.as_posix()) # Print main paths print('\n> Blender path is:\n' + path_blender.as_posix() + '\n' + '\n> Python path is:\n' + path_python.as_posix() + '\n' + '\n> site-packages path is:\n' + path_sitepkg.as_posix() + '\n') # If pip is not installed if not 'pip' in os.listdir(path_sitepkg.as_posix()): print( 'pip is not installed, installing it through ensurepip\n') # Execute ensurepip print('Execute ensurepip') import ensurepip ensurepip._main() print('pip successfully installed\n') # Continue if pip is installed if 'pip' in os.listdir(path_sitepkg.as_posix()): # If Cython is not installed if not 'Cython' in os.listdir(path_sitepkg.as_posix()): print( 'Cython is not installed, installing it through pip\n') # Install Cython through pip call(path_python.name + ' -m pip install Cython') print('Cython successfully installed\n') # If bgcython is not installed if not 'bgcython' in os.listdir(path_sitepkg.as_posix()): print('bgcython is not installed, installing it\n') # Copy bgcython package to site-packages print('Copying bgcython package to site-packages') shutil.copytree(path_bgcython.as_posix(), path_sitepkg.as_posix() + '/bgcython/') # Copy settings.txt to package folder print('Copying settings.txt package folder') shutil.copyfile( path_bgcython.as_posix() + '/settings.txt', path_sitepkg.as_posix() + '/bgcython/settings.txt') print('bgcython successfully installed\n') # Open settings file for editing os.startfile(path_sitepkg.as_posix() + '/bgcython/settings.txt') print('Installation successfully finished') # Change working directory back to current os.chdir(path_current.as_posix())
def test_bootstrapping_error_code(self): self.run_pip.return_value = 2 exit_code = ensurepip._main([]) self.assertEqual(exit_code, 2)
python_links = ['python', 'python3', 'python3.7'] for link in python_links: try: full = os.path.join(bin_dir, link) os.unlink(full) os.symlink(exe, full) except OSError: pass #TODO offline initialization try: import pip except ImportError: import ensurepip ensurepip._main() import pip try: try: import requests except ImportError: print('installing requests setuptools wheel') execute([exe, '-m', 'pip', 'install', '--upgrade', 'pip', 'setuptools', 'wheel', 'requests'], kill_phrases=INSTALL_PHRASES) import requests except Exception: pass #optional packages upgrade = False tar = os.path.join(os.environ['TMP'], 'appy.tar.gz') try:
import ensurepip if __name__ == "__main__": ensurepip._main()