[yt-svn] commit/yt: MatthewTurk: Merged in xarthisius/yt (pull request #1899)

commits-noreply at bitbucket.org commits-noreply at bitbucket.org
Mon Dec 14 11:18:36 PST 2015


1 new commit in yt:

https://bitbucket.org/yt_analysis/yt/commits/e8f6316dad05/
Changeset:   e8f6316dad05
Branch:      yt
User:        MatthewTurk
Date:        2015-12-14 19:18:26+00:00
Summary:     Merged in xarthisius/yt (pull request #1899)

[bugfix] py3 compat
Affected #:  14 files

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/analysis_modules/halo_finding/halo_objects.py
--- a/yt/analysis_modules/halo_finding/halo_objects.py
+++ b/yt/analysis_modules/halo_finding/halo_objects.py
@@ -1344,7 +1344,8 @@
 
     def _retrieve_halos(self):
         # First get the halo particulars.
-        lines = file("%s.out" % self.basename)
+        with open("%s.out" % self.basename, 'r') as fh:
+            lines = fh.readlines()
         # The location of particle data for each halo.
         locations = self._collect_halo_data_locations()
         halo = 0
@@ -1395,7 +1396,8 @@
 
     def _collect_halo_data_locations(self):
         # The halos are listed in order in the file.
-        lines = file("%s.txt" % self.basename)
+        with open("%s.txt" % self.basename, 'r') as fh:
+            lines = fh.readlines()
         locations = []
         realpath = path.realpath("%s.txt" % self.basename)
         for line in lines:
@@ -1408,7 +1410,6 @@
                 item = item.split("/")
                 temp.append(path.join(path.dirname(realpath), item[-1]))
             locations.append(temp)
-        lines.close()
         return locations
 
 class TextHaloList(HaloList):
@@ -1422,7 +1423,8 @@
 
     def _retrieve_halos(self, fname, columns, comment):
         # First get the halo particulars.
-        lines = file(fname)
+        with open(fname, 'r') as fh:
+            lines = fh.readlines()
         halo = 0
         base_set = ['x', 'y', 'z', 'r']
         keys = columns.keys()

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/data_objects/construction_data_containers.py
--- a/yt/data_objects/construction_data_containers.py
+++ b/yt/data_objects/construction_data_containers.py
@@ -17,9 +17,11 @@
 import numpy as np
 from functools import wraps
 import fileinput
+import io
 from re import finditer
 from tempfile import TemporaryFile
 import os
+import sys
 import zipfile
 
 from yt.config import ytcfg
@@ -1272,14 +1274,13 @@
     def _color_samples_obj(self, cs, em, color_log, emit_log, color_map, arr,
                            color_field_max, color_field_min, color_field,
                            emit_field_max, emit_field_min, emit_field): # this now holds for obj files
-        from sys import version
         if color_field is not None:
             if color_log: cs = np.log10(cs)
         if emit_field is not None:
             if emit_log: em = np.log10(em)
         if color_field is not None:
             if color_field_min is None:
-                if version >= '3':
+                if sys.version_info > (3, ):
                     cs = [float(field) for field in cs]
                     cs = np.array(cs)
                 mi = cs.min()
@@ -1287,7 +1288,7 @@
                 mi = color_field_min
                 if color_log: mi = np.log10(mi)
             if color_field_max is None:
-                if version >= '3':
+                if sys.version_info > (3, ):
                     cs = [float(field) for field in cs]
                     cs = np.array(cs)
                 ma = cs.max()
@@ -1305,7 +1306,7 @@
         # now, get emission
         if emit_field is not None:
             if emit_field_min is None:
-                if version >= '3':
+                if sys.version_info > (3, ):
                     em = [float(field) for field in em]
                     em = np.array(em)
                 emi = em.min()
@@ -1313,7 +1314,7 @@
                 emi = emit_field_min
                 if emit_log: emi = np.log10(emi)
             if emit_field_max is None:
-                if version >= '3':
+                if sys.version_info > (3, ):
                     em = [float(field) for field in em]
                     em = np.array(em)
                 ema = em.max()
@@ -1333,15 +1334,9 @@
                     color_log = True, emit_log = True, plot_index = None,
                     color_field_max = None, color_field_min = None,
                     emit_field_max = None, emit_field_min = None):
-        from sys import version
-        from io import IOBase
         if plot_index is None:
             plot_index = 0
-        if version < '3':
-            checker = file
-        else:
-            checker = IOBase
-        if isinstance(filename, checker):
+        if isinstance(filename, io.IOBase):
             fobj = filename + '.obj'
             fmtl = filename + '.mtl'
         else:
@@ -1633,7 +1628,7 @@
     @parallel_root_only
     def _export_ply(self, filename, bounds = None, color_field = None,
                    color_map = "algae", color_log = True, sample_type = "face"):
-        if isinstance(filename, file):
+        if isinstance(filename, io.IOBase):
             f = filename
         else:
             f = open(filename, "wb")

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/data_objects/region_expression.py
--- a/yt/data_objects/region_expression.py
+++ b/yt/data_objects/region_expression.py
@@ -12,8 +12,8 @@
 #-----------------------------------------------------------------------------
 
 import weakref
-import types
 
+from yt.extern.six import string_types
 from yt.utilities.exceptions import YTDimensionalityError
 
 class RegionExpression(object):
@@ -31,11 +31,11 @@
         # At first, we will only implement this as accepting a slice that is
         # (optionally) unitful corresponding to a specific set of coordinates
         # that result in a rectangular prism or a slice.
-        if isinstance(item, types.StringTypes):
+        if isinstance(item, string_types):
             # This is some field; we will instead pass this back to the
             # all_data object.
             return self.all_data[item]
-        if isinstance(item, tuple) and isinstance(item[1], types.StringTypes):
+        if isinstance(item, tuple) and isinstance(item[1], string_types):
             return self.all_data[item]
         if len(item) != self.ds.dimensionality:
             # Not the right specification, and we don't want to do anything

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/data_objects/static_output.py
--- a/yt/data_objects/static_output.py
+++ b/yt/data_objects/static_output.py
@@ -1141,5 +1141,5 @@
     def _calculate_offsets(self, fields):
         pass
 
-    def __cmp__(self, other):
-        return cmp(self.filename, other.filename)
+    def __lt__(self, other):
+        return self.filename < other.filename

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/frontends/athena/data_structures.py
--- a/yt/frontends/athena/data_structures.py
+++ b/yt/frontends/athena/data_structures.py
@@ -152,10 +152,7 @@
         self.dataset_type = dataset_type
         # for now, the index file is the dataset!
         self.index_filename = os.path.join(os.getcwd(), self.dataset.filename)
-        if PY2:
-            self._fhandle = file(self.index_filename,'rb')
-        else:
-            self._fhandle = open(self.index_filename,'rb')
+        self._fhandle = open(self.index_filename,'rb')
         GridIndex.__init__(self, ds, dataset_type)
 
         self._fhandle.close()

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/frontends/gadget/simulation_handling.py
--- a/yt/frontends/gadget/simulation_handling.py
+++ b/yt/frontends/gadget/simulation_handling.py
@@ -375,7 +375,7 @@
         else:
             if self.parameters["OutputListOn"]:
                 a_values = [float(a) for a in 
-                           file(self.parameters["OutputListFilename"], "r").readlines()]
+                            open(self.parameters["OutputListFilename"], "r").readlines()]
             else:
                 a_values = [float(self.parameters["TimeOfFirstSnapshot"])]
                 time_max = float(self.parameters["TimeMax"])

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/frontends/owls_subfind/io.py
--- a/yt/frontends/owls_subfind/io.py
+++ b/yt/frontends/owls_subfind/io.py
@@ -42,7 +42,7 @@
         for chunk in chunks:
             for obj in chunk.objs:
                 data_files.update(obj.data_files)
-        for data_file in sorted(data_files):
+        for data_file in sorted(data_files, key=lambda f: f.filename):
             with h5py.File(data_file.filename, "r") as f:
                 for ptype, field_list in sorted(ptf.items()):
                     pcount = data_file.total_particles[ptype]
@@ -76,7 +76,7 @@
         for chunk in chunks:
             for obj in chunk.objs:
                 data_files.update(obj.data_files)
-        for data_file in sorted(data_files):
+        for data_file in sorted(data_files, key=lambda f: f.filename):
             with h5py.File(data_file.filename, "r") as f:
                 for ptype, field_list in sorted(ptf.items()):
                     pcount = data_file.total_particles[ptype]

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/frontends/tipsy/data_structures.py
--- a/yt/frontends/tipsy/data_structures.py
+++ b/yt/frontends/tipsy/data_structures.py
@@ -38,6 +38,10 @@
 from .fields import \
     TipsyFieldInfo
 
+import sys
+if sys.version_info > (3,):
+    long = int
+
 class TipsyFile(ParticleFile):
     def __init__(self, ds, io, filename, file_id):
         # To go above 1 domain, we need to include an indexing step in the

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/funcs.py
--- a/yt/funcs.py
+++ b/yt/funcs.py
@@ -16,6 +16,7 @@
 
 import errno
 from yt.extern.six import string_types
+from yt.extern.six.moves import input
 import time
 import inspect
 import traceback
@@ -586,7 +587,7 @@
         data = urllib.parse.urlencode(data)
     req = urllib.request.Request(uri, data)
     if use_pass:
-        username = raw_input("Bitbucket Username? ")
+        username = input("Bitbucket Username? ")
         password = getpass.getpass()
         upw = '%s:%s' % (username, password)
         req.add_header('Authorization', 'Basic %s' % base64.b64encode(upw).strip())
@@ -604,7 +605,7 @@
         print("*** is a delicate act, I require you to respond   ***")
         print("*** to the prompt with the word 'yes'.            ***")
         print()
-        response = raw_input("Do you want me to try to check it out? ")
+        response = input("Do you want me to try to check it out? ")
         if response != "yes":
             print()
             print("Okay, I understand.  You can check it out yourself.")

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/utilities/command_line.py
--- a/yt/utilities/command_line.py
+++ b/yt/utilities/command_line.py
@@ -38,7 +38,7 @@
     update_hg, \
     enable_plugins
 from yt.extern.six import add_metaclass, string_types
-from yt.extern.six.moves import urllib
+from yt.extern.six.moves import urllib, input
 from yt.convenience import load
 from yt.visualization.plot_window import \
     SlicePlot, \
@@ -325,7 +325,7 @@
     if not os.path.exists(date_file):
         print("Could not determine when yt stack was last updated.")
         return
-    print("".join(file(date_file, 'r').readlines()))
+    print("".join(open(date_file, 'r').readlines()))
     print("To update all dependencies, run \"yt update --all\".")
 
 def _update_yt_stack(path):
@@ -345,7 +345,7 @@
     print()
     print("[hit enter to continue or Ctrl-C to stop]")
     try:
-        raw_input()
+        input()
     except:
         sys.exit(0)
     os.environ["REINST_YT"] = "1"
@@ -381,7 +381,7 @@
         data = urllib.parse.urlencode(data)
     req = urllib.request.Request(uri, data)
     if use_pass:
-        username = raw_input("Bitbucket Username? ")
+        username = input("Bitbucket Username? ")
         password = getpass.getpass()
         upw = '%s:%s' % (username, password)
         req.add_header('Authorization', 'Basic %s' % base64.b64encode(upw).strip())
@@ -419,7 +419,7 @@
         print("   http://yt-project.org/irc.html")
         print("   http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org")
         print()
-        summary = raw_input("Press <enter> if you remain firm in your conviction to continue.")
+        summary = input("Press <enter> if you remain firm in your conviction to continue.")
         print()
         print()
         print("Okay, sorry about that. How about a nice, pithy ( < 12 words )")
@@ -430,7 +430,7 @@
             current_version = get_yt_version()
         except:
             current_version = "Unavailable"
-        summary = raw_input("Summary? ")
+        summary = input("Summary? ")
         bugtype = "bug"
         data = dict(title = summary, type=bugtype)
         print()
@@ -442,7 +442,7 @@
         if "EDITOR" in os.environ:
             print()
             print("Press enter to spawn your editor, %s" % os.environ["EDITOR"])
-            raw_input()
+            input()
             tf = tempfile.NamedTemporaryFile(delete=False)
             fn = tf.name
             tf.close()
@@ -463,7 +463,7 @@
             print()
             lines = []
             while 1:
-                line = raw_input()
+                line = input()
                 if line.strip() == "---": break
                 lines.append(line)
             content = "\n".join(lines)
@@ -487,7 +487,7 @@
         print("'submit'.  Next we'll ask for your Bitbucket Username.")
         print("If you don't have one, run the 'yt bootstrap_dev' command.")
         print()
-        raw_input()
+        input()
         retval = bb_apicall(endpoint, data, use_pass=True)
         import json
         retval = json.loads(retval)
@@ -528,17 +528,17 @@
         print()
         print("What username would you like to go by?")
         print()
-        username = raw_input("Username? ")
+        username = input("Username? ")
         if len(username) == 0: sys.exit(1)
         print()
         print("To start out, what's your name?")
         print()
-        name = raw_input("Name? ")
+        name = input("Name? ")
         if len(name) == 0: sys.exit(1)
         print()
         print("And your email address?")
         print()
-        email = raw_input("Email? ")
+        email = input("Email? ")
         if len(email) == 0: sys.exit(1)
         print()
         print("Please choose a password:")
@@ -554,12 +554,12 @@
         print("Would you like a URL displayed for your user?")
         print("Leave blank if no.")
         print()
-        url = raw_input("URL? ")
+        url = input("URL? ")
         print()
         print("Okay, press enter to register.  You should receive a welcome")
         print("message at %s when this is complete." % email)
         print()
-        raw_input()
+        input()
         data = dict(name = name, email = email, username = username,
                     password = password1, password2 = password2,
                     url = url, zap = "rowsdower")

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/utilities/poster/encode.py
--- a/yt/utilities/poster/encode.py
+++ b/yt/utilities/poster/encode.py
@@ -114,11 +114,11 @@
                 except:
                     raise ValueError("Could not determine filesize")
 
-    def __cmp__(self, other):
+    def __lt__(self, other):
         attrs = ['name', 'value', 'filename', 'filetype', 'filesize', 'fileobj']
         myattrs = [getattr(self, a) for a in attrs]
         oattrs = [getattr(other, a) for a in attrs]
-        return cmp(myattrs, oattrs)
+        return myattrs < oattrs
 
     def reset(self):
         if self.fileobj is not None:

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/utilities/pyparselibconfig/libconfig.py
--- a/yt/utilities/pyparselibconfig/libconfig.py
+++ b/yt/utilities/pyparselibconfig/libconfig.py
@@ -74,7 +74,7 @@
         return eval(v)
 
     def write(self, filename):
-        f = file(filename, 'w')
+        f = open(filename, 'w')
 
         self.write_dict(f, self, 0)
 

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/utilities/sdf.py
--- a/yt/utilities/sdf.py
+++ b/yt/utilities/sdf.py
@@ -292,7 +292,7 @@
             self.load_memmaps()
 
     def write(self, filename):
-        f = file(filename, 'w')
+        f = open(filename, 'w')
         f.write("# SDF 1.0\n")
         f.write("parameter byteorder = %s;\n" % (self.parameters['byteorder']))
         for c in self.comments:

diff -r 0447987365b19d53451bd04609832f070f7362b2 -r e8f6316dad05ec9850bc3e994e163bd484cadb69 yt/visualization/volume_rendering/camera.py
--- a/yt/visualization/volume_rendering/camera.py
+++ b/yt/visualization/volume_rendering/camera.py
@@ -520,7 +520,7 @@
         """
 
         dtheta = (1.0*theta)/n_steps
-        for i in xrange(n_steps):
+        for i in range(n_steps):
             self.rotate(dtheta, rot_vector=rot_vector, rot_center=rot_center)
             yield i
 
@@ -561,7 +561,7 @@
             dx = position_diff**(1.0/n_steps)
         else:
             dx = (final - self.position)*1.0/n_steps
-        for i in xrange(n_steps):
+        for i in range(n_steps):
             if exponential:
                 self.set_position(self.position * dx)
             else:
@@ -621,7 +621,7 @@
 
         """
         f = final**(1.0/n_steps)
-        for i in xrange(n_steps):
+        for i in range(n_steps):
             self.zoom(f)
             yield i

Repository URL: https://bitbucket.org/yt_analysis/yt/

--

This is a commit notification from bitbucket.org. You are receiving
this because you have the service enabled, addressing the recipient of
this email.



More information about the yt-svn mailing list