From b19cd881688330c55d4354ad8344d1876989f436 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Wed, 16 Dec 2020 12:04:16 +0100 Subject: [PATCH 1/6] update metadata --- Makefile | 2 +- setup.cfg | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index c5a715c..3dbd9f0 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ upload: rm -f dist/* # python3 setup.py sdist bdist_wheel # https://stackoverflow.com/a/58756491/353337 - python3 -m pep517.build --source --binary . + python3 -m build --sdist --wheel . twine upload dist/* publish: tag upload diff --git a/setup.cfg b/setup.cfg index e0b153f..8696610 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,7 +2,7 @@ name = stressberry version = 0.3.1 author = Nico Schlömer -email = nico.schloemer@gmail.com +author_email = nico.schloemer@gmail.com description = Stress tests for the Raspberry Pi url = https://github.com/nschloe/stressberry project_urls = @@ -10,8 +10,7 @@ project_urls = Issues=https://github.com/nschloe/stressberry/issues long_description = file: README.md long_description_content_type = text/markdown -license = GPLv3 -platforms = any +license = GPL-3.0-or-later classifiers = Development Status :: 4 - Beta License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+) @@ -21,6 +20,7 @@ classifiers = Programming Language :: Python :: 3.6 Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 + Programming Language :: Python :: 3.9 Topic :: Utilities [options] @@ -28,13 +28,10 @@ packages = find: # importlib_metadata can be removed when we support Python 3.8+ only install_requires = dufte - importlib_metadata + importlib_metadata;python_version<"3.8" matplotlib pyyaml python_requires = >=3.6 -setup_requires = - setuptools>=42 - wheel [options.entry_points] console_scripts = From 7f13f522c2befd09b0c0e3761cac5c7d2ea81d25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Wed, 16 Dec 2020 12:04:39 +0100 Subject: [PATCH 2/6] version bump --- setup.cfg | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 8696610..19d215a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = stressberry -version = 0.3.1 +version = 0.3.2 author = Nico Schlömer author_email = nico.schloemer@gmail.com description = Stress tests for the Raspberry Pi @@ -25,7 +25,6 @@ classifiers = [options] packages = find: -# importlib_metadata can be removed when we support Python 3.8+ only install_requires = dufte importlib_metadata;python_version<"3.8" From 073bb2a530fc935d0ddf61ae7668b8bac4d0eefc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Wed, 16 Dec 2020 12:04:50 +0100 Subject: [PATCH 3/6] pyupgrade --- stressberry/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stressberry/main.py b/stressberry/main.py index 88aae59..f407e20 100644 --- a/stressberry/main.py +++ b/stressberry/main.py @@ -30,7 +30,7 @@ def measure_temp(filename=None): """Returns the core temperature in Celsius. """ if filename is not None: - with open(filename, "r") as f: + with open(filename) as f: temp = float(f.read()) / 1000 else: # Using vcgencmd is specific to the raspberry pi @@ -43,7 +43,7 @@ def measure_core_frequency(filename=None): """Returns the CPU frequency in MHz """ if filename is not None: - with open(filename, "r") as f: + with open(filename) as f: frequency = float(f.read()) / 1000 else: # Only vcgencmd measure_clock arm is accurate on Raspberry Pi. From 1c5cc52e2a53b9db3e9de678ed3267a0dd673c41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Wed, 16 Dec 2020 12:06:57 +0100 Subject: [PATCH 4/6] format --- Makefile | 6 ++---- stressberry/cli/run.py | 6 ++++-- stressberry/main.py | 14 +++++--------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 3dbd9f0..9ecb1f6 100644 --- a/Makefile +++ b/Makefile @@ -26,11 +26,9 @@ clean: @rm -rf *.egg-info/ build/ dist/ format: - isort -rc . - black . - -black: + isort . black . + blacken-docs README.md lint: black --check . diff --git a/stressberry/cli/run.py b/stressberry/cli/run.py index e194a6d..a3a8eff 100644 --- a/stressberry/cli/run.py +++ b/stressberry/cli/run.py @@ -114,8 +114,10 @@ def run(argv=None): # If never had a good result, probably configuration error # Else use last known value if available or worst case set to zero if not ambient: - message = "Could not read ambient temperature sensor {} on pin {}".format( - args.ambient[0], args.ambient[1] + message = ( + "Could not read ambient temperature sensor {} on pin {}".format( + args.ambient[0], args.ambient[1] + ) ) else: message = "WARN - Could not read ambient temperature, using last good value" diff --git a/stressberry/main.py b/stressberry/main.py index f407e20..b65125e 100644 --- a/stressberry/main.py +++ b/stressberry/main.py @@ -9,8 +9,7 @@ def stress_cpu(num_cpus, time): def cooldown(interval=60, filename=None): - """Lets the CPU cool down until the temperature does not change anymore. - """ + """Lets the CPU cool down until the temperature does not change anymore.""" prev_tmp = measure_temp(filename=filename) while True: tme.sleep(interval) @@ -27,8 +26,7 @@ def cooldown(interval=60, filename=None): def measure_temp(filename=None): - """Returns the core temperature in Celsius. - """ + """Returns the core temperature in Celsius.""" if filename is not None: with open(filename) as f: temp = float(f.read()) / 1000 @@ -40,8 +38,7 @@ def measure_temp(filename=None): def measure_core_frequency(filename=None): - """Returns the CPU frequency in MHz - """ + """Returns the CPU frequency in MHz""" if filename is not None: with open(filename) as f: frequency = float(f.read()) / 1000 @@ -54,8 +51,7 @@ def measure_core_frequency(filename=None): def measure_ambient_temperature(sensor_type="2302", pin="23"): - """Uses Adafruit temperature sensor to measure ambient temperature - """ + """Uses Adafruit temperature sensor to measure ambient temperature""" try: import Adafruit_DHT # Late import so that library is only needed if requested except ImportError as e: @@ -83,7 +79,7 @@ def measure_ambient_temperature(sensor_type="2302", pin="23"): def test(stress_duration, idle_duration, cores): """Run stress test for specified duration with specified idle times - at the start and end of the test. + at the start and end of the test. """ if cores is None: cores = cpu_count() From 632586ef3aa82a43fe7db742b25a9e0a501c606e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Wed, 16 Dec 2020 12:09:29 +0100 Subject: [PATCH 5/6] some f-strings --- stressberry/cli/run.py | 1 - stressberry/main.py | 14 ++++---------- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/stressberry/cli/run.py b/stressberry/cli/run.py index a3a8eff..8e9b97c 100644 --- a/stressberry/cli/run.py +++ b/stressberry/cli/run.py @@ -161,4 +161,3 @@ def run(argv=None): }, args.outfile, ) - return diff --git a/stressberry/main.py b/stressberry/main.py index b65125e..31ae5e1 100644 --- a/stressberry/main.py +++ b/stressberry/main.py @@ -15,9 +15,8 @@ def cooldown(interval=60, filename=None): tme.sleep(interval) tmp = measure_temp(filename=filename) print( - "Current temperature: {:4.1f}°C - Previous temperature: {:4.1f}°C".format( - tmp, prev_tmp - ) + f"Current temperature: {tmp:4.1f}°C - " + f"Previous temperature: {prev_tmp:4.1f}°C" ) if abs(tmp - prev_tmp) < 0.2: break @@ -68,7 +67,7 @@ def measure_ambient_temperature(sensor_type="2302", pin="23"): except KeyError as e: print("Invalid ambient temperature sensor") raise e - humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) + _, temperature = Adafruit_DHT.read_retry(sensor, pin) # Note that sometimes you won't get a reading and the results will be null (because # Linux can't guarantee the timing of calls to read the sensor). The read_retry # call will attempt to read the sensor 15 times with a 2 second delay. Care should @@ -84,11 +83,7 @@ def test(stress_duration, idle_duration, cores): if cores is None: cores = cpu_count() - print( - "Preparing to stress [{}] CPU Cores for [{}] seconds".format( - cores, stress_duration - ) - ) + print(f"Preparing to stress [{cores}] CPU Cores for [{stress_duration}] seconds") print(f"Idling for {idle_duration} seconds...") tme.sleep(idle_duration) @@ -96,4 +91,3 @@ def test(stress_duration, idle_duration, cores): print(f"Idling for {idle_duration} seconds...") tme.sleep(idle_duration) - return From 4faa9f99611cf91545f332e11d6da28ff4849e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nico=20Schl=C3=B6mer?= Date: Wed, 16 Dec 2020 12:12:52 +0100 Subject: [PATCH 6/6] more f-strings --- stressberry/cli/run.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/stressberry/cli/run.py b/stressberry/cli/run.py index 8e9b97c..f7ba436 100644 --- a/stressberry/cli/run.py +++ b/stressberry/cli/run.py @@ -114,29 +114,29 @@ def run(argv=None): # If never had a good result, probably configuration error # Else use last known value if available or worst case set to zero if not ambient: - message = ( - "Could not read ambient temperature sensor {} on pin {}".format( - args.ambient[0], args.ambient[1] - ) + print( + f"Could not read ambient temperature sensor {args.ambient[0]} " + f"on pin {args.ambient[1]}" ) else: - message = "WARN - Could not read ambient temperature, using last good value" - print(message) + print( + "WARN - Could not read ambient temperature, " + "using last good value" + ) ambient_temperature = next( (temp for temp in reversed(ambient) if temp is not None), 0 ) ambient.append(ambient_temperature) delta_t = temps[-1] - ambient[-1] print( - "Temperature (current | ambient | ΔT): {:4.1f}°C | {:4.1f}°C | {:4.1f}°C - Frequency: {:4.0f}MHz".format( - temps[-1], ambient[-1], delta_t, freqs[-1] - ) + "Temperature (current | ambient | ΔT): " + f"{temps[-1]:4.1f}°C | {ambient[-1]:4.1f}°C | {delta_t:4.1f}°C " + f"- Frequency: {freqs[-1]:4.0f}MHz" ) else: print( - "Current temperature: {:4.1f}°C - Frequency: {:4.0f}MHz".format( - temps[-1], freqs[-1] - ) + f"Current temperature: {temps[-1]:4.1f}°C " + f"- Frequency: {freqs[-1]:4.0f}MHz" ) # Choose the sample interval such that we have a respectable number of # data points @@ -147,9 +147,8 @@ def run(argv=None): times = [tm - time0 for tm in times] args.outfile.write( - "# This file was created by stressberry v{} on {}\n".format( - __version__, datetime.datetime.now() - ) + f"# This file was created by stressberry v{__version__} " + f"on {datetime.datetime.now()}\n" ) yaml.dump( {