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

Cleanup legacy python checks #2641

Merged
merged 1 commit into from
Jul 19, 2020
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
1 change: 0 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ omit=*.yml
yt/mods.py
yt/utilities/fits_image.py
yt/utilities/lodgeit.py
yt/utilities/lru_cache.py
yt/utilities/poster/*
yt/visualization/_mpl_imports.py

Expand Down
1 change: 0 additions & 1 deletion .pep8speaks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ pycodestyle:
- \*/__config__.py
- yt/visualization/_mpl_imports.py
- yt/utilities/lodgeit.py
- yt/utilities/lru_cache.py
- yt/utilities/poster/\*
- yt/extern/\*
- yt/mods.py
Expand Down
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ exclude = doc,
yt/visualization/_mpl_imports.py,
yt/utilities/fits_image.py,
yt/utilities/lodgeit.py,
yt/utilities/lru_cache.py,
yt/mods.py,
yt/visualization/_colormap_data.py,

Expand Down
21 changes: 8 additions & 13 deletions yt/data_objects/construction_data_containers.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import fileinput
import io
import os
import sys
import zipfile
from functools import wraps
from re import finditer
Expand Down Expand Up @@ -1878,18 +1877,16 @@ def _color_samples_obj(
em = np.log10(em)
if color_field is not None:
if color_field_min is None:
if sys.version_info > (3,):
cs = [float(field) for field in cs]
cs = np.array(cs)
cs = [float(field) for field in cs]
cs = np.array(cs)
mi = cs.min()
else:
mi = color_field_min
if color_log:
mi = np.log10(mi)
if color_field_max is None:
if sys.version_info > (3,):
cs = [float(field) for field in cs]
cs = np.array(cs)
cs = [float(field) for field in cs]
cs = np.array(cs)
ma = cs.max()
else:
ma = color_field_max
Expand All @@ -1907,18 +1904,16 @@ def _color_samples_obj(
# now, get emission
if emit_field is not None:
if emit_field_min is None:
if sys.version_info > (3,):
em = [float(field) for field in em]
em = np.array(em)
em = [float(field) for field in em]
em = np.array(em)
emi = em.min()
else:
emi = emit_field_min
if emit_log:
emi = np.log10(emi)
if emit_field_max is None:
if sys.version_info > (3,):
em = [float(field) for field in em]
em = np.array(em)
em = [float(field) for field in em]
em = np.array(em)
ema = em.max()
else:
ema = emit_field_max
Expand Down
8 changes: 2 additions & 6 deletions yt/fields/tests/test_fields_plugins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import sys
import unittest

import yt
Expand Down Expand Up @@ -75,12 +74,9 @@ def testCustomField(self):
plugin_file = os.path.join(CONFIG_DIR, ytcfg.get("yt", "pluginfilename"))
msg = "INFO:yt:Loading plugins from %s" % plugin_file

if sys.version_info >= (3, 4, 0):
with self.assertLogs("yt", level="INFO") as cm:
yt.enable_plugins()
self.assertEqual(cm.output, [msg])
else:
with self.assertLogs("yt", level="INFO") as cm:
yt.enable_plugins()
self.assertEqual(cm.output, [msg])

ds = fake_random_ds(16)
dd = ds.all_data()
Expand Down
8 changes: 2 additions & 6 deletions yt/frontends/exodus_ii/util.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
import re
import string
import sys
from collections import OrderedDict
from itertools import takewhile

import numpy as np

_printable = set([ord(_) for _ in string.printable])


def get_num_pseudo_dims(coords):
D = coords.shape[1]
return sum([np.all(coords[:, dim] == 0.0) for dim in range(D)])


def sanitize_string(s):
if sys.version_info > (3,):
return "".join([chr(_) for _ in takewhile(lambda a: a in _printable, s)])
return "".join([_ for _ in takewhile(lambda a: a in string.printable, s)])
_printable = set([ord(_) for _ in string.printable])
return "".join([chr(_) for _ in takewhile(lambda a: a in _printable, s)])


def load_info_records(info_records):
Expand Down
3 changes: 0 additions & 3 deletions yt/frontends/sdf/data_structures.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import contextlib
import os
import sys

import numpy as np

Expand All @@ -15,8 +14,6 @@

@contextlib.contextmanager
def safeopen(*args, **kwargs):
if sys.version[0] != "3":
kwargs.pop("encoding")
with open(*args, **kwargs) as f:
yield f

Expand Down
4 changes: 0 additions & 4 deletions yt/frontends/tipsy/data_structures.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import glob
import os
import struct
import sys

import numpy as np

Expand All @@ -14,9 +13,6 @@

from .fields import TipsyFieldInfo

if sys.version_info > (3,):
long = int


class TipsyFile(ParticleFile):
def __init__(self, ds, io, filename, file_id, range=None):
Expand Down
3 changes: 1 addition & 2 deletions yt/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import urllib.parse
import urllib.request
import warnings
from functools import wraps
from functools import lru_cache, wraps
from math import ceil, floor
from numbers import Number as numeric_type

Expand All @@ -29,7 +29,6 @@
from yt.units import YTArray, YTQuantity
from yt.utilities.exceptions import YTInvalidWidthError
from yt.utilities.logger import ytLogger as mylog
from yt.utilities.lru_cache import lru_cache

# Some functions for handling sequences and other types

Expand Down
4 changes: 2 additions & 2 deletions yt/utilities/io_handler.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import os
from collections import defaultdict
from contextlib import contextmanager
from functools import _make_key, lru_cache

import numpy as np

from yt.geometry.selection_routines import GridSelector
from yt.utilities.lru_cache import _make_key, local_lru_cache
from yt.utilities.on_demand_imports import _h5py as h5py

io_registry = {}
Expand All @@ -25,7 +25,7 @@ def __init__(cls, name, b, d):
if hasattr(cls, "_dataset_type"):
io_registry[cls._dataset_type] = cls
if use_caching and hasattr(cls, "_read_obj_field"):
cls._read_obj_field = local_lru_cache(
cls._read_obj_field = lru_cache(
maxsize=use_caching, typed=True, make_key=_make_io_key
)(cls._read_obj_field)

Expand Down
11 changes: 4 additions & 7 deletions yt/utilities/lodgeit.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
import sys
from optparse import OptionParser

if sys.version_info >= (3, 0, 0):
unicode = str

SCRIPT_NAME = os.path.basename(sys.argv[0])
VERSION = "0.3"
SERVICE_URL = "http://paste.yt-project.org/"
Expand Down Expand Up @@ -92,14 +89,14 @@ def load_default_settings():
def make_utf8(text, encoding):
"""Convert a text to UTF-8, brute-force."""
try:
u = unicode(text, "utf-8")
u = str(text, "utf-8")
uenc = "utf-8"
except UnicodeError:
try:
u = unicode(text, encoding)
u = str(text, encoding)
uenc = "utf-8"
except UnicodeError:
u = unicode(text, "iso-8859-15", "ignore")
u = str(text, "iso-8859-15", "ignore")
uenc = "iso-8859-15"
try:
import chardet
Expand All @@ -108,7 +105,7 @@ def make_utf8(text, encoding):
d = chardet.detect(text)
if d["encoding"] == uenc:
return u.encode("utf-8")
return unicode(text, d["encoding"], "ignore").encode("utf-8")
return str(text, d["encoding"], "ignore").encode("utf-8")


def get_xmlrpc_service():
Expand Down
Loading