Skip to content
This repository has been archived by the owner on Jan 7, 2019. It is now read-only.

Python compatibility issues on current dev #338

Closed
Maju-Ketchup opened this issue Jan 26, 2018 · 6 comments
Closed

Python compatibility issues on current dev #338

Maju-Ketchup opened this issue Jan 26, 2018 · 6 comments

Comments

@Maju-Ketchup
Copy link
Contributor

Since the current dev is 'upgraded' to Python 3, working with Python 2 throws some errors because the 'ConfigParser' class was renamed to 'configparser'.
I have found a small work around to make it backwards compatible while changing one line in one file.

File: compatibility xpcc/scons/site_tools/configfile.py
old code(line 32):
import configparser
new code:

try:
       import configparser
except:
       import ConfigParser as configparser 

Should I commit this small to the current dev for backwards compatibility or should it stay the way it is so everyone should force update to Python 3?

@salkinium
Copy link
Member

@mhthies
Copy link
Contributor

mhthies commented Jan 28, 2018

In theory, the build system should work with both, Python 2 and 3 resp. SCons 2.5 and 3.0. I also tested both Python and SCons versions on my computer, before submitting the changes for Python 3 compatibility. That makes me wondering, why the configparser import breaks on your system …

@rleh
Copy link
Member

rleh commented Jan 28, 2018

In Python 3, ConfigParser has been renamed to configparser for PEP 8 compliance. [↗]

import configparser should fail on all Python 2 installations.
I can reproduce this with Python 2 on my Fedora system:

$ python2
Python 2.7.13 (default, Dec  1 2017, 09:21:53) 
[GCC 6.4.1 20170727 (Red Hat 6.4.1-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import configparser
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named configparser

@mhthies
Copy link
Contributor

mhthies commented Jan 28, 2018

That lets @Maju-Ketchup's fix seem reasonable to me.

We could discuss if it's more elegant to check for the Python version, instead of catching the import's exception. However, as far as I remember, catching exceptions is "The Pythonic Way"™.

@salkinium salkinium added this to the 2018q1 milestone Jan 28, 2018
@chris-durand
Copy link
Member

I also tested both Python and SCons versions on my computer, before submitting the changes for Python 3 compatibility. That makes me wondering, why the configparser import breaks on your system …

@mhthies You probably installed the python2 configparser backports package from pypi (https://pypi.python.org/pypi/configparser).

@rleh
Copy link
Member

rleh commented Jan 28, 2018

Python suggests the package six (Python 2 and 3 compatibility utilities), but this would add an additional dependency.
I like @Maju-Ketchup's solution too.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants