Caoimhinmg / PmagPy

Python-based tools for Paleomagnetic research
scripps.ucsd.edu
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

backwards compatibility #3

Open moonshoes87 opened 7 years ago

moonshoes87 commented 7 years ago

Can we discuss the difficulties of backwards compatibility here? I wasn't sure from our conversations exactly how much of a possibility that is.

In trying to run some of this updated code with Python 2, some things work off the bat. The first substantial issue I ran into was with reading json:

  File "pmagpy/data_model3.py", line 47, in get_dm_offline
    raw = json.loads(string)
  File "/Applications/Canopy.app/appdata/canopy-1.7.4.3348.macosx-x86_64/Canopy\.app/Contents/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/Applications/Canopy.app/appdata/canopy-1.7.4.3348.macosx-x86_64/Canopy\.app/Contents/lib/python2.7/json/decoder.py", line 364, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Applications/Canopy.app/appdata/canopy-1.7.4.3348.macosx-x86_64/Canopy\.app/Contents/lib/python2.7/json/decoder.py", line 382, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Is it worth trying to work through some of these issues, or not?

Caoimhinmg commented 7 years ago

Yeah, this is one of the few no goes of backwards compatibility. It basically has to do with the kind of string encoding the json library expects which differs between python2 and 3 and has to do with the whole EVERYTHING UNICODE of python3. It also results in having these .decode and .encode methods of some objects which allow use of UTF-8 and other methods to switch between encodings, which just don't exist in python2 so if you use them there goes python2 compatibility. This proves to be a small nightmare I have solved this by just accepting that where we use the power of the json we must give up backwards compatibility with python2 as I just can't seem to get it to work both ways.

moonshoes87 commented 7 years ago

Right. So, for this not to be the nail in the coffin, we would have to have two separate data_model modules (or functions within the modules) that are Python version specific?

Caoimhinmg commented 7 years ago

As far as I can tell yes. I tried to hack my way around this for a while, but it just doesn't seem possible.