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

Remove python2 six functionality #1072

Merged
merged 5 commits into from
Mar 2, 2022
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
8 changes: 4 additions & 4 deletions asv/commands/preview.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

from six.moves import SimpleHTTPServer, socketserver

import socketserver
import http.server
import errno
import os
import random
Expand Down Expand Up @@ -84,9 +84,9 @@ def run_from_conf_args(cls, conf, args):
def run(cls, conf, port=0, browser=False):
os.chdir(conf.html_dir)

class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
class Handler(http.server.SimpleHTTPRequestHandler):
def translate_path(self, path):
path = SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(
path = http.server.SimpleHTTPRequestHandler.translate_path(
self, path)
return util.long_path(path)

Expand Down
10 changes: 4 additions & 6 deletions asv/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import os
import traceback
import math
from six.moves import xrange

from . import util
from . import step_detect

Expand Down Expand Up @@ -183,7 +181,7 @@ def mean_axis0(v):
if not v:
return [None] * self.n_series
return [mean_na(x[j] for x in v)
for j in xrange(self.n_series)]
for j in range(self.n_series)]

# Average data over commit log
val = []
Expand All @@ -196,14 +194,14 @@ def mean_axis0(v):

# Discard missing data at edges
i = 0
for i in xrange(len(val)):
for i in range(len(val)):
if any(not is_na(v) for v in val[i][1]):
break
else:
i = len(val)

j = i
for j in xrange(len(val) - 1, i, -1):
for j in range(len(val) - 1, i, -1):
if any(not is_na(v) for v in val[j][1]):
break

Expand Down Expand Up @@ -454,7 +452,7 @@ def resample_data(val, num_points=RESAMPLED_POINTS):

new_val = []
j = 0
for i in xrange(min_revision + step_size, max_revision + step_size, step_size):
for i in range(min_revision + step_size, max_revision + step_size, step_size):
chunk = []
while j < len(val) and val[j][0] < i:
chunk.append(val[j][1])
Expand Down
6 changes: 2 additions & 4 deletions asv/plugins/regressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import re
import itertools
import datetime

from six.moves.urllib.parse import urlencode

import urllib.parse
from ..results import iter_results
from ..console import log
from ..publishing import OutputPublisher
Expand Down Expand Up @@ -153,7 +151,7 @@ def _save_feed(cls, conf, benchmarks, data, revisions, revision_to_hash):
params['commits'] = '{0}-{1}'.format(revision_to_hash[rev1],
revision_to_hash[rev2])

link = 'index.html#{0}?{1}'.format(benchmark_name, urlencode(params))
link = 'index.html#{0}?{1}'.format(benchmark_name, urllib.parse.urlencode(params))

try:
best_percentage = "{0:.2f}%".format(100 * (last_value - best_value) / best_value)
Expand Down
4 changes: 1 addition & 3 deletions asv/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import itertools
import hashlib
import datetime
from six.moves import zip as izip

from . import environment
from .console import log
from .machine import Machine
Expand Down Expand Up @@ -169,7 +167,7 @@ def _compatible_results(result, result_params, params):
# Pick results for those parameters that also appear in the
# current benchmark
old_results = {}
for param, value in izip(itertools.product(*result_params), result):
for param, value in zip(itertools.product(*result_params), result):
old_results[param] = value

new_results = []
Expand Down
6 changes: 2 additions & 4 deletions asv/step_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,6 @@
import math
import collections
import heapq
import six

try:
from . import _rangemedian
except ImportError:
Expand Down Expand Up @@ -938,7 +936,7 @@ def rolling_median_dev(items):
try:
while True:
# Odd
v = six.next(s)
v = next(s)
min_heap_sum += v
v = -heapq.heappushpop(min_heap, -v)
min_heap_sum -= v
Expand All @@ -949,7 +947,7 @@ def rolling_median_dev(items):
yield (max_heap[0], d)

# Even
v = six.next(s)
v = next(s)
max_heap_sum += v
v = heapq.heappushpop(max_heap, v)
max_heap_sum -= v
Expand Down
10 changes: 3 additions & 7 deletions asv/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@
import operator
import collections
import multiprocessing

import six
from six.moves import xrange

from .extern import minify_json


Expand Down Expand Up @@ -250,7 +246,7 @@ def human_time(seconds, err=None):
# nan
return "n/a"

for i in xrange(len(units) - 1):
for i in range(len(units) - 1):
if scale < units[i + 1][1]:
str_time = human_float(seconds / units[i][1], 3, significant_zeros=True)
if err is None:
Expand Down Expand Up @@ -904,7 +900,7 @@ def update_json(cls, path, api_version, compact=False):
"No version specified in {0}.".format(path))

if d['version'] < api_version:
for x in six.moves.xrange(d['version'] + 1, api_version + 1):
for x in range(d['version'] + 1, api_version + 1):
d = getattr(cls, 'update_to_{0}'.format(x), lambda x: x)(d)
write_json(path, d, api_version, compact=compact)
elif d['version'] > api_version:
Expand Down Expand Up @@ -1192,7 +1188,7 @@ def _remove_readonly(func, path, exc_info):
pass

# Reraise original error
six.reraise(*exc_info)
raise

def long_path_open(filename, *a, **kw):
return open(long_path(filename), *a, **kw)
Expand Down
5 changes: 1 addition & 4 deletions test/test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
import datetime
import shutil
from os.path import join

import six

from asv import results, runner, util
import pytest
from .tools import example_results # noqa F401 needed to load fixtures (see #1030)
Expand All @@ -31,7 +28,7 @@ def test_results(tmpdir):
duration = 1.5

resultsdir = join(tmpdir, "results")
for i in six.moves.xrange(10):
for i in range(10):
r = results.Results(
{'machine': 'foo',
'arch': 'x86_64'},
Expand Down
8 changes: 4 additions & 4 deletions test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import contextlib
from os.path import join, abspath, dirname

from six.moves.urllib.parse import parse_qs, splitquery, splittag
import urllib.parse

import pytest
import asv
Expand Down Expand Up @@ -320,9 +320,9 @@ def test_web_summarylist(browser, basic_html):
assert m, cur_row2.text

# Check link
base_href, qs = splitquery(base_link.get_attribute('href'))
base_url, tag = splittag(base_href)
assert parse_qs(qs) == {'ram': ['128GB'], 'cpu': ['Blazingly fast'],
base_href, qs = urllib.parse.splitquery(base_link.get_attribute('href'))
base_url, tag = urllib.parse.splittag(base_href)
assert urllib.parse.parse_qs(qs) == {'ram': ['128GB'], 'cpu': ['Blazingly fast'],
'NUL': ['[none]']}
assert tag == 'params_examples.track_find_test'

Expand Down
3 changes: 1 addition & 2 deletions test/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import datetime
import json

import six
import pytest

from os.path import abspath, dirname, join, isfile, relpath
Expand Down Expand Up @@ -122,7 +121,7 @@ def test_run_publish(capfd, basic_conf):
with open(filename, 'r') as fp:
data = json.load(fp)
assert len(data) == 2
assert isinstance(data[0][0], six.integer_types) # revision
assert isinstance(data[0][0], int) # revision
assert len(data[0][1]) == 3
assert len(data[1][1]) == 3
assert isinstance(data[0][1][0], float)
Expand Down
13 changes: 6 additions & 7 deletions test/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@
import os
import threading
import time
import six
import tempfile
import textwrap
import sys
import shutil
import subprocess
import http.server

from os.path import abspath, join, dirname, relpath, isdir
from contextlib import contextmanager
from hashlib import sha256
from six.moves import SimpleHTTPServer
from filelock import FileLock


Expand Down Expand Up @@ -554,16 +553,16 @@ def ChromeHeadless():
return selenium.webdriver.Chrome(options=options)

ns = {}
six.exec_("import selenium.webdriver", ns)
six.exec_("from selenium.webdriver import *", ns)
exec("import selenium.webdriver", ns)
exec("from selenium.webdriver import *", ns)
ns['FirefoxHeadless'] = FirefoxHeadless
ns['ChromeHeadless'] = ChromeHeadless

create_driver = ns.get(driver_str, None)
if create_driver is None:
src = "def create_driver():\n"
src += textwrap.indent(driver_str, " ")
six.exec_(src, ns)
exec(src, ns)
create_driver = ns['create_driver']

# Create the browser
Expand Down Expand Up @@ -596,10 +595,10 @@ def preview(base_path):

"""

class Handler(SimpleHTTPServer.SimpleHTTPRequestHandler):
class Handler(http.server.SimpleHTTPRequestHandler):
def translate_path(self, path):
# Don't serve from cwd, but from a different directory
path = SimpleHTTPServer.SimpleHTTPRequestHandler.translate_path(self, path)
path = http.server.SimpleHTTPRequestHandler.translate_path(self, path)
path = os.path.join(base_path, os.path.relpath(path, os.getcwd()))
return util.long_path(path)

Expand Down