Foxboron / ClojureDoc-Search

Sublime Text Plugin to browse clojuredocs
2 stars 2 forks source link

Sublime Text 3 compatibility #3

Closed trevor closed 11 years ago

trevor commented 11 years ago

SB3 uses python 3 exclusively, may want to put in python 2 vs 3 conditionals:

reloading plugin ClojureDocSearch.clsdocs
Traceback (most recent call last):
  File "/Applications/Sublime Text.app/Contents/MacOS/sublime_plugin.py", line 73, in reload_plugin
    m = importlib.import_module(modulename)
  File "X/importlib/__init__.py", line 88, in import_module
  File "<frozen importlib._bootstrap>", line 1577, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1558, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1525, in _find_and_load_unlocked
  File "/Users/username/Library/Application Support/Sublime Text 3/Installed Packages/ClojureDocSearch.sublime-package/clsdocs.py", line 35, in <module>
ImportError: No module named 'urllib2'
Foxboron commented 11 years ago

Yes, i haven't came around updating this for ST3. I know wbond have made some changes for the .json file so you can tell what suits which version.

I'll go ahead and port it when i am done with exams, have to prioritize. I will tho try too add the .json file! :)

trevor commented 11 years ago

hi @Foxboron - I agree with your prioritization strategy, good luck with finals!

Foxboron commented 11 years ago

Woohooo! Approval!

FichteFoll commented 11 years ago

I recommend writing conditionals to support both versions instead of maintaining two branches. This is way easier for a small plugin like this.

Foxboron commented 11 years ago

I agree with @FichteFoll HOWEVER! bs4 is not fucking compitable with the python3 Sublime uses.

class NamespacedAttribute(unicode):

    def __new__(cls, prefix, name, namespace=None):
        if name is None:
            obj = unicode.__new__(cls, prefix)
        elif prefix is None:
            # Not really namespaced.
            obj = unicode.__new__(cls, name)
        else:
            obj = unicode.__new__(cls, prefix + ":" + name)
        obj.prefix = prefix
        obj.name = name
        obj.namespace = namespace
        return obj

Inherit unicode in python3, yay. How the fuck do i even solve this? Atm i am fixing the import so its works with ST2 and ST3, but i am still baffeled with this code.

and that is not the only code. Looking at several lines reading: unicode.__new__(cls, original_value)

FichteFoll commented 11 years ago
if sys.version_info >= (3,):
    unicode = str

or similarly. I do that regularly with basestring = str when I need to check if a parameter is a string using isinstance().

Foxboron commented 11 years ago

Pushing a experimental build too the branch python3. I wont promis it works at this very moment.

Foxboron commented 11 years ago

Now i have fixed everything, i hope. Please give feedback if there re any errors!