Skip to content

Added version sorting on Web and Removed obsolete versions #52887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
23 changes: 22 additions & 1 deletion web/pandas_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import feedparser
import jinja2
import markdown
from packaging import version
import requests
import yaml

Expand Down Expand Up @@ -231,7 +232,27 @@ def home_add_releases(context):
) as f:
json.dump(releases, f, default=datetime.datetime.isoformat)

for release in releases:
parsed_releases = [
(version.parse(release["tag_name"]), release) for release in releases
]

# The following filters out obsolete releases
# A version is obsolete if it's not the latest minor version.
# In the list ["1.4.0", "1.4.1", "1.4.2", "1.5.0", "1.5.1"], versions
# "1.4.0", "1.4.1", and "1.5.0" are obsolete,
# We don't need 1.5.0 as 1.5.1 has the same features with some bugs fixed

# Dummy version for filtering obsolete versions
prev_version = version.Version("0.0.0")

for v, release in sorted(parsed_releases, reverse=True):
# Example: If "1.5.3" is already added, we skip "1.5.2" and "1.5.1"
# Only the most up-to-date "1.5.x" release would be included due to sorting
if (v.major, v.minor) == (prev_version.major, prev_version.minor):
continue

prev_version = v

if release["prerelease"]:
continue
published = datetime.datetime.strptime(
Expand Down
1 change: 1 addition & 0 deletions web/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[tool.pytest.ini_options]
65 changes: 65 additions & 0 deletions web/tests/test_pandas_web.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from unittest.mock import (
MagicMock,
patch,
)

from web.pandas_web import Preprocessors


def test_home_add_releases():
# Prepare test data
releases = [
{
"tag_name": "v1.0.0",
"prerelease": False,
"published_at": "2021-04-01T00:00:00Z",
"assets": [{"browser_download_url": "https://example.com/download"}],
},
{
"tag_name": "v2.0.0",
"prerelease": False,
"published_at": "2022-01-01T00:00:00Z",
"assets": [{"browser_download_url": "https://example.com/download"}],
},
{
"tag_name": "v1.5.4",
"prerelease": False,
"published_at": "2023-08-01T00:00:00Z",
"assets": [],
},
{
"tag_name": "v1.5.3",
"prerelease": False,
"published_at": "2021-07-01T00:00:00Z",
"assets": [],
},
{
"tag_name": "v1.5.2",
"prerelease": False,
"published_at": "2021-06-01T00:00:00Z",
"assets": [],
},
]
github_repo_url = "pandas-dev/pandas"
context = {
"main": {
"github_repo_url": github_repo_url,
"production_url": "https://example.com/",
},
"target_path": "/tmp",
"releases": [],
}

# Mock the requests module to return the test data
resp = MagicMock()
resp.status_code = 200
resp.json.return_value = releases
with patch("requests.get", return_value=resp):
# Call the function being tested
Preprocessors.home_add_releases(context)

# Assert that releases were correctly added to the context
assert len(context["releases"]) == 3
assert context["releases"][0]["name"] == "2.0.0"
assert context["releases"][1]["name"] == "1.5.4"
assert context["releases"][2]["name"] == "1.0.0"