Skip to content

Commit

Permalink
Merge pull request #72 from nschloe/cleanplotlib
Browse files Browse the repository at this point in the history
Cleanplotlib
  • Loading branch information
nschloe authored Apr 29, 2020
2 parents ec3fef4 + 348c6ca commit 58fe95b
Show file tree
Hide file tree
Showing 11 changed files with 773 additions and 132 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/test.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@ jobs:
- uses: actions/setup-python@v1
with:
python-version: "3.x"
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Lint with flake8
run: |
pip install --upgrade pip
pip install flake8
flake8 .
- name: Lint with black
Expand All @@ -22,20 +21,22 @@ jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8]
steps:
- uses: actions/setup-python@v1
with:
python-version: "3.x"
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Install dependencies
run: sudo apt-get install -y stress
- name: Install package
run: |
pip install --upgrade pip
pip install .[all]
pip install .
- name: Test with pytest
run: |
pip install pytest pytest-cov
cd test/ && MPLBACKEND=Agg pytest --cov stressberry
- name: Submit to codecov
run: bash <(curl -s https://codecov.io/bash)
# - name: Submit to codecov
# run: bash <(curl -s https://codecov.io/bash)
695 changes: 674 additions & 21 deletions LICENSE

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
VERSION=$(shell python3 -c "import stressberry; print(stressberry.__version__)")
VERSION=$(shell python3 -c "from configparser import ConfigParser; p = ConfigParser(); p.read('setup.cfg'); print(p['metadata']['version'])")

default:
@echo "\"make publish\"?"

tag:
# Make sure we're on the master branch
@if [ "$(shell git rev-parse --abbrev-ref HEAD)" != "master" ]; then exit 1; fi
@echo "Tagging v$(VERSION)..."
git tag v$(VERSION)
git push --tags
curl -H "Authorization: token `cat $(HOME)/.github-access-token`" -d '{"tag_name": "$(VERSION)"}' https://api.github.com/repos/nschloe/stressberry/releases
# @echo "Tagging v$(VERSION)..."
# git tag v$(VERSION)
# git push --tags
curl -H "Authorization: token `cat $(HOME)/.github-access-token`" -d '{"tag_name": "v$(VERSION)"}' https://api.github.com/repos/nschloe/stressberry/releases

# https://packaging.python.org/distributing/#id72
upload: setup.py
@if [ "$(shell git rev-parse --abbrev-ref HEAD)" != "master" ]; then exit 1; fi
rm -f dist/*
python3 setup.py sdist
python3 setup.py bdist_wheel --universal
# python3 setup.py sdist bdist_wheel
# https://stackoverflow.com/a/58756491/353337
python3 -m pep517.build --source --binary .
twine upload dist/*

publish: tag upload
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ pytest
```

### License
stressberry is published under the [MIT license](https://en.wikipedia.org/wiki/MIT_License).
This software is published under the [GPLv3 license](https://www.gnu.org/licenses/gpl-3.0.en.html).
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["setuptools>=42", "wheel"]
build-backend = "setuptools.build_meta"
42 changes: 42 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[metadata]
name = stressberry
version = 0.3.0
author = Nico Schlömer
email = [email protected]
description = Stress tests for the Raspberry Pi
url = https://github.com/nschloe/stressberry
project_urls =
Code=https://github.com/nschloe/stressberry
Issues=https://github.com/nschloe/stressberry/issues
long_description = file: README.md
long_description_content_type = text/markdown
license = GPLv3
platforms = any
classifiers =
Development Status :: 4 - Beta
License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)
Operating System :: OS Independent
Programming Language :: Python
Programming Language :: Python :: 3
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Topic :: Utilities

[options]
packages = find:
# importlib_metadata can be removed when we support Python 3.8+ only
install_requires =
cleanplotlib
importlib_metadata
matplotlib
pyyaml
python_requires = >=3.6
setup_requires =
setuptools>=42
wheel

[options.entry_points]
console_scripts =
stressberry-run = stressberry.cli:run
stressberry-plot = stressberry.cli:plot
40 changes: 0 additions & 40 deletions setup.py

This file was deleted.

17 changes: 10 additions & 7 deletions stressberry/__about__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
__author__ = "Nico Schlömer"
__email__ = "[email protected]"
__copyright__ = f"Copyright (c) 2017-2020, {__author__} <{__email__}>"
__license__ = "License :: OSI Approved :: MIT License"
__version__ = "0.2.3"
__maintainer__ = "Nico Schlömer"
__status__ = "Development Status :: 4 - Beta"
try:
# Python 3.8
from importlib import metadata
except ImportError:
import importlib_metadata as metadata

try:
__version__ = metadata.version("stressberry")
except Exception:
__version__ = "unknown"
20 changes: 2 additions & 18 deletions stressberry/__init__.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
from . import cli
from .__about__ import (
__author__,
__copyright__,
__email__,
__license__,
__status__,
__version__,
)
from .__about__ import __version__
from .main import stress_cpu

__all__ = [
"__author__",
"__email__",
"__copyright__",
"__license__",
"__version__",
"__status__",
"cli",
"stress_cpu",
]
__all__ = ["__version__", "cli", "stress_cpu"]
4 changes: 2 additions & 2 deletions stressberry/cli/helpers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import sys

from ..__about__ import __copyright__, __version__
from ..__about__ import __version__


def _get_version_text():
Expand All @@ -12,6 +12,6 @@ def _get_version_text():
sys.version_info.minor,
sys.version_info.micro,
),
__copyright__,
"Copyright (c) 2017-2020 Nico Schlömer <[email protected]>",
]
)
52 changes: 23 additions & 29 deletions stressberry/cli/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,41 +6,40 @@


def plot(argv=None):
import cleanplotlib as cpl
import matplotlib.pyplot as plt

parser = _get_parser_plot()
args = parser.parse_args(argv)

data = [yaml.load(f, Loader=yaml.SafeLoader) for f in args.infiles]

# sort the data such that the data series with the lowest terminal
# temperature is plotted last (and appears in the legend last)
terminal_temps = [d["temperature"][-1] for d in data]
order = [i[0] for i in sorted(enumerate(terminal_temps), key=lambda x: x[1])]
# actually plot it
fig = plt.figure()
ax1 = fig.add_subplot(1, 1, 1)
for k in order[::-1]:
temperature_data = data[k]["temperature"]
a = []
b = []
c = []
for d in data:
temperature_data = d["temperature"]
if args.delta_t:
temperature_data = []
zip_object = zip(data[k]["temperature"], data[k]["ambient"])
for data[k]["temperature"], data[k]["ambient"] in zip_object:
temperature_data.append(data[k]["temperature"] - data[k]["ambient"])
ax1.plot(
data[k]["time"], temperature_data, label=data[k]["name"], lw=args.line_width
)
zip_object = zip(d["temperature"], d["ambient"])
for d["temperature"], d["ambient"] in zip_object:
temperature_data.append(d["temperature"] - d["ambient"])
a.append(d["time"])
b.append(temperature_data)
c.append(d["name"])

cpl.multiplot(a, b, c)

ax1.grid()
if not args.hide_legend:
ax1.legend(loc="upper left", bbox_to_anchor=(1.03, 1.0), borderaxespad=0)
if args.delta_t:
plot_yaxis_label = "Δ temperature °C (over ambient)"
plot_yaxis_label = "Δ temperature [°C over ambient]"
else:
plot_yaxis_label = "temperature °C"
ax1.set_xlabel("time (s)")
ax1.set_ylabel(plot_yaxis_label)
ax1.set_xlim([data[-1]["time"][0], data[-1]["time"][-1]])
plot_yaxis_label = "temperature [°C]"
cpl.xlabel("time [s]")
cpl.ylabel(plot_yaxis_label)

if args.temp_lims:
ax1.set_ylim(*args.temp_lims)

Expand All @@ -51,14 +50,13 @@ def plot(argv=None):
if args.freq_lims:
ax2.set_ylim(*args.freq_lims)
try:
for k in order[::-1]:
for d in data:
ax2.plot(
data[k]["time"],
data[k]["cpu frequency"],
label=data[k]["name"],
d["time"],
d["cpu frequency"],
label=d["name"],
color="C1",
alpha=0.9,
lw=args.line_width,
)
ax1.set_zorder(ax2.get_zorder() + 1) # put ax1 plot in front of ax2
ax1.patch.set_visible(False) # hide the 'canvas'
Expand Down Expand Up @@ -125,17 +123,13 @@ def _get_parser_plot():
default=None,
help="limits for the frequency scale (default: data limits)",
)
parser.add_argument("--hide-legend", help="do not draw legend", action="store_true")
parser.add_argument(
"--not-transparent",
dest="transparent",
help="do not make images transparent",
action="store_false",
default=True,
)
parser.add_argument(
"-lw", "--line-width", type=float, default=None, help="line width"
)
parser.add_argument(
"--delta-t",
action="store_true",
Expand Down

0 comments on commit 58fe95b

Please sign in to comment.