def fetch_build_egg(self, req): """ Specialized version of Distribution.fetch_build_egg that respects respects allow_hosts and index_url. """ from setuptools.command.easy_install import easy_install dist = Distribution({'script_args': ['easy_install']}) dist.parse_config_files() opts = dist.get_option_dict('easy_install') keep = ( 'find_links', 'site_dirs', 'index_url', 'optimize', 'site_dirs', 'allow_hosts' ) for key in list(opts): if key not in keep: del opts[key] # don't use any other settings if self.dependency_links: links = self.dependency_links[:] if 'find_links' in opts: links = opts['find_links'][1].split() + links opts['find_links'] = ('setup', links) if self.allow_hosts: opts['allow_hosts'] = ('test', self.allow_hosts) if self.index_url: opts['index_url'] = ('test', self.index_url) install_dir_func = getattr(self, 'get_egg_cache_dir', _os.getcwd) install_dir = install_dir_func() cmd = easy_install( dist, args=["x"], install_dir=install_dir, exclude_scripts=True, always_copy=False, build_directory=None, editable=False, upgrade=False, multi_version=True, no_report=True, user=False ) cmd.ensure_finalized() return cmd.easy_install(req)
def get_option_dict(self, command_name): opts = Distribution.get_option_dict(self, command_name) if command_name == 'easy_install': if find_links is not None: opts['find_links'] = ('setup script', find_links) if index_url is not None: opts['index_url'] = ('setup script', index_url) if allow_hosts is not None: opts['allow_hosts'] = ('setup script', allow_hosts) return opts
def get_option_dict(self, command_name): opts = Distribution.get_option_dict(self, command_name) if command_name == "easy_install": if find_links is not None: opts["find_links"] = ("setup script", find_links) if index_url is not None: opts["index_url"] = ("setup script", index_url) if allow_hosts is not None: opts["allow_hosts"] = ("setup script", allow_hosts) return opts
def get_option_dict(self, command_name): opts = Distribution.get_option_dict(self, command_name) if command_name == 'easy_install': if find_links is not None: opts['find_links'] = ('setup script', find_links) if index_url is not None: opts['index_url'] = ('setup script', index_url) # For setuptools>=42, the allow_hosts option can't # be used because pip doesn't support it. if allow_hosts is not None and SETUPTOOLS_LT_42: opts['allow_hosts'] = ('setup script', allow_hosts) return opts
def fetch_build_egg(self, req): """ Specialized version of Distribution.fetch_build_egg that respects respects allow_hosts and index_url. """ from setuptools.command.easy_install import easy_install dist = Distribution({"script_args": ["easy_install"]}) dist.parse_config_files() opts = dist.get_option_dict("easy_install") keep = ( "find_links", "site_dirs", "index_url", "optimize", "site_dirs", "allow_hosts", ) for key in list(opts): if key not in keep: del opts[key] # don't use any other settings if self.dependency_links: links = self.dependency_links[:] if "find_links" in opts: links = opts["find_links"][1].split() + links opts["find_links"] = ("setup", links) if self.allow_hosts: opts["allow_hosts"] = ("test", self.allow_hosts) if self.index_url: opts["index_url"] = ("test", self.index_url) install_dir_func = getattr(self, "get_egg_cache_dir", _os.getcwd) install_dir = install_dir_func() cmd = easy_install( dist, args=["x"], install_dir=install_dir, exclude_scripts=True, always_copy=False, build_directory=None, editable=False, upgrade=False, multi_version=True, no_report=True, user=False, ) cmd.ensure_finalized() return cmd.easy_install(req)
def read_setuptools_cfg(): """ Reads the `setup.cfg` file and extracts the various requirements lists """ # see https://stackoverflow.com/a/30679041/7262247 from setuptools import Distribution dist = Distribution() dist.parse_config_files() # standard requirements options_dct = dist.get_option_dict('options') setup_reqs = options_dct['setup_requires'][1].strip().splitlines() install_reqs = options_dct['install_requires'][1].strip().splitlines() tests_reqs = options_dct['tests_require'][1].strip().splitlines() return SetupCfg(setup_requires=setup_reqs, install_requires=install_reqs, tests_requires=tests_reqs)
def main(argv=None, **kw): """ Run a test package's tests. """ org.setup_global_org_config() USAGE = """\ usage: %(script)s <package name> [test options] or: %(script)s --help """ % { 'script': sys.argv[0] or 'runtests' } if argv is None: argv = sys.argv[1:] if not argv: print "Please specify a package name." print USAGE sys.exit(1) pkg_name, argv = argv[0], argv[1:] test_pkg_name = 'test.%s' % pkg_name # Find our real_dist = [i for i in working_set if i.project_name == pkg_name] if not real_dist: print "Package %s is not installed" % pkg_name sys.exit(1) real_dist = real_dist[0] test_dist = [i for i in working_set if i.project_name == test_pkg_name] if not test_dist: print "Test package %s is not installed" % test_pkg_name sys.exit(1) test_dist = test_dist[0] # Construct a distutils.Distribtion class from the pkg_resources.Distribution # of the real package so we can pass it into the test command class. # We have checked that the packages are already installed so we set the install # requirements to blank. args = { 'name': real_dist.project_name, 'install_requires': [], 'tests_require': [], 'namespace_packages': list(real_dist._get_metadata('namespace_packages')), 'packages': [real_dist.project_name], } real_cmd_dist = Distribution(args) cmd = test(real_cmd_dist) cmd.args = argv # Read in the test options saved away during egg_info and set the command defaults, # this would normally be done by the setup() method via the Distribution class test_options = join(test_dist.location, 'EGG-INFO', 'test_options.txt') if isfile(test_options): real_cmd_dist.parse_config_files([test_options]) for k, v in real_cmd_dist.get_option_dict('test').items(): print "Found test option in %s: %s = %s" % (v[0], k, v[1]) setattr(cmd, k, v[1]) # Finalize and run the command, overriding the test root to be inside the test egg cmd.finalize_options() cmd.test_root = join(test_dist.location, CONFIG.test_egg_namespace, real_dist.project_name.replace('.', '/')) # Pylint is only for regular Jenkins jobs, this in itself should not trigger even if # running under Jenkins cmd.no_pylint = True cmd.run()
# Third-party modules - we depend on numpy for everything import numpy # Obtain the numpy include directory. This logic works across numpy versions. try: numpy_include = numpy.get_include() except AttributeError: numpy_include = numpy.get_numpy_include() # Get our own instance of Distribution dist = Distribution() dist.parse_config_files() dist.parse_command_line() # Get prefix from either config file or command line prefix = dist.get_option_dict('install')['prefix'][1] print("Prefix is: " + prefix) pymod_name = "parcels_nodes" py_version = 'python%d.%d' % (sys.version_info[0], sys.version_info[1]) print(sys.prefix) PCLS_NODES_HOME = '/git_code/list_set_experiments' # '/vps/otbknox/williams/OTB_2.0' PCLS_NODES_INCLDIR = [ os.path.join(PCLS_NODES_HOME, pymod_name, 'include'), os.path.join(sys.prefix, 'include'), os.path.join(sys.prefix, 'include', py_version), os.path.join(sys.prefix, 'lib', py_version, 'site-packages', pymod_name, 'include'), os.path.join(prefix, py_version, 'site-packages', pymod_name, 'include') ] PCLS_NODES_LIBDIR = [
def main(argv=None, **kw): """ Run a test package's tests. """ # TODO: allow cmdline override of org config? config.setup_org_config() from path import path USAGE = """\ usage: %(script)s <package name> [test options] or: %(script)s --help """ % {'script': sys.argv[0] or 'runtests'} if argv is None: argv = sys.argv[1:] if not argv: print "Please specify a package name." print USAGE sys.exit(1) pkg_name, argv = argv[0], argv[1:] test_pkg_name = 'test.%s' % pkg_name # Find our real_dist = [i for i in working_set if i.project_name == pkg_name] if not real_dist: print "Package %s is not installed" % pkg_name sys.exit(1) real_dist = real_dist[0] test_dist = [i for i in working_set if i.project_name == test_pkg_name] if not test_dist: print "Test package %s is not installed" % test_pkg_name sys.exit(1) test_dist = test_dist[0] # Construct a distutils.Distribtion class from the pkg_resources.Distribution # of the real package so we can pass it into the test command class. # We have checked that the packages are already installed so we set the install # requirements to blank. args = {'name': real_dist.project_name, 'install_requires': [], 'tests_require': [], 'namespace_packages': list(real_dist._get_metadata('namespace_packages')), 'packages': [real_dist.project_name], } real_cmd_dist = Distribution(args) cmd = test(real_cmd_dist) cmd.args = argv # Read in the test options saved away during egg_info and set the command defaults, # this would normally be done by the setup() method via the Distribution class test_options = path(test_dist.location) / 'EGG-INFO' / 'test_options.txt' if test_options.isfile(): real_cmd_dist.parse_config_files([test_options]) for k, v in real_cmd_dist.get_option_dict('test').items(): print "Found test option in %s: %s = %s" % (v[0], k, v[1]) setattr(cmd, k, v[1]) # Finalize and run the command, overriding the test root to be inside the test egg cmd.finalize_options() cmd.test_root = path(test_dist.location) / CONFIG.test_egg_namespace / \ real_dist.project_name.replace('.', '/') # Pylint is only for regular Jenkins jobs, this in itself should not trigger even if # running under Jenkins cmd.no_pylint = True cmd.run()