Skip to content

Commit

Permalink
Misc Python 2 removal cleanups
Browse files Browse the repository at this point in the history
* Fix flake8 warnings
* Fix tox command in setup.py
* Update requirements
  • Loading branch information
vstinner committed Mar 19, 2020
1 parent 89f2afd commit f2ed187
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 49 deletions.
21 changes: 0 additions & 21 deletions pyperformance/benchmarks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,27 +304,6 @@ def get_benchmarks():
return (bench_funcs, bench_groups)


def filter_benchmarks(benchmarks, bench_funcs, base_ver):
"""Filters out benchmarks not supported by both Pythons.
Args:
benchmarks: a set() of benchmark names
bench_funcs: dict mapping benchmark names to functions
python: the interpereter commands (as lists)
Returns:
The filtered set of benchmark names
"""
for bm in list(benchmarks):
func = bench_funcs[bm]
if getattr(func, '_python2_only', False) and (3, 0) <= base_ver:
benchmarks.discard(bm)
logging.info("Skipping Python2-only benchmark %s; "
"not compatible with Python %s" % (bm, base_ver))
continue
return benchmarks


def expand_benchmark_name(bm_name, bench_groups):
"""Recursively expand name benchmark names.
Expand Down
2 changes: 1 addition & 1 deletion pyperformance/benchmarks/bm_hg_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def get_hg_version(hg_bin):
# Fast-path: use directly the Python module
try:
from mercurial.__version__ import version
if sys.version_info >= (3,) and isinstance(version, bytes):
if isinstance(version, bytes):
return version.decode('utf8')
else:
return version
Expand Down
3 changes: 1 addition & 2 deletions pyperformance/benchmarks/bm_xml_etree.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def add_cmdline_args(cmd, args):
"Default is '%s'" % default_etmodule)
parser.add_argument("--no-accelerator", action="store_true", default=False,
help="Disable the '_elementree' accelerator module "
"for ElementTree in Python 3.3+.")
"for ElementTree.")
parser.add_argument("benchmark", nargs='?', choices=BENCHMARKS)

options = runner.parse_args()
Expand Down Expand Up @@ -270,7 +270,6 @@ def import_module(module_name):
if options.no_accelerator:
accelerator = False
else:
# Python 3.0-3.2 always use the accelerator
accelerator = True
if accelerator:
module += ' (with C accelerator)'
Expand Down
10 changes: 2 additions & 8 deletions pyperformance/cli_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,14 @@
import pyperf

import pyperformance
from pyperformance.benchmarks import (filter_benchmarks, get_benchmarks,
select_benchmarks)
from pyperformance.benchmarks import get_benchmarks, select_benchmarks
from pyperformance.compare import display_benchmark_suite
from pyperformance.run import run_benchmarks


def filter_benchmarks_python(benchmarks, bench_funcs):
return filter_benchmarks(benchmarks, bench_funcs, sys.version_info)


def get_benchmarks_to_run(options):
bench_funcs, bench_groups = get_benchmarks()
should_run = select_benchmarks(options.benchmarks, bench_groups)
should_run = filter_benchmarks_python(should_run, bench_funcs)
return (bench_funcs, bench_groups, should_run)


Expand Down Expand Up @@ -71,7 +65,7 @@ def cmd_list_groups(options):
bench_funcs, bench_groups = get_benchmarks()

funcs = set(bench_groups['all'])
all_funcs = filter_benchmarks_python(set(funcs), bench_funcs)
all_funcs = set(funcs)

for group, funcs in sorted(bench_groups.items()):
funcs = set(funcs) & all_funcs
Expand Down
2 changes: 1 addition & 1 deletion pyperformance/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ psutil==5.6.7
pyaes==1.6.1
pyperf==1.7.0
pytz==2019.3 # via django
six==1.14.0
six==1.14.0 # via html5lib, pyperf
sqlalchemy==1.3.13
sqlparse==0.3.0 # via django
sympy==1.5.1
Expand Down
18 changes: 3 additions & 15 deletions pyperformance/venv.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import errno
import os
import platform
import shutil
import subprocess
import sys
Expand Down Expand Up @@ -81,12 +80,7 @@ def safe_rmtree(path):


def python_implementation():
if hasattr(sys, 'implementation'):
# PEP 421, Python 3.3
name = sys.implementation.name
else:
name = platform.python_implementation()
return name.lower()
return sys.implementation.name.lower()


def get_venv_program(program):
Expand Down Expand Up @@ -213,22 +207,16 @@ def get_path(self):

script = textwrap.dedent("""
import hashlib
import platform
import sys
performance_version = sys.argv[1]
requirements = sys.argv[2]
data = performance_version + sys.executable + sys.version
pyver= sys.version_info
pyver = sys.version_info
if hasattr(sys, 'implementation'):
# PEP 421, Python 3.3
implementation = sys.implementation.name
else:
implementation = platform.python_implementation()
implementation = implementation.lower()
implementation = sys.implementation.name.lower()
if not isinstance(data, bytes):
data = data.encode('utf-8')
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# - maybe update version in pyperformance/__init__.py and doc/conf.py
# - set release date in doc/changelog.rst
# - git commit -a -m "prepare release x.y"
# - run tests: tox --parallel 0
# - run tests: tox --parallel auto
# - git push
# - check Travis CI status:
# https://travis-ci.org/python/pyperformance
Expand Down

0 comments on commit f2ed187

Please sign in to comment.