def test_needs_to_downgrade(self): # Given reqs = [] # When/Then self.assertFalse(needs_to_downgrade_enstaller(reqs)) # Given reqs = [ Requirement.from_anything("numpy"), Requirement.from_anything("scipy") ] # When/Then self.assertFalse(needs_to_downgrade_enstaller(reqs)) # Given reqs = [ Requirement.from_anything("enstaller"), Requirement.from_anything("scipy") ] # When/Then self.assertFalse(needs_to_downgrade_enstaller(reqs)) # Given reqs = [Requirement.from_anything("enstaller 4.5.1")] # When/Then self.assertTrue(needs_to_downgrade_enstaller(reqs))
def test_needs_to_downgrade(self): # Given reqs = [] # When/Then self.assertFalse(needs_to_downgrade_enstaller(reqs)) # Given reqs = [Requirement.from_anything("numpy"), Requirement.from_anything("scipy")] # When/Then self.assertFalse(needs_to_downgrade_enstaller(reqs)) # Given reqs = [Requirement.from_anything("enstaller"), Requirement.from_anything("scipy")] # When/Then self.assertFalse(needs_to_downgrade_enstaller(reqs)) # Given reqs = [Requirement.from_anything("enstaller 4.5.1")] # When/Then self.assertTrue(needs_to_downgrade_enstaller(reqs))
def _compute_reqs(cnames): reqs = [] for arg in cnames: if '-' in arg: name, version = arg.split('-', 1) reqs.append(Requirement(name + ' ' + version)) else: reqs.append(Requirement(arg)) return reqs
def _compute_reqs(cnames): reqs = [] for arg in cnames: if len(arg) != 0: if '-' in arg: name, version = arg.split('-', 1) reqs.append( Requirement.from_legacy_requirement_string( name + ' ' + version ) ) else: reqs.append(Requirement.from_legacy_requirement_string(arg)) return reqs
def test_simple(self, install_req): # Given data = { "authentication": { "kind": "simple", "username": "******", "password": "******", }, "files_cache": self.prefix, "repositories": ["enthought/free", "enthought/commercial", "file://foo/bar"], "requirement": "numpy", "store_url": "https://acme.com", } # When with mock_stdin(json.dumps(data).encode("utf8")): install() # Then self.assertTrue(install_req.called) self.assertEqual( install_req.call_args[0][2], Requirement.from_legacy_requirement_string("numpy") )
def test_find_package_from_requirement_all(self): # Given requirement = Requirement.from_anything("nose 1.3.0-1") # When package = self.repository.find_package_from_requirement(requirement) # Then self.assertEqual(package.full_version, "1.3.0-1") # Given requirement = Requirement.from_anything("nose 1.2.1-1") # When package = self.repository.find_package_from_requirement(requirement) # Then self.assertEqual(package.full_version, "1.2.1-1")
def test_find_package_from_requirement_missing(self): # Given requirement_strings = ["fubar", "nose 1.3.1"] # When for requirement_string in requirement_strings: requirement = Requirement.from_anything(requirement_string) with self.assertRaises(NoSuchPackage): self.repository.find_package_from_requirement(requirement)
def test_find_package_from_requirement_name_and_version(self): # Given requirement = Requirement.from_legacy_requirement_string("nose 1.3.0") # When package = self.repository.find_package_from_requirement(requirement) # Then self.assertEqual(package.full_version, "1.3.0-2") # Given requirement = Requirement.from_legacy_requirement_string("nose 1.2.1") # When package = self.repository.find_package_from_requirement(requirement) # Then self.assertEqual(package.full_version, "1.2.1-1")
def needs_to_downgrade_enstaller(reqs): """ Returns True if the running enstaller would be downgraded by satisfying the list of requirements. """ for req in reqs: has_version_constraint = ( req != Requirement.from_legacy_requirement_string("enstaller") ) if req.name == "enstaller" and has_version_constraint: return True return False
def install_parse_json_string(json_string): json_data = json.loads(json_string) try: jsonschema.validate(json_data, INSTALL_SCHEMA) except jsonschema.ValidationError as e: msg = "Invalid configuration: {0!r}".format(e.message) raise EnstallerException(msg) config = _config_from_json_data(json_data) requirement_string = json_data[_REQUIREMENT] requirement = Requirement.from_legacy_requirement_string(requirement_string) return config, requirement
def query_platform(session, indices, requirement, platform): repository = repository_factory(session, indices) requirement = Requirement(requirement) resolve = Resolve(repository) def print_level(parent, level=0): level += 4 for r in resolve._dependencies_from_egg(parent): print("{0}{1}".format(level * " ", r)) egg = resolve._latest_egg(r) if egg is None: msg = "Error: Could not find egg for requirement {0!r}" print(msg.format(r)) sys.exit(-1) print_level(egg, level) root = resolve._latest_egg(requirement) if root is None: print("No egg found for requirement {0}".format(requirement)) else: print("Resolving dependencies for {0}: {1}".format(requirement, root)) print_level(root)
def install_req(enpkg, config, req, opts): """ Try to execute the install actions. """ # Unix exit-status codes FAILURE = 1 req = Requirement.from_anything(req) request = Request() request.install(req) def _done(exit_status): sys.exit(exit_status) def _get_unsupported_packages(actions): ret = [] for opcode, egg in actions: if opcode == "install": name, version = egg_name_to_name_version(egg) package = enpkg._remote_repository.find_package(name, version) if package.product == "pypi": ret.append(package) return ret def _ask_pypi_confirmation(package_list_string): msg = textwrap.dedent("""\ The following packages/requirements are coming from the PyPi repo: {0} The PyPi repository which contains >10,000 untested ("as is") packages. Some packages are licensed under GPL or other licenses which are prohibited for some users. Dependencies may not be provided. If you need an updated version or if the installation fails due to unmet dependencies, the Knowledge Base article Installing external packages into Canopy Python (https://support.enthought.com/entries/23389761) may help you with installing it. """.format(package_list_string)) print(msg) msg = "Are you sure that you wish to proceed? (y/[n])" if not prompt_yes_no(msg, opts.yes): sys.exit(0) def _ask_pypi_confirmation_from_actions(actions): unsupported_packages = _get_unsupported_packages(actions) if len(unsupported_packages) > 0: package_list = sorted("'{0}-{1}'".format(p.name, p.full_version) for p in unsupported_packages) package_list_string = "\n".join(package_list) _ask_pypi_confirmation(package_list_string) try: mode = 'root' if opts.no_deps else 'recur' pypi_asked = False solver = enpkg._solver_factory(mode, opts.force, opts.forceall) pypi_requirements = _requirement_from_pypi(request, enpkg._remote_repository) try: actions = solver.resolve(request) except MissingDependency as e: if len(pypi_requirements) > 0: msg = _BROKEN_PYPI_TEMPLATE.format(requested=e.requester, dependency=e.requirement) print(msg) else: print("One of the requested package has broken dependencies") print("(Dependency solving error: {0})".format(e)) _done(FAILURE) if len(pypi_requirements) > 0: package_list = sorted(str(p) for p in pypi_requirements) _ask_pypi_confirmation("\n".join(package_list)) pypi_asked = True installed = (egg for opcode, egg in actions if opcode == "install") actions = [("fetch", egg) for egg in installed] + actions if _is_any_package_unavailable(enpkg._remote_repository, actions): _notify_unavailable_package(config, req, enpkg._session) _done(FAILURE) if not pypi_asked: _ask_pypi_confirmation_from_actions(actions) enpkg.execute(actions) if len(actions) == 0: print("No update necessary, %r is up-to-date." % req.name) print(install_time_string(enpkg._installed_repository, req.name)) except NoPackageFound as e: print(str(e)) _done(FAILURE) except OSError as e: if e.errno == errno.EACCES and sys.platform == 'darwin': print("Install failed. OSX install requires admin privileges.") print("You should add 'sudo ' before the 'enpkg' command.") _done(FAILURE) else: raise
def dispatch_commands_with_enpkg(args, enpkg, config, prefix, session, parser, pat): if args.dry_run: def print_actions(actions): for item in actions: print('%-8s %s' % item) enpkg.execute = print_actions if args.imports: # --imports repository = Repository._from_prefixes(enpkg.prefixes) imports_option(repository) return if args.revert: # --revert revert(enpkg, args.revert) return # Try to auto-update enstaller if config.autoupdate: if update_enstaller(session, enpkg._remote_repository, args): print("Enstaller has been updated.\n" "Please re-run your previous command.") return if args.search: # --search search(enpkg._remote_repository, enpkg._installed_repository, config, session, pat) return if args.info: # --info if len(args.cnames) != 1: parser.error("Option requires one argument (name of package)") info_option(enpkg._remote_repository, enpkg._installed_repository, args.cnames[0]) return if args.whats_new: # --whats-new whats_new(enpkg._remote_repository, enpkg._installed_repository) return if args.update_all: # --update-all update_all(enpkg, config, args) return if args.requirements: install_from_requirements(enpkg, config, args) return if len(args.cnames) == 0 and not args.remove_enstaller: parser.error("Requirement(s) missing") elif len(args.cnames) == 2: pat = re.compile(r'\d+\.\d+') if pat.match(args.cnames[1]): args.cnames = ['-'.join(args.cnames)] reqs = _compute_reqs(args.cnames) # This code assumes we have already upgraded enstaller if needed if needs_to_downgrade_enstaller(reqs): msg = "Enstaller in requirement list: enstaller will be downgraded !" warnings.warn(msg) else: logger.debug("Enstaller is up to date, not updating") reqs = [req for req in reqs if req.name != "enstaller"] logger.info("Requirements:") for req in reqs: logger.info(' %r', req) logger.info("prefix: %r", prefix) REMOVE_ENSTALLER_WARNING = ("Removing enstaller package will break enpkg " "and is not recommended.") if args.remove: if any(req.name == 'enstaller' for req in reqs): print(REMOVE_ENSTALLER_WARNING) print("If you are sure you wish to remove enstaller, use:") print(" enpkg --remove-enstaller") return if args.remove_enstaller: print(REMOVE_ENSTALLER_WARNING) if prompt_yes_no("Really remove enstaller? (y/[n]) ", args.yes): args.remove = True reqs = [Requirement('enstaller')] if any(req.name == 'epd' for req in reqs): if args.remove: parser.error("Can't remove 'epd'") elif len(reqs) > 1: parser.error("Can't combine 'enpkg epd' with other packages.") elif not epd_install_confirm(args.yes): return if args.remove: for req in reqs: solver = enpkg._solver_factory() try: request = Request() request.remove(req) enpkg.execute(solver.resolve(request)) except EnpkgError as e: print(str(e)) else: for req in reqs: install_req(enpkg, config, req, args)