我们从Python开源项目中,提取了以下35个代码示例,用于说明如何使用setuptools.command.easy_install.main()。
def test_setup_requires_honors_fetch_params(self): """ When easy_install installs a source distribution which specifies setup_requires, it should honor the fetch parameters (such as allow-hosts, index-url, and find-links). """ # set up a server which will simulate an alternate package index. p_index = setuptools.tests.server.MockServer() p_index.start() netloc = 1 p_index_loc = urlparse(p_index.url)[netloc] if p_index_loc.endswith(':0'): # Some platforms (Jython) don't find a port to which to bind, # so skip this test for them. return with quiet_context(): # create an sdist that has a build-time dependency. with TestSetupRequires.create_sdist() as dist_file: with tempdir_context() as temp_install_dir: with environment_context(PYTHONPATH=temp_install_dir): ei_params = ['--index-url', p_index.url, '--allow-hosts', p_index_loc, '--exclude-scripts', '--install-dir', temp_install_dir, dist_file] with reset_setup_stop_context(): with argv_context(['easy_install']): # attempt to install the dist. It should fail because # it doesn't exist. self.assertRaises(SystemExit, easy_install_pkg.main, ei_params) # there should have been two or three requests to the server # (three happens on Python 3.3a) self.assertTrue(2 <= len(p_index.requests) <= 3) self.assertEqual(p_index.requests[0].path, '/does-not-exist/')
def main(argv, version=DEFAULT_VERSION): """Install or upgrade setuptools and EasyInstall""" try: import setuptools except ImportError: egg = None try: egg = download_setuptools(version, delay=0) sys.path.insert(0,egg) from setuptools.command.easy_install import main return main(list(argv)+[egg]) # we're done here finally: if egg and os.path.exists(egg): os.unlink(egg) else: if setuptools.__version__ == '0.0.1': print >>sys.stderr, ( "You have an obsolete version of setuptools installed. Please\n" "remove it from your system entirely before rerunning this script." ) sys.exit(2) req = "setuptools>="+version import pkg_resources try: pkg_resources.require(req) except pkg_resources.VersionConflict: try: from setuptools.command.easy_install import main except ImportError: from easy_install import main main(list(argv)+[download_setuptools(delay=0)]) sys.exit(0) # try to force an exit else: if argv: from setuptools.command.easy_install import main main(argv) else: print "Setuptools version",version,"or greater has been installed." print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
def main(argv, version=DEFAULT_VERSION): """Install or upgrade setuptools and EasyInstall""" try: import setuptools except ImportError: egg = None try: egg = download_setuptools(version, delay=0) sys.path.insert(0,egg) from setuptools.command.easy_install import main return main(list(argv)+[egg]) # we're done here finally: if egg and os.path.exists(egg): os.unlink(egg) else: if setuptools.__version__ == '0.0.1': sys.stderr.write( "You have an obsolete version of setuptools installed. Please\n" "remove it from your system entirely before rerunning this script.\n" ) sys.exit(2) req = "setuptools>="+version import pkg_resources try: pkg_resources.require(req) except pkg_resources.VersionConflict: try: from setuptools.command.easy_install import main except ImportError: from easy_install import main main(list(argv)+[download_setuptools(delay=0)]) sys.exit(0) # try to force an exit else: if argv: from setuptools.command.easy_install import main main(argv) else: print("Setuptools version",version,"or greater has been installed.") print('(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)')
def check_prerequisites(): if major == 2: raise Exception("\nERROR RUNNING INSTALLATION:\n" "You are running the setup with Python " + str(major) + "." + str(minor) + "." + str( micro) + "!\n" "Please install Python version 3.4 or higher and run with that version instead (python3 optimalsetup.py)") if major == 3 and minor < 4: _pythonversion = str(major) + "." + str(minor) + "." + str(micro) try: print("Python " + _pythonversion + " found, so checking if pip is installed..") import pip print("it was, continuing..") except ImportError: print("it wasn't, checking if easy_install is installed..") try: from setuptools.command import easy_install if minor == 3: print("it was, installing pip..") easy_install.main(["pip"]) else: print("it was, installing pip 7.1.2 because 8.x isn't compatible with 3.0-3.2..") easy_install.main(["pip==7.1.2"]) except ImportError: print("it wasn't, halting installation, raising error.") raise Exception("Error RUNNING INSTALLATION:\n" "You are running the setup with Python " + _pythonversion + "!\n" "It doesn't have pip package management installed as default and this installation failed to install it automatically.\n" "PLease check the pip web site for instructions for your platform:\n" "https://pip.pypa.io/en/stable/installing/")
def install_package(_package_name, _arguments=None): """ Install the packages listed if not present :param _package_name: The package to install :param _argument: An optional argument :return: """ _installed = [] import pip _exists = None if minor < 3: import pkgutil _exists = pkgutil.find_loader(_package_name) elif minor == 3: import importlib _exists = importlib.find_loader(_package_name) else: import importlib _exists = importlib.util.find_spec(_package_name) if _exists is None: print(_package_name + " not installed, installing...") if _arguments is None: pip.main(['install', _package_name]) else: pip.main(['install', _package_name] + _arguments) print(_package_name + " installed...") return True else: print(_package_name + " already installed, skipping...") return False
def main(argv, version=DEFAULT_VERSION): """Install or upgrade setuptools and EasyInstall""" try: import setuptools except ImportError: egg = None try: egg = download_setuptools(version, delay=0) sys.path.insert(0, egg) from setuptools.command.easy_install import main return main(list(argv)+[egg]) # we're done here finally: if egg and os.path.exists(egg): os.unlink(egg) else: if setuptools.__version__ == '0.0.1': print >>sys.stderr, ( "You have an obsolete version of setuptools installed." " Please remove it from your system entirely before rerunning" " this script.") sys.exit(2) req = "setuptools>="+version import pkg_resources try: pkg_resources.require(req) except pkg_resources.VersionConflict: try: from setuptools.command.easy_install import main except ImportError: from easy_install import main main(list(argv)+[download_setuptools(delay=0)]) sys.exit(0) # try to force an exit else: if argv: from setuptools.command.easy_install import main main(argv) else: print ("Setuptools version", version, "or greater has been installed.") print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
def test_setup_requires_honors_fetch_params(self): """ When easy_install installs a source distribution which specifies setup_requires, it should honor the fetch parameters (such as allow-hosts, index-url, and find-links). """ # set up a server which will simulate an alternate package index. p_index = setuptools.tests.server.MockServer() p_index.start() netloc = 1 p_index_loc = urlparse(p_index.url)[netloc] if p_index_loc.endswith(':0'): # Some platforms (Jython) don't find a port to which to bind, # so skip this test for them. return with contexts.quiet(): # create an sdist that has a build-time dependency. with TestSetupRequires.create_sdist() as dist_file: with contexts.tempdir() as temp_install_dir: with contexts.environment(PYTHONPATH=temp_install_dir): ei_params = [ '--index-url', p_index.url, '--allow-hosts', p_index_loc, '--exclude-scripts', '--install-dir', temp_install_dir, dist_file, ] with sandbox.save_argv(['easy_install']): # attempt to install the dist. It should fail because # it doesn't exist. with pytest.raises(SystemExit): easy_install_pkg.main(ei_params) # there should have been two or three requests to the server # (three happens on Python 3.3a) assert 2 <= len(p_index.requests) <= 3 assert p_index.requests[0].path == '/does-not-exist/'
def test_setup_requires_honors_fetch_params(self): """ When easy_install installs a source distribution which specifies setup_requires, it should honor the fetch parameters (such as allow-hosts, index-url, and find-links). """ # set up a server which will simulate an alternate package index. p_index = setuptools.tests.server.MockServer() p_index.start() netloc = 1 p_index_loc = urllib.parse.urlparse(p_index.url)[netloc] if p_index_loc.endswith(':0'): # Some platforms (Jython) don't find a port to which to bind, # so skip this test for them. return with contexts.quiet(): # create an sdist that has a build-time dependency. with TestSetupRequires.create_sdist() as dist_file: with contexts.tempdir() as temp_install_dir: with contexts.environment(PYTHONPATH=temp_install_dir): ei_params = [ '--index-url', p_index.url, '--allow-hosts', p_index_loc, '--exclude-scripts', '--install-dir', temp_install_dir, dist_file, ] with sandbox.save_argv(['easy_install']): # attempt to install the dist. It should fail because # it doesn't exist. with pytest.raises(SystemExit): easy_install_pkg.main(ei_params) # there should have been two or three requests to the server # (three happens on Python 3.3a) assert 2 <= len(p_index.requests) <= 3 assert p_index.requests[0].path == '/does-not-exist/'
def win_install_deps(options): """ Install all Windows Binary automatically This can be removed as wheels become available for these packages """ download_dir = path('downloaded').abspath() if not download_dir.exists(): download_dir.makedirs() win_packages = { # required by transifex-client "Py2exe": dev_config['WINDOWS']['py2exe'], "Nose": dev_config['WINDOWS']['nose'], # the wheel 1.9.4 installs but pycsw wants 1.9.3, which fails to compile # when pycsw bumps their pyproj to 1.9.4 this can be removed. "PyProj": dev_config['WINDOWS']['pyproj'], "lXML": dev_config['WINDOWS']['lxml'] } failed = False for package, url in win_packages.iteritems(): tempfile = download_dir / os.path.basename(url) print "Installing file ... " + tempfile grab_winfiles(url, tempfile, package) try: easy_install.main([tempfile]) except Exception as e: failed = True print "install failed with error: ", e os.remove(tempfile) if failed and sys.maxsize > 2**32: print "64bit architecture is not currently supported" print "try finding the 64 binaries for py2exe, nose, and pyproj" elif failed: print "install failed for py2exe, nose, and/or pyproj" else: print "Windows dependencies now complete. Run pip install -e geonode --use-mirrors"
def test_setup_requires_honors_fetch_params(self): """ When easy_install installs a source distribution which specifies setup_requires, it should honor the fetch parameters (such as allow-hosts, index-url, and find-links). """ # set up a server which will simulate an alternate package index. p_index = setuptools.tests.server.MockServer() p_index.start() netloc = 1 p_index_loc = urlparse(p_index.url)[netloc] if p_index_loc.endswith(':0'): # Some platforms (Jython) don't find a port to which to bind, # so skip this test for them. return # create an sdist that has a build-time dependency. with TestSetupRequires.create_sdist() as dist_file: with tempdir_context() as temp_install_dir: with environment_context(PYTHONPATH=temp_install_dir): ei_params = ['--index-url', p_index.url, '--allow-hosts', p_index_loc, '--exclude-scripts', '--install-dir', temp_install_dir, dist_file] with reset_setup_stop_context(): with argv_context(['easy_install']): # attempt to install the dist. It should fail because # it doesn't exist. self.assertRaises(SystemExit, easy_install_pkg.main, ei_params) # there should have been two or three requests to the server # (three happens on Python 3.3a) self.assertTrue(2 <= len(p_index.requests) <= 3) self.assertEqual(p_index.requests[0].path, '/does-not-exist/')
def main(argv, version=DEFAULT_VERSION): """Install or upgrade setuptools and EasyInstall""" try: import setuptools except ImportError: egg = None try: egg = download_setuptools(version, delay=0) sys.path.insert(0,egg) from setuptools.command.easy_install import main return main(list(argv)+[egg]) # we're done here finally: if egg and os.path.exists(egg): os.unlink(egg) else: if setuptools.__version__ == '0.0.1': # tell the user to uninstall obsolete version use_setuptools(version) req = "setuptools>="+version import pkg_resources try: pkg_resources.require(req) except pkg_resources.VersionConflict: try: from setuptools.command.easy_install import main except ImportError: from easy_install import main main(list(argv)+[download_setuptools(delay=0)]) sys.exit(0) # try to force an exit else: if argv: from setuptools.command.easy_install import main main(argv) else: print "Setuptools version",version,"or greater has been installed." print '(Run "ez_setup.py -U setuptools" to reinstall or upgrade.)'
def gen_lib(): """Build libs locally for app Using the setup.py this method will install all required python modules locally to be used for local testing. """ lib_directory = 'lib_{}.{}.{}'.format( sys.version_info.major, sys.version_info.minor, sys.version_info.micro) app_path = os.getcwd() app_name = os.path.basename(app_path) lib_path = os.path.join(app_path, lib_directory) if not os.path.isdir(lib_path): os.mkdir(lib_path) os.environ['PYTHONPATH'] = '{}'.format(lib_path) stdout = sys.stdout stderr = sys.stderr try: with open(os.path.join(app_path, '{}-libs.log'.format(app_name)), 'w') as log: sys.stdout = log sys.stderr = log easy_install.main(['-axZ', '-d', lib_path, str(app_path)]) except SystemExit as e: raise Exception(str(e)) finally: sys.stdout = stdout sys.stderr = stderr if os.listdir(lib_path): err = 'Encountered error running easy_install for {}. Check log file for details.' raise Exception(err.format(app_name)) build_path = os.path.join(app_path, 'build') if os.access(build_path, os.W_OK): shutil.rmtree(build_path) temp_path = os.path.join(app_path, 'temp') if os.access(temp_path, os.W_OK): shutil.rmtree(temp_path) egg_path = os.path.join(app_path, app_name + '.egg-info') if os.access(egg_path, os.W_OK): shutil.rmtree(egg_path)
def main(): parser = optparse.OptionParser() parser.add_option('-d', '--download-dir', help='Directory with maually downloaded python modules.' ) opts, _ = parser.parse_args() # Install packages. for k, v in _PACKAGES.items(): # Test python version for module. if k in _PY_VERSION: # Python version too old, skip module. if PYVER < _PY_VERSION[k]: continue try: __import__(k) print('Already installed...', k) # Module is not available - install it. except ImportError: # If not url or module name then look for installers in download area. if not v[0].startswith('http') and v[0].endswith('exe'): files = [] # Try all file patterns. for pattern in v: pattern = os.path.join(opts.download_dir, pattern) files += glob.glob(pattern) # No file with that pattern was not found - skip it. if not files: print('Skipping module...', k) continue # Full path to installers in download directory. v = files print('Installing module...', k) # Some modules might require several .exe files to install. for f in v: print(' ', f) # Use --no-deps ... installing module dependencies might fail # because easy_install tries to install the same module from # PYPI from source code and if fails because of C code that # that needs to be compiled. try: easy_install.main(['--no-deps', '--always-unzip', f]) except Exception: print(' ', k, 'installation failed')
def test_setup_requires_honors_fetch_params(self): """ When easy_install installs a source distribution which specifies setup_requires, it should honor the fetch parameters (such as allow-hosts, index-url, and find-links). """ # set up a server which will simulate an alternate package index. p_index = setuptools.tests.server.MockServer() p_index.start() netloc = 1 p_index_loc = urlparse(p_index.url)[netloc] if p_index_loc.endswith(':0'): # Some platforms (Jython) don't find a port to which to bind, # so skip this test for them. return # I realize this is all-but-impossible to read, because it was # ported from some well-factored, safe code using 'with'. If you # need to maintain this code, consider making the changes in # the parent revision (of this comment) and then port the changes # back for Python 2.4 (or deprecate Python 2.4). def install(dist_file): def install_at(temp_install_dir): def install_env(): ei_params = ['--index-url', p_index.url, '--allow-hosts', p_index_loc, '--exclude-scripts', '--install-dir', temp_install_dir, dist_file] def install_clean_reset(): def install_clean_argv(): # attempt to install the dist. It should fail because # it doesn't exist. self.assertRaises(SystemExit, easy_install_pkg.main, ei_params) argv_context(install_clean_argv, ['easy_install']) reset_setup_stop_context(install_clean_reset) environment_context(install_env, PYTHONPATH=temp_install_dir) tempdir_context(install_at) # create an sdist that has a build-time dependency. self.create_sdist(install) # there should have been two or three requests to the server # (three happens on Python 3.3a) self.assertTrue(2 <= len(p_index.requests) <= 3) self.assertEqual(p_index.requests[0].path, '/does-not-exist/')