-
Notifications
You must be signed in to change notification settings - Fork 253
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
Python 2.6 Support #235
Comments
@Ahuge as long as it doesn't hamper future development and cause Python 3 issues (which I don't think it'll do), I don't see a problem with this. To me it looks like your code should work exactly as-is, so you could just set up a PR and we'll take it from there. |
As it happens, Here is the entire definition of
"""Backport of importlib.import_module from 3.x."""
# While not critical (and in no way guaranteed!), it would be nice to keep this
# code compatible with Python 2.3.
import sys
def _resolve_name(name, package, level):
"""Return the absolute name of the module to be imported."""
if not hasattr(package, 'rindex'):
raise ValueError("'package' not set to a string")
dot = len(package)
for x in xrange(level, 1, -1):
try:
dot = package.rindex('.', 0, dot)
except ValueError:
raise ValueError("attempted relative import beyond top-level "
"package")
return "%s.%s" % (package[:dot], name)
def import_module(name, package=None):
"""Import a module.
The 'package' argument is required when performing a relative import. It
specifies the package to use as the anchor point from which to resolve the
relative import to an absolute import.
"""
if name.startswith('.'):
if not package:
raise TypeError("relative imports require the 'package' argument")
level = 0
for character in name:
if character != '.':
break
level += 1
name = _resolve_name(name[level:], package, level)
__import__(name)
return sys.modules[name] Incidentally, it even mentioned compatibility with Python 2.3, so embedding this as-is into Qt.py and thus supporting Python 2.6 (and below?) shouldn't be a problem! |
#245 has been merged, I guess this can be closed now (although I'd recommend testing it on Travis). |
Hey all
I am slightly ignorant as to the benefits of importlib, looking at it's source it looks fairly basic, and much of it's complexity seems more than we need.
Python2.6 does not appear to have importlib and thus Qt.py cannot be used in anything below 2.7
Does anyone have any problem with me creating an implementation of how we are using importlib but only using import instead?
It would be something like this:
With a little bit of sanity checking in there.
Our studio is planning on updating to python2.7 soon, but that has been the plan for a while, so if you don't think you want to add this complexity to support 2.6 I understand.
Thanks
The text was updated successfully, but these errors were encountered: