Skip to content
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

Updating to Python 3.12 and switching to use pip-tools #606

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.7
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: 3.7
python-version: 3.12
- uses: actions/cache@v3
name: Cache dependencies
with:
Expand All @@ -30,8 +30,8 @@ jobs:
./get_stats.sh
- name: Run tests
run: pytest --cov .
- name: Coveralls
run: coveralls --service=github-actions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
# - name: Coveralls
# run: coveralls --service=github-actions
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
20 changes: 7 additions & 13 deletions plots.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
#!/usr/bin/env python
""" Generates static images of stats graphs using matplotlib.
"""
Show how to make date plots in matplotlib using date tick locators and
formatters. See major_minor_demo1.py for more information on
controlling major and minor ticks

All matplotlib date plotting is done by converting date instances into
days since the 0001-01-01 UTC. The conversion, tick locating and
formatting is done behind the scenes so this is most transparent to
you. The dates module provides several converter functions date2num
and num2date

"""
import datetime
import numpy as np # noqa: F401
from collections import defaultdict
Expand Down Expand Up @@ -68,7 +59,7 @@ def make_plot(stat_path, git_stats, img_prefix=''):
if not stat_dict:
return
items = sorted(stat_dict.items())
x_values = [datetime.date(int(x[0:4]), int(x[5:7]), int(x[8:10])).toordinal() for x, y in items]
x_values = [datetime.date(int(x[0:4]), int(x[5:7]), int(x[8:10])) for x, y in items]
if type(stat_path) == tuple:
y_values = [dict((k, v) for k, v in y.items() if stat_path[1](k)) for x, y in items]
else:
Expand All @@ -92,10 +83,10 @@ def make_plot(stat_path, git_stats, img_prefix=''):
if stat_name in ['publisher_types', 'activities_per_publisher_type']:
# Sort by the most recent value for the key
sorted_items = sorted(plots.items(), key=lambda x: y_values[-1][x[0]], reverse=True)
fig_legend.legend([x[1] for x in sorted_items], [x[0] for x in sorted_items], 'center', ncol=1)
fig_legend.legend([x[1] for x in sorted_items], [x[0] for x in sorted_items], loc='center', ncol=1)
fig_legend.set_size_inches(600.0 / dpi, 300.0 / dpi)
else:
fig_legend.legend(plots.values(), plots.keys(), 'center', ncol=4)
fig_legend.legend(plots.values(), plots.keys(), loc='center', ncol=4)
fig_legend.set_size_inches(600.0 / dpi, 100.0 / dpi)
fig_legend.savefig('out/{0}{1}{2}_legend.png'.format(img_prefix, stat_name, stat_path[2]))
else:
Expand All @@ -122,6 +113,8 @@ def make_plot(stat_path, git_stats, img_prefix=''):
# axes up to make room for them
fig.autofmt_xdate()

ax.ticklabel_format(axis='y', style='plain', useOffset=False)

fig.savefig('out/{0}{1}{2}.png'.format(img_prefix, stat_name, stat_path[2] if type(stat_path) == tuple else ''), dpi=dpi)
plt.close('all')

Expand Down Expand Up @@ -168,6 +161,7 @@ def make_plot(stat_path, git_stats, img_prefix=''):
]:
make_plot(stat_path, git_stats)


# Delete git_stats variable to save memory
del git_stats

Expand Down
12 changes: 12 additions & 0 deletions requirements.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
flask==0.12.3
frozen-flask==0.15
jinja2==2.11.3
python-dateutil==2.8.1
pytz
matplotlib==3.9.0
werkzeug==0.16.1
xmlschema==1.6.2
lxml
requests
markupsafe==2.0.1
itsdangerous==2.0.1 # Pinned as >2.0.1 drops itsdangerous.json
82 changes: 72 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,74 @@
Flask==0.12.3
Frozen-Flask==0.15
Jinja2==2.11.3
lxml
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile requirements.in
#
certifi==2024.7.4
# via requests
charset-normalizer==3.3.2
# via requests
click==8.1.7
# via flask
contourpy==1.2.1
# via matplotlib
cycler==0.12.1
# via matplotlib
elementpath==2.5.3
# via xmlschema
flask==0.12.3
# via
# -r requirements.in
# frozen-flask
fonttools==4.53.1
# via matplotlib
frozen-flask==0.15
# via -r requirements.in
idna==3.7
# via requests
itsdangerous==2.0.1
# via
# -r requirements.in
# flask
jinja2==2.11.3
# via
# -r requirements.in
# flask
kiwisolver==1.4.5
# via matplotlib
lxml==5.2.2
# via -r requirements.in
markupsafe==2.0.1
# via
# -r requirements.in
# jinja2
matplotlib==3.9.0
# via -r requirements.in
numpy==2.0.0
# via
# contourpy
# matplotlib
packaging==24.1
# via matplotlib
pillow==10.4.0
# via matplotlib
pyparsing==3.1.2
# via matplotlib
python-dateutil==2.8.1
pytz
matplotlib==2.2.5
requests
Werkzeug==0.12.2
# via
# -r requirements.in
# matplotlib
pytz==2024.1
# via -r requirements.in
requests==2.32.3
# via -r requirements.in
six==1.16.0
# via python-dateutil
urllib3==2.2.2
# via requests
werkzeug==0.16.1
# via
# -r requirements.in
# flask
xmlschema==1.6.2
markupsafe==2.0.1
itsdangerous==2.0.1
# via -r requirements.in
5 changes: 5 additions & 0 deletions requirements_dev.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-r requirements.txt
pytest==8.2.2
pytest-cov==5.0.0
coveralls==4.0.1
flake8==3.7.7
137 changes: 133 additions & 4 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,134 @@
-r requirements.txt
pytest<6.1.0
pytest-cov==2.11.1
coveralls==3.0.1
#
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile requirements_dev.in
#
certifi==2024.7.4
# via
# -r requirements.txt
# requests
charset-normalizer==3.3.2
# via
# -r requirements.txt
# requests
click==8.1.7
# via
# -r requirements.txt
# flask
contourpy==1.2.1
# via
# -r requirements.txt
# matplotlib
coverage[toml]==7.5.4
# via
# coveralls
# pytest-cov
coveralls==4.0.1
# via -r requirements_dev.in
cycler==0.12.1
# via
# -r requirements.txt
# matplotlib
docopt==0.6.2
# via coveralls
elementpath==2.5.3
# via
# -r requirements.txt
# xmlschema
entrypoints==0.3
# via flake8
flake8==3.7.7
# via -r requirements_dev.in
flask==0.12.3
# via
# -r requirements.txt
# frozen-flask
fonttools==4.53.1
# via
# -r requirements.txt
# matplotlib
frozen-flask==0.15
# via -r requirements.txt
idna==3.7
# via
# -r requirements.txt
# requests
iniconfig==2.0.0
# via pytest
itsdangerous==2.0.1
# via
# -r requirements.txt
# flask
jinja2==2.11.3
# via
# -r requirements.txt
# flask
kiwisolver==1.4.5
# via
# -r requirements.txt
# matplotlib
lxml==5.2.2
# via -r requirements.txt
markupsafe==2.0.1
# via
# -r requirements.txt
# jinja2
matplotlib==3.9.0
# via -r requirements.txt
mccabe==0.6.1
# via flake8
numpy==2.0.0
# via
# -r requirements.txt
# contourpy
# matplotlib
packaging==24.1
# via
# -r requirements.txt
# matplotlib
# pytest
pillow==10.4.0
# via
# -r requirements.txt
# matplotlib
pluggy==1.5.0
# via pytest
pycodestyle==2.5.0
# via flake8
pyflakes==2.1.1
# via flake8
pyparsing==3.1.2
# via
# -r requirements.txt
# matplotlib
pytest==8.2.2
# via
# -r requirements_dev.in
# pytest-cov
pytest-cov==5.0.0
# via -r requirements_dev.in
python-dateutil==2.8.1
# via
# -r requirements.txt
# matplotlib
pytz==2024.1
# via -r requirements.txt
requests==2.32.3
# via
# -r requirements.txt
# coveralls
six==1.16.0
# via
# -r requirements.txt
# python-dateutil
urllib3==2.2.2
# via
# -r requirements.txt
# requests
werkzeug==0.16.1
# via
# -r requirements.txt
# flask
xmlschema==1.6.2
# via -r requirements.txt
33 changes: 33 additions & 0 deletions tests/test_timeliness.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Testing of functions in timeliness.py
"""

import sys
from os import path

sys.path.append(path.dirname(path.dirname(path.abspath(__file__))))

import timeliness # noqa: E402


def test_short_month():
month_strings = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
for index, s in enumerate(month_strings):
assert timeliness.short_month('01-{:02d}-2024'.format(index + 1)) == s


def test_parse_iso_date():
test_date_1 = timeliness.parse_iso_date("2024-01-01")
assert test_date_1.year == 2024
assert test_date_1.month == 1
assert test_date_1.day == 1

test_date_2 = timeliness.parse_iso_date("2024-02-29")
assert test_date_2.year == 2024
assert test_date_2.month == 2
assert test_date_2.day == 29

test_date_3 = timeliness.parse_iso_date("2024-04-01")
assert test_date_3.year == 2024
assert test_date_3.month == 4
assert test_date_3.day == 1
Loading