Skip to content

Commit f61facc

Browse files
committed
1 parent 185c53f commit f61facc

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

web/pandas_web.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
import sys
3737
import time
3838
import typing
39+
from packaging import version
40+
from itertools import groupby
3941

4042
import feedparser
4143
import jinja2
@@ -223,9 +225,20 @@ def home_add_releases(context):
223225
with open(pathlib.Path(context["target_path"]) / "releases.json", "w") as f:
224226
json.dump(releases, f, default=datetime.datetime.isoformat)
225227

226-
for release in releases:
228+
non_obsolete_releases = []
229+
230+
# This is necessary for the versions to be properly grouped
231+
releases = sorted(releases, key=lambda release:version.parse(release["tag_name"]), reverse=True)
232+
233+
for _, group in groupby(releases, key=lambda release:
234+
((version.parse(release["tag_name"]).major), version.parse(release["tag_name"]).minor)):
235+
236+
non_obsolete_releases.append(max(group, key=lambda release: version.parse(release["tag_name"])))
237+
238+
for release in non_obsolete_releases:
227239
if release["prerelease"]:
228240
continue
241+
229242
published = datetime.datetime.strptime(
230243
release["published_at"], "%Y-%m-%dT%H:%M:%SZ"
231244
)

web/tests/test_pandas_web.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import yaml
2+
import os
3+
# Not working in code. the pandas directory is set up for this, but not the web directory
4+
from pandas_web import Preprocessors
5+
import pytest
6+
7+
@pytest.fixture # I think this is fine
8+
def test_home_releases_versions():
9+
context_path = os.path.join('pandas/config.yml')
10+
11+
# As it is, the home_add_releases function pull data from the github release page
12+
# with an http request. After I run the function, I print the data out.
13+
# In order to run custom data, you would need to modify the function in some way
14+
with open(context_path, 'r') as context_file:
15+
context = yaml.safe_load(context_file)
16+
17+
context["target_path"] = "build"
18+
19+
Preprocessors.home_add_releases(context)
20+
21+
for release in context["releases"]:
22+
print(release)

0 commit comments

Comments
 (0)