def evaluate_pep386(self): if not hasattr(self, "_evaluate_pep386"): normalized = verlib.suggest_normalized_version(self.version) evaluator = { "title": _("PEP386 Compatibility"), "message": jinja2.Markup(_("PEP386 defines a specific allowed syntax for Python package versions." "<br /><br />" "Previously it was impossible to accurately determine across any Python package what " "order the versions should go in, but with PEP386 we can now intelligently sort by version..." "<br /><br />" "But only if the version numbers are compatible!")) } if self.version == normalized: self._evaluate_pep386 = { "level": "success", "message": jinja2.Markup(_('Compatible with <a href="http://www.python.org/dev/peps/pep-0386/">PEP386</a>.')), "evaluator": evaluator, } elif normalized is not None: self._evaluate_pep386 = { "level": None, "message": jinja2.Markup(_('Almost Compatible with <a href="http://www.python.org/dev/peps/pep-0386/">PEP386</a>.')), "evaluator": evaluator, } else: self._evaluate_pep386 = { "level": "error", "message": jinja2.Markup(_('Incompatible with <a href="http://www.python.org/dev/peps/pep-0386/">PEP386</a>.')), "evaluator": evaluator, } return self._evaluate_pep386
def version_ordering(sender, **kwargs): instance = kwargs.get("instance") if instance is not None: releases = Release.objects.filter(package__pk=instance.package.pk) versions = [] dated = [] for release in releases: normalized = verlib.suggest_normalized_version(release.version) if normalized is not None: versions.append(release) else: dated.append(release) versions.sort(key=lambda x: verlib.NormalizedVersion(verlib.suggest_normalized_version(x.version))) dated.sort(key=lambda x: x.created) for i, release in enumerate(dated + versions): if release.order != i: Release.objects.filter(pk=release.pk).update(order=i)
def evaluate_pep386(self): if not hasattr(self, "_evaluate_pep386"): normalized = verlib.suggest_normalized_version(self.version) evaluator = { "title": _("PEP386 Compatibility"), "message": jinja2.Markup( _("PEP386 defines a specific allowed syntax for Python package versions." "<br /><br />" "Previously it was impossible to accurately determine across any Python package what " "order the versions should go in, but with PEP386 we can now intelligently sort by version..." "<br /><br />" "But only if the version numbers are compatible!")) } if self.version == normalized: self._evaluate_pep386 = { "level": "success", "message": jinja2.Markup( _('Compatible with <a href="http://www.python.org/dev/peps/pep-0386/">PEP386</a>.' )), "evaluator": evaluator, } elif normalized is not None: self._evaluate_pep386 = { "level": None, "message": jinja2.Markup( _('Almost Compatible with <a href="http://www.python.org/dev/peps/pep-0386/">PEP386</a>.' )), "evaluator": evaluator, } else: self._evaluate_pep386 = { "level": "error", "message": jinja2.Markup( _('Incompatible with <a href="http://www.python.org/dev/peps/pep-0386/">PEP386</a>.' )), "evaluator": evaluator, } return self._evaluate_pep386
def evaluate(self, release): normalized = verlib.suggest_normalized_version(release.version) if release.version == normalized: # Release Is Already Normalized return { "level": "success", "message": mark_safe('Compatible with <a href="http://www.python.org/dev/peps/pep-0386/">PEP386</a>.'), } elif normalized is not None: # Release Isn't Normalized, But We Can Figure It Out return { "level": None, "message": mark_safe('Almost Compatible with <a href="http://www.python.org/dev/peps/pep-0386/">PEP386</a>.'), } else: # We Can't Normalize the Release Version return { "level": "error", "message": mark_safe('Incompatible with <a href="http://www.python.org/dev/peps/pep-0386/">PEP386</a>.'), }