From 8440db746c3a25896323b0519ee7f2ab884e0fac Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sun, 8 Nov 2026 19:48:13 +0000 Subject: [PATCH] Drop support for Python 2 and clarify the fork and upstream distinction --- AUTHORS | 6 +++- CHANGELOG | 4 +++ README.md | 35 ++++++++++++---------- codespeed/admin.py | 2 -- codespeed/commits/exceptions.py | 3 -- codespeed/commits/github.py | 11 +------ codespeed/commits/logs.py | 3 -- codespeed/commits/mercurial.py | 3 -- codespeed/commits/subversion.py | 2 -- codespeed/models.py | 15 ++++------ codespeed/results.py | 3 -- codespeed/settings.py | 1 - codespeed/templatetags/percentages.py | 2 -- codespeed/tests/test_auth.py | 2 -- codespeed/tests/test_commits.py | 1 - codespeed/tests/test_models.py | 1 - codespeed/tests/test_views.py | 3 +- codespeed/tests/test_views_data.py | 1 - codespeed/urls.py | 1 - codespeed/views.py | 5 +--- codespeed/views_data.py | 3 -- sample_project/client.py | 10 +++---- sample_project/settings.py | 1 - setup.py | 16 +++++----- speed_pypy/settings.py | 1 - speed_pypy/urls.py | 2 -- speed_python/client.py | 8 ++--- speed_python/generate_secret.py | 2 -- speed_python/settings.py | 1 - speed_python/urls.py | 2 -- tools/create_trunks.py | 4 +-- tools/migrate_script.py | 2 +- tools/pypy/import_from_json.py | 1 - tools/pypy/savecpython.py | 13 +++++---- tools/pypy/saveresults.py | 17 ++++------- tools/pypy/test_saveresults.py | 1 - tools/save_multiple_results.py | 21 +++++++------- tools/save_single_result.py | 24 +++++++-------- tools/test_performance.py | 42 +++++++++++++-------------- 39 files changed, 112 insertions(+), 163 deletions(-) diff --git a/AUTHORS b/AUTHORS index 0a1845c9..9b10fb74 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,4 +1,4 @@ -Codespeed is written and maintained by Miquel Torres Barceló and various contributors: +Codespeed was written by Miquel Torres Barceló and various contributors: Frank Becker Chris Adams @@ -32,3 +32,7 @@ Codespeed is written and maintained by Miquel Torres Barceló and various contri Octavian Moraru Iskander (Alex) Sharipov Tim (Timmmm) + +This fork, which powers speed.python.org and speed.pypy.org, is developed +independently of tobami/codespeed at https://github.com/python/codespeed. +Its contributors are recorded in the Git history. diff --git a/CHANGELOG b/CHANGELOG index 661a6ca2..5b013d66 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ == Change Log == +This file records the releases of the original tobami/codespeed project and +ends with its last release, 0.13.0. The python/codespeed fork does not cut +releases, its changes since then are described by Git history. + === Version 0.13.0, February 23, 2019 === * NEW #263: Added support for Django 2.1, drop support for Django 1.8 * NEW #255: Allow partial requests of timeline grid diff --git a/README.md b/README.md index 42207aaa..5e037061 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,25 @@ # Codespeed [![Tests](https://github.com/python/codespeed/actions/workflows/test.yml/badge.svg?branch=main)](https://github.com/python/codespeed/actions/workflows/test.yml) -[![PyPI version](https://img.shields.io/pypi/v/codespeed.svg)](https://pypi.python.org/pypi/codespeed) Codespeed is a web application to monitor and analyze the performance of your code. -Known to be used by [CPython](https://speed.python.org), [PyPy](http://speed.pypy.org), [Twisted](http://speed.twistedmatrix.com) and others. +This started as a fork of [tobami/codespeed](https://github.com/tobami/codespeed), +however it is now developed independently here, and has different requirements. +The `codespeed` Django app is still generic and could possibly be used for other +projects. `speed_python` and `speed_pypy` hold what is specific to the two sites. -For an overview of some application concepts see the [wiki page](https://github.com/tobami/codespeed/wiki/Overview) +For an overview of some application concepts see the original project's +[wiki page](https://github.com/tobami/codespeed/wiki/Overview). ## Installation -You will need Python 2.7 or 3.5+. +You will need Python 3.10 or newer. -To install dependencies and the codespeed Django app: +Clone this repository and install the dependencies: - pip install codespeed + git clone https://github.com/python/codespeed.git + cd codespeed + pip install -r requirements.txt If you want version control integration, there are additional requirements: @@ -27,8 +32,6 @@ If you want version control integration, there are additional requirements: Codespeed will try to clone the repo, which depending on the size of the project can take a long time. Please be patient. -* Download the last stable release from - [github.com/tobami/codespeed/tags](https://github.com/tobami/codespeed/tags), unpack it and install it with `python setup.py install`. * To get started, you can use the `sample_project` directory as a starting point for your Django project, which can be normally configured by editing `sample_project/settings.py`. * For simplicity, you can use the default sqlite configuration, which will save the data to a database named `data.db` @@ -48,7 +51,6 @@ The codespeed installation can now be accessed by navigating to `http://localhos **Note**: for production, you should configure a real server like Apache or nginx (refer to the [Django docs](http://docs.djangoproject.com/en/dev/howto/deployment/)). You should also modify `sample_project/settings.py` and set `DEBUG = False`. -[`sample_project/README.md`](https://github.com/tobami/codespeed/tree/master/sample_project/README.md) also describes some production settings. ### Running the tests @@ -245,13 +247,14 @@ COMP_EXECUTABLES = [ which have low rate limits so an exception may be thrown when retrieving info from the Github API due to the rate limit being reached. -## Getting help +## Getting help and reporting bugs -For help regarding the configuration of Codespeed, or to share any ideas or -suggestions you may have, please post on Codespeed's [discussion -group](http://groups.google.com/group/codespeed) +Questions, suggestions and bug reports for this fork belong on the +[GitHub issue tracker](https://github.com/python/codespeed/issues). +The original project's Google group and issue tracker are no longer active. -## Reporting bugs +## History and license -If you find any bug in Codespeed please report it on the -[Github issue tracker](https://github.com/tobami/codespeed/issues) +Codespeed was written by Miquel Torres and contributors (see `AUTHORS`). It is +licensed under the GNU Lesser General Public License v2.1 (see `LICENSE`), this +fork keeps that license. diff --git a/codespeed/admin.py b/codespeed/admin.py index abf9d794..678cf3fd 100644 --- a/codespeed/admin.py +++ b/codespeed/admin.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import forms from django.contrib import admin diff --git a/codespeed/commits/exceptions.py b/codespeed/commits/exceptions.py index 7b27cc2f..d14d670e 100644 --- a/codespeed/commits/exceptions.py +++ b/codespeed/commits/exceptions.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - class CommitLogError(Exception): """An error when trying to display commit log messages""" diff --git a/codespeed/commits/github.py b/codespeed/commits/github.py index 42897230..4d9cc42a 100644 --- a/codespeed/commits/github.py +++ b/codespeed/commits/github.py @@ -1,21 +1,12 @@ -# encoding: utf-8 """ Specialized Git backend which uses Github.com for all of the heavy work Among other things, this means that the codespeed server doesn't need to have git installed, the ability to write files, etc. """ -from __future__ import absolute_import import logging -try: - # Python 3 - from urllib.request import urlopen - from urllib.request import Request -except ImportError: - # Python 2 - from urllib2 import urlopen - from urllib2 import Request +from urllib.request import Request, urlopen import re import json diff --git a/codespeed/commits/logs.py b/codespeed/commits/logs.py index 72c4390f..d5e3fb6d 100644 --- a/codespeed/commits/logs.py +++ b/codespeed/commits/logs.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import datetime import logging diff --git a/codespeed/commits/mercurial.py b/codespeed/commits/mercurial.py index 636af365..629d596c 100644 --- a/codespeed/commits/mercurial.py +++ b/codespeed/commits/mercurial.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import - import os import datetime from subprocess import Popen, PIPE diff --git a/codespeed/commits/subversion.py b/codespeed/commits/subversion.py index 2ace60fd..bacc8602 100644 --- a/codespeed/commits/subversion.py +++ b/codespeed/commits/subversion.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- """Subversion commit logs support""" -from __future__ import absolute_import from datetime import datetime diff --git a/codespeed/models.py b/codespeed/models.py index e835f1db..12a6f4aa 100644 --- a/codespeed/models.py +++ b/codespeed/models.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import logging import os import json @@ -77,10 +74,10 @@ def save(self, *args, **kwargs): m.group('username'), m.group('project') ) self.commit_browsing_url = url - super(Project, self).save(*args, **kwargs) + super().save(*args, **kwargs) -class HistoricalValue(object): +class HistoricalValue: def __init__(self, name=None, val=0, color='none'): self.name = name self.val = val @@ -241,7 +238,7 @@ class Result(models.Model): Environment, on_delete=models.CASCADE, related_name="results") def __str__(self): - return u"%s: %s" % (self.benchmark.name, self.value) + return "%s: %s" % (self.benchmark.name, self.value) class Meta: unique_together = ("revision", "executable", "benchmark", "environment") @@ -259,7 +256,7 @@ class Report(models.Model): _tablecache = models.TextField(blank=True) def __str__(self): - return u"Report for %s" % self.revision + return "Report for %s" % self.revision class Meta: unique_together = ("revision", "executable", "environment") @@ -270,7 +267,7 @@ def save(self, *args, **kwargs): changes = self.aggregate_significant_changes(tablelist) self.update_to_highest_priority_change(changes) - super(Report, self).save(*args, **kwargs) + super().save(*args, **kwargs) def update_to_highest_priority_change(self, changes): average_change = changes['average_change'] @@ -367,7 +364,7 @@ def updown(self, val): direction = val >= 0 and "up" or "down" aval = abs(val) if aval == float("inf"): - return u"%s ∞%%" % direction + return "%s ∞%%" % direction else: return "%s %.1f%%" % (direction, aval) diff --git a/codespeed/results.py b/codespeed/results.py index 21cc1a5a..be051b7a 100644 --- a/codespeed/results.py +++ b/codespeed/results.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import - import logging from datetime import datetime diff --git a/codespeed/settings.py b/codespeed/settings.py index bae836c8..3d6959a9 100644 --- a/codespeed/settings.py +++ b/codespeed/settings.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Default settings for Codespeed""" ## General default options ## diff --git a/codespeed/templatetags/percentages.py b/codespeed/templatetags/percentages.py index 33739432..1404ea9e 100644 --- a/codespeed/templatetags/percentages.py +++ b/codespeed/templatetags/percentages.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django import template register = template.Library() diff --git a/codespeed/tests/test_auth.py b/codespeed/tests/test_auth.py index bc2b356b..5d6e7828 100644 --- a/codespeed/tests/test_auth.py +++ b/codespeed/tests/test_auth.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from unittest import mock from django.test import TestCase, override_settings diff --git a/codespeed/tests/test_commits.py b/codespeed/tests/test_commits.py index 3bfc9304..9413db0b 100644 --- a/codespeed/tests/test_commits.py +++ b/codespeed/tests/test_commits.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from datetime import datetime, timedelta import shutil import subprocess diff --git a/codespeed/tests/test_models.py b/codespeed/tests/test_models.py index 1070d73a..0e573ec7 100644 --- a/codespeed/tests/test_models.py +++ b/codespeed/tests/test_models.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import json import os diff --git a/codespeed/tests/test_views.py b/codespeed/tests/test_views.py index 2983fc4d..e133af5c 100644 --- a/codespeed/tests/test_views.py +++ b/codespeed/tests/test_views.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from datetime import datetime, timedelta import copy import json @@ -465,7 +464,7 @@ def test_gettimelinedata(self): "There are 2 datapoints") self.assertEqual( responsedata['timelines'][0]['branches']['master']['1:1'][1], - [u'2011/04/13 17:04:22 +0000', 2000.0, 1.11111, u'2', u'', u'master', u'']) + ['2011/04/13 17:04:22 +0000', 2000.0, 1.11111, '2', '', 'master', '']) def test_no_source_fold_with_one_source(self): """A single source shows a flat benchmark list and no fold header""" diff --git a/codespeed/tests/test_views_data.py b/codespeed/tests/test_views_data.py index 66112bbb..52f5b571 100644 --- a/codespeed/tests/test_views_data.py +++ b/codespeed/tests/test_views_data.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.test import TestCase from django.test import override_settings diff --git a/codespeed/urls.py b/codespeed/urls.py index cd83233e..70bd0178 100644 --- a/codespeed/urls.py +++ b/codespeed/urls.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- from django.urls import re_path from codespeed import views diff --git a/codespeed/views.py b/codespeed/views.py index 02c081c8..c14a21ef 100644 --- a/codespeed/views.py +++ b/codespeed/views.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import, unicode_literals - import json import logging import os @@ -74,7 +71,7 @@ class HomeView(TemplateView): template_name = "home.html" def get_context_data(self, **kwargs): - context = super(HomeView, self).get_context_data(**kwargs) + context = super().get_context_data(**kwargs) context['show_reports'] = settings.SHOW_REPORTS context['show_historical'] = settings.SHOW_HISTORICAL historical_settings = ['SHOW_HISTORICAL', 'DEF_BASELINES', 'DEF_EXECUTABLES'] diff --git a/codespeed/views_data.py b/codespeed/views_data.py index 29c520cd..40a63394 100644 --- a/codespeed/views_data.py +++ b/codespeed/views_data.py @@ -1,6 +1,3 @@ -# -*- coding: utf-8 -*- -from __future__ import absolute_import - from django.conf import settings from django.core.exceptions import ObjectDoesNotExist from django.shortcuts import get_object_or_404 diff --git a/sample_project/client.py b/sample_project/client.py index 58c3e9ab..189955c6 100644 --- a/sample_project/client.py +++ b/sample_project/client.py @@ -1,10 +1,8 @@ -# encoding: utf-8 - -from urlparse import urljoin import logging import platform -import urllib import sys +from urllib.parse import urlencode, urljoin +from urllib.request import urlopen def save_to_speedcenter(url=None, project=None, commitid=None, executable=None, @@ -57,7 +55,7 @@ def save_to_speedcenter(url=None, project=None, commitid=None, executable=None, if not data.get('environment', None): data['environment'] = platform.platform(aliased=True) - f = urllib.urlopen(url, urllib.urlencode(data)) + f = urlopen(url, urlencode(data).encode('utf-8')) response = f.read() status = f.getcode() @@ -117,6 +115,6 @@ def save_to_speedcenter(url=None, project=None, commitid=None, executable=None, try: save_to_speedcenter(**kwargs) sys.exit(0) - except StandardError as e: + except Exception as e: logging.error("Error saving results: %s", e) sys.exit(1) diff --git a/sample_project/settings.py b/sample_project/settings.py index 929d5577..cad3c1c0 100644 --- a/sample_project/settings.py +++ b/sample_project/settings.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Django settings for a Codespeed project. import os diff --git a/setup.py b/setup.py index f1f03513..b63fd8dd 100644 --- a/setup.py +++ b/setup.py @@ -5,10 +5,11 @@ version='0.13.0', author='Miquel Torres', author_email='tobami@gmail.com', - url='https://github.com/tobami/codespeed', - download_url="https://github.com/tobami/codespeed/tags", + url='https://github.com/python/codespeed', + download_url='https://github.com/python/codespeed/tags', license='GNU Lesser General Public License version 2.1', keywords=['benchmarking', 'visualization'], + python_requires='>=3.10', install_requires=['django', 'isodate', 'matplotlib'], packages=find_packages(exclude=['ez_setup', 'sample_project', 'speed_python', 'speed_pypy']), long_description='README.md', @@ -23,12 +24,13 @@ 'License :: OSI Approved :: GNU Lesser General Public License v2 (LGPLv2)', 'Operating System :: OS Independent', 'Programming Language :: Python', - 'Programming Language :: Python :: 2', - 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', - 'Programming Language :: Python :: 3.6', + 'Programming Language :: Python :: 3 :: Only', + 'Programming Language :: Python :: 3.10', + 'Programming Language :: Python :: 3.11', + 'Programming Language :: Python :: 3.12', + 'Programming Language :: Python :: 3.13', + 'Programming Language :: Python :: 3.14', 'Topic :: Internet :: WWW/HTTP :: WSGI :: Application', ] ) diff --git a/speed_pypy/settings.py b/speed_pypy/settings.py index 6a94d0db..e427ae1a 100644 --- a/speed_pypy/settings.py +++ b/speed_pypy/settings.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Django settings for a Codespeed project. import os diff --git a/speed_pypy/urls.py b/speed_pypy/urls.py index 1b3554df..17346da0 100644 --- a/speed_pypy/urls.py +++ b/speed_pypy/urls.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - from django.conf import settings from django.urls import include, re_path from django.contrib import admin diff --git a/speed_python/client.py b/speed_python/client.py index 2a09f94b..1f89fd38 100644 --- a/speed_python/client.py +++ b/speed_python/client.py @@ -1,10 +1,8 @@ -# encoding: utf-8 - -from urlparse import urljoin import logging import platform -import urllib import sys +from urllib.parse import urlencode, urljoin +from urllib.request import urlopen def save_to_speedcenter(url=None, project=None, commitid=None, executable=None, @@ -57,7 +55,7 @@ def save_to_speedcenter(url=None, project=None, commitid=None, executable=None, if not data.get('environment', None): data['environment'] = platform.platform(aliased=True) - f = urllib.urlopen(url, urllib.urlencode(data)) + f = urlopen(url, urlencode(data).encode('utf-8')) response = f.read() status = f.getcode() diff --git a/speed_python/generate_secret.py b/speed_python/generate_secret.py index 5e2b53e7..3e639cfd 100755 --- a/speed_python/generate_secret.py +++ b/speed_python/generate_secret.py @@ -1,7 +1,5 @@ #!/usr/bin/env python -from __future__ import print_function - import os from django.utils.crypto import get_random_string diff --git a/speed_python/settings.py b/speed_python/settings.py index c4ceb46a..208b41d5 100644 --- a/speed_python/settings.py +++ b/speed_python/settings.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Django settings for a Codespeed project. import os diff --git a/speed_python/urls.py b/speed_python/urls.py index 3ed6418f..10af27f6 100644 --- a/speed_python/urls.py +++ b/speed_python/urls.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - import os.path from django.conf import settings diff --git a/tools/create_trunks.py b/tools/create_trunks.py index 5514e3b9..85d05c9a 100644 --- a/tools/create_trunks.py +++ b/tools/create_trunks.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ Create the default branch for all existing projects Starting v 0.8.0 that is mandatory. @@ -9,6 +8,7 @@ """ import sys import os +from functools import reduce ## Setup to import models from Django app ## @@ -49,7 +49,7 @@ def main(): if not proj.branches.filter(name='default'): trunk = Branch(name='default', project=proj) trunk.save() - print "Created branch 'default' for project {0}".format(proj) + print("Created branch 'default' for project {0}".format(proj)) if __name__ == '__main__': diff --git a/tools/migrate_script.py b/tools/migrate_script.py index e87379e9..32dca8e0 100644 --- a/tools/migrate_script.py +++ b/tools/migrate_script.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Adds the default branch to all existing revisions Note: This file is assumed to be in the same directory @@ -7,6 +6,7 @@ """ import sys import os +from functools import reduce ## Setup to import models from Django app ## diff --git a/tools/pypy/import_from_json.py b/tools/pypy/import_from_json.py index 0fe722cb..4a6f2e4c 100644 --- a/tools/pypy/import_from_json.py +++ b/tools/pypy/import_from_json.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ################################################################################ # This script imports PyPy's result data from json files located on the server # ################################################################################ diff --git a/tools/pypy/savecpython.py b/tools/pypy/savecpython.py index c15ce033..b561be8c 100644 --- a/tools/pypy/savecpython.py +++ b/tools/pypy/savecpython.py @@ -1,6 +1,7 @@ -# -*- coding: utf-8 -*- -import urllib, urllib2 from datetime import datetime +from urllib.error import URLError +from urllib.parse import urlencode +from urllib.request import urlopen SPEEDURL = 'http://127.0.0.1:8000/' #SPEEDURL = 'http://speed.pypy.org/' @@ -42,17 +43,17 @@ def save(project, revision, results, options, executable, host, testing=False): def send(data): #save results - params = urllib.urlencode(data) + params = urlencode(data).encode('utf-8') f = None response = "None" info = str(datetime.today()) + ": Saving result for " + data['executable'] + " revision " info += str(data['commitid']) + ", benchmark " + data['benchmark'] print(info) try: - f = urllib2.urlopen(SPEEDURL + 'result/add/', params) - response = f.read() + f = urlopen(SPEEDURL + 'result/add/', params) + response = f.read().decode() f.close() - except urllib2.URLError, e: + except URLError as e: if hasattr(e, 'reason'): response = '\n We failed to reach a server\n' response += ' Reason: ' + str(e.reason) diff --git a/tools/pypy/saveresults.py b/tools/pypy/saveresults.py index ddc000e5..f1726f50 100644 --- a/tools/pypy/saveresults.py +++ b/tools/pypy/saveresults.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- ####################################################### # This script saves result data # # It expects the format of unladen swallow's perf.py # @@ -19,18 +18,14 @@ $ ./saveresults.py result.json -r '45757:fabe4fc0dc08' -n pypy-c-jit-64 \ -H benchmarker """ -from __future__ import division, print_function from datetime import datetime import optparse import sys import time -try: - import urllib2 - from urllib import urlencode -except ImportError: - import urllib.request as urllib2 - from urllib.parse import urlencode +from urllib.error import URLError +from urllib.request import urlopen +from urllib.parse import urlencode import json import pprint @@ -116,19 +111,19 @@ def send(data, url): while True: try: print('result/add') - f = urllib2.urlopen(url + 'result/add/json/', params) + f = urlopen(url + 'result/add/json/', params) print('urlopen') response = f.read().decode() print('response') f.close() break - except urllib2.URLError: + except URLError: if not retries: raise d = retries.pop(0) print("retrying in %d seconds..." % d) time.sleep(d) - except urllib2.URLError as e: + except URLError as e: if hasattr(e, 'reason'): response = '\n We failed to save the data\n' response += ' Reason: ' + str(e.reason) diff --git a/tools/pypy/test_saveresults.py b/tools/pypy/test_saveresults.py index b84f3b28..94cf166e 100644 --- a/tools/pypy/test_saveresults.py +++ b/tools/pypy/test_saveresults.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- import saveresults import unittest diff --git a/tools/save_multiple_results.py b/tools/save_multiple_results.py index 82d340b7..e7b7eab4 100644 --- a/tools/save_multiple_results.py +++ b/tools/save_multiple_results.py @@ -1,10 +1,10 @@ -# -*- coding: utf-8 -*- #################################################### # Sample script that shows how to save result data using json # #################################################### -import urllib -import urllib2 import json +from urllib.error import HTTPError +from urllib.parse import urlencode +from urllib.request import urlopen # You need to enter the real URL and have the server running @@ -35,18 +35,17 @@ def add(data): - #params = urllib.urlencode(data) response = "None" try: - f = urllib2.urlopen( - CODESPEED_URL + 'result/add/json/', urllib.urlencode(data)) - except urllib2.HTTPError as e: - print str(e) - print e.read() + f = urlopen( + CODESPEED_URL + 'result/add/json/', urlencode(data).encode('utf-8')) + except HTTPError as e: + print(str(e)) + print(e.read().decode()) return - response = f.read() + response = f.read().decode() f.close() - print "Server (%s) response: %s\n" % (CODESPEED_URL, response) + print("Server (%s) response: %s\n" % (CODESPEED_URL, response)) if __name__ == "__main__": diff --git a/tools/save_single_result.py b/tools/save_single_result.py index 736cb77e..674b1ec1 100644 --- a/tools/save_single_result.py +++ b/tools/save_single_result.py @@ -1,10 +1,10 @@ -# -*- coding: utf-8 -*- #################################################### # Sample script that shows how to save result data # #################################################### from datetime import datetime -import urllib -import urllib2 +from urllib.error import HTTPError +from urllib.parse import urlencode +from urllib.request import urlopen # You need to enter the real URL and have the server running CODESPEED_URL = 'http://localhost:8000/' @@ -35,19 +35,19 @@ def add(data): - params = urllib.urlencode(data) + params = urlencode(data).encode('utf-8') response = "None" - print "Saving result for executable %s, revision %s, benchmark %s" % ( - data['executable'], data['commitid'], data['benchmark']) + print("Saving result for executable %s, revision %s, benchmark %s" % ( + data['executable'], data['commitid'], data['benchmark'])) try: - f = urllib2.urlopen(CODESPEED_URL + 'result/add/', params) - except urllib2.HTTPError as e: - print str(e) - print e.read() + f = urlopen(CODESPEED_URL + 'result/add/', params) + except HTTPError as e: + print(str(e)) + print(e.read().decode()) return - response = f.read() + response = f.read().decode() f.close() - print "Server (%s) response: %s\n" % (CODESPEED_URL, response) + print("Server (%s) response: %s\n" % (CODESPEED_URL, response)) if __name__ == "__main__": add(data) diff --git a/tools/test_performance.py b/tools/test_performance.py index 20408da4..b7731458 100644 --- a/tools/test_performance.py +++ b/tools/test_performance.py @@ -1,6 +1,7 @@ -import timeit -import urllib import sys +import timeit +from urllib.parse import urlencode +from urllib.request import urlopen SPEEDURL = 'http://localhost:8000/' @@ -16,12 +17,12 @@ def test_overview(): "executable": "1", "host": "bigdog", } - params = urllib.urlencode(data) - page = urllib.urlopen(SPEEDURL + 'overview/table/?' + params) - jsonstring = page.read() + params = urlencode(data) + page = urlopen(SPEEDURL + 'overview/table/?' + params) + jsonstring = page.read().decode() page.close() if not '' in jsonstring: - print "bad overview response" + print("bad overview response") sys.exit(1) @@ -33,30 +34,29 @@ def test_timeline(bench): "host": "bigdog", "revisions": 200 } - params = urllib.urlencode(data) - page = urllib.urlopen(SPEEDURL + 'timeline/json/?' + params) - jsonstring = page.read() - #print jsonstring + params = urlencode(data) + page = urlopen(SPEEDURL + 'timeline/json/?' + params) + jsonstring = page.read().decode() page.close() if not '"lessisbetter": " (less is better)", "baseline":' in jsonstring \ or not', "error": "None"}' in jsonstring: - print "bad timeline response" + print("bad timeline response") sys.exit(1) if __name__ == "__main__": t = timeit.Timer('test_overview()', 'from __main__ import test_overview') results = t.repeat(20, 1) - print - print "OVERVIEW RESULTS" - print "min:", min(results) - print "avg:", sum(results) / len(results) - print - print "TIMELINE RESULTS" + print() + print("OVERVIEW RESULTS") + print("min:", min(results)) + print("avg:", sum(results) / len(results)) + print() + print("TIMELINE RESULTS") for bench in benchmarks: t = timeit.Timer('test_timeline("' + bench + '")', 'from __main__ import test_timeline') results = t.repeat(20, 1) - print "benchmark =", bench - print "min:", min(results) - print "avg:", sum(results) / len(results) - print + print("benchmark =", bench) + print("min:", min(results)) + print("avg:", sum(results) / len(results)) + print()