eerohele / exalt

A Sublime Text plugin for validating and formatting XML documents
MIT License
22 stars 3 forks source link

[Bug] TypeError: 'NoneType' object is not iterable #6

Closed Kristinita closed 7 years ago

Kristinita commented 7 years ago

1. Summary

I get stack trace in console, when I run Sublime Text.

2. Expected behavior

No stack trace in console.

3. Actual behavior

Stack trace 1:

reloading plugin Exalt.constants
reloading plugin Exalt.encodings
reloading plugin Exalt.exalt
reloading plugin Exalt.impl.plugin
Traceback (most recent call last):
  File "D:\Sublime Text Build 3126 x64 For Debug\sublime_plugin.py", line 157, in reload_plugin
    m.plugin_loaded()
  File "D:\Sublime Text Build 3126 x64 For Debug\Data\Packages\Exalt\exalt.py", line 84, in plugin_loaded
    sublime_plugin.reload_plugin("%s.impl.plugin" % constants.PLUGIN_NAME)
  File "D:\Sublime Text Build 3126 x64 For Debug\sublime_plugin.py", line 109, in reload_plugin
    m = importlib.import_module(modulename)
  File "./python3.3/importlib/__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1022, in load_module
  File "<frozen importlib._bootstrap>", line 1003, in load_module
  File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 868, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "D:\Sublime Text Build 3126 x64 For Debug\Data\Packages\Exalt\impl\plugin.py", line 18, in <module>
    os.environ["XML_CATALOG_FILES"] = exalt.get_catalog_files()
  File "D:\Sublime Text Build 3126 x64 For Debug\Data\Packages\Exalt\exalt.py", line 64, in get_catalog_files
    catalog_urls = map(lambda file: file_to_uri(file), catalog_files)
TypeError: 'NoneType' object is not iterable
reloading settings Packages/Exalt/Exalt.sublime-settings
reloading plugin Exalt.messages
reloading plugin Exalt.namespaces
reloading plugin Exalt.settings
reloading plugin Exalt.utils
reloading plugin Exalt.view
reloading settings Packages/Exalt/XSLT.sublime-settings

Stack trace 2:

reloading plugin Exalt.impl.plugin
Traceback (most recent call last):
  File "D:\Sublime Text Build 3126 x64 For Debug\sublime_plugin.py", line 210, in on_api_ready
    m.plugin_loaded()
  File "D:\Sublime Text Build 3126 x64 For Debug\Data\Packages\Exalt\exalt.py", line 84, in plugin_loaded
    sublime_plugin.reload_plugin("%s.impl.plugin" % constants.PLUGIN_NAME)
  File "D:\Sublime Text Build 3126 x64 For Debug\sublime_plugin.py", line 109, in reload_plugin
    m = importlib.import_module(modulename)
  File "./python3.3/importlib/__init__.py", line 90, in import_module
  File "<frozen importlib._bootstrap>", line 1584, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1565, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1532, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 584, in _check_name_wrapper
  File "<frozen importlib._bootstrap>", line 1022, in load_module
  File "<frozen importlib._bootstrap>", line 1003, in load_module
  File "<frozen importlib._bootstrap>", line 560, in module_for_loader_wrapper
  File "<frozen importlib._bootstrap>", line 868, in _load_module
  File "<frozen importlib._bootstrap>", line 313, in _call_with_frames_removed
  File "D:\Sublime Text Build 3126 x64 For Debug\Data\Packages\Exalt\impl\plugin.py", line 23, in <module>
    from lxml import etree
ImportError: DLL load failed: The specified module could not be found.

4. Steps to reproduce

I reproduce the problem in a version of Sublime Text without plugins and user settings.

I install Exalt via Package Control → I get stack trace 1. I restart Sublime Text → I get stack trace 2.

5. Environment

Operating system and version: Windows 10 Enterprise LTSB 64-bit EN Sublime Text: Build 3126 Python 3.6.0 lxml: 3.7.3

Thanks.

eerohele commented 7 years ago

Hmm... does Exalt work for you despite these stack traces?

You mention that you have Python 3.6.0 and lxml 3.7.3 installed. I wonder whether Sublime Text is trying to use the lxml you have installed instead of its dependency...?

I can't reproduce either error, but I'll try to look into it a bit more when I get the chance.

Kristinita commented 7 years ago

@eerohele , please, to see my Stack Overflow question, 6.2 item about your lxml dependency. Possibly, question relate with this issue.

Thanks.

keith-hall commented 7 years ago

I think @eerohele might be on to something here:

You mention that you have Python 3.6.0 and lxml 3.7.3 installed. I wonder whether Sublime Text is trying to use the lxml you have installed instead of its dependency...?

what is the output of import sys; sys.path in the ST console @Kristinita ?

on my computer it is

['C:\\Program Files\\Sublime Text 3', 'C:\\Program Files\\Sublime Text 3/python3.3.zip', 'C:\\Users\\Keith\\AppData\\Roaming\\Sublime Text 3\\Packages', 'C:\\Users\\Keith\\AppData\\Roaming\\SUBLIM~1\\Packages\\lxml\\ST3_WI~2']

if it contains anything outside of the ST installation folder and Packages folder, then most likely your system-wide packages are being picked up, which won't work well with ST unless the Python version on your system is the same as ST's - which it isn't. So you will need to remove these from the path, so that ST won't pick them up, and instead correctly use the ST dependency package.

Kristinita commented 7 years ago

@keith-hall ,

1. Demonstration

Thanks for the answer! Now my plugin works!

Keith Hall

2. Settings

My plugin. I don't need to remove global lxml.

import re
import sys
import urllib

from w3lib.url import safe_url_string

import sublime_plugin
sys.path.append('C:\\Python36\\Lib\\site-packages')

from bs4 import BeautifulSoup  # noqa

class KristinitaLuckyLinkCommand(sublime_plugin.TextCommand):

    def run(self, edit):
        # Get selection text
        print('KristinitaLuckyLink called')
        select = self.view.sel()
        selection_region = select[0]
        selection_text = self.view.substr(selection_region)
        print(selection_text)

        # ASCII link for solved encoding problems —
        # http://stackoverflow.com/a/40654295/5951529
        ascii_link = safe_url_string(
            u'http://duckduckgo.com/html/?q=' + (selection_text),
            encoding="UTF-8")
        print(ascii_link)
        # SERP DuckDuckGo
        serp = urllib.request.urlopen(ascii_link)
        # Reading SERP
        read_serp = serp.read()
        # BeautifulSoup — http://stackoverflow.com/a/11923803/5951529
        parsed = BeautifulSoup(read_serp, "lxml")
        # Parsed first link
        first_link = parsed.findAll(
            'div', {'class': re.compile('links_main*')})[0].a['href']
        # Remove DuckDuckGo specific characters —
        # http://stackoverflow.com/a/3942100/5951529
        remove_duckduckgo_symbols = first_link.replace("/l/?kh=-1&uddg=", "")
        # Final link — http://stackoverflow.com/a/32451970/5951529
        final_link = (urllib.parse.unquote(remove_duckduckgo_symbols))
        markdown_link = '[' + selection_text + ']' + \
            '(' + final_link + ')'
        print(markdown_link)

        # Replace selected text to Markdown link
        self.view.replace(
            edit, selection_region, markdown_link)

Output:

>>> import sys; sys.path
['D:\\Sublime Text 3 x64\\Data\\Packages\\FileHeader', 'D:\\Sublime Text 3 x64\\Data\\Packages\\WakaTime\\packages\\wakatime\\packages', 'D:\\Sublime Text 3 x64\\Data\\Packages\\WakaTime\\packages\\wakatime\\packages', 'D:\\Sublime Text 3 x64\\Data\\Packages\\WakaTime\\packages', 'D:\\Sublime Text 3 x64\\Data\\Packages\\WakaTime\\packages', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Python PEP8 Autoformat\\libs\\py33', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Python PEP8 Autoformat\\libs', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Mediawiker\\lib\\pyaes.zip', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Mediawiker\\lib\\pbkdf2.zip', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Mediawiker\\lib\\keyring.zip', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Travis YML Lint\\lib', 'D:\\Sublime Text 3 x64\\Data\\Packages\\sublime-github\\lib', 'D:\\Sublime Text 3 x64\\Data\\Packages\\sublime-github', 'D:\\Sublime Text 3 x64\\Data\\Packages\\sublime-github', 'D:\\Sublime Text 3 x64\\Data\\Packages\\sublime-github', 'D:\\Sublime Text 3 x64\\Data\\Packages\\sublime-github\\lib', 'D:\\Sublime Text 3 x64\\Data\\Packages\\sublime-github', 'D:\\Sublime Text 3 x64\\Data\\Packages\\sublime-github', 'FileHeader', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Browser Refresh\\win', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Browser Refresh', 'D:\\Sublime Text 3 x64', 'D:\\Sublime Text 3 x64/python3.3.zip', 'D:\\Sublime Text 3 x64\\Data\\Packages', 'D:\\SUDCA3~1\\Data\\Packages\\pygments\\all', 'D:\\SUDCA3~1\\Data\\Packages\\lxml\\ST3_WI~2', 'D:\\SUDCA3~1\\Data\\Packages\\PATHTO~2\\all', 'D:\\SUDCA3~1\\Data\\Packages\\coverage\\ST3_WI~2', 'D:\\SUDCA3~1\\Data\\Packages\\PACKAG~1\\all', 'D:\\SUDCA3~1\\Data\\Packages\\watchdog\\all', 'D:\\SUDCA3~1\\Data\\Packages\\backrefs\\st3', 'D:\\SUDCA3~1\\Data\\Packages\\dateutil\\all', 'D:\\SUDCA3~1\\Data\\Packages\\gntp\\all', 'D:\\SUDCA3~1\\Data\\Packages\\MARKUP~1\\all', 'D:\\SUDCA3~1\\Data\\Packages\\oauthlib\\all', 'D:\\SUDCA3~1\\Data\\Packages\\PY2BF6~1\\st3', 'D:\\SUDCA3~1\\Data\\Packages\\python-pywin32\\st3_windows_x64', 'D:\\SUDCA3~1\\Data\\Packages\\python-pywin32\\st3_windows_x64\\win32', 'D:\\SUDCA3~1\\Data\\Packages\\python-pywin32\\st3_windows_x64\\win32\\lib', 'D:\\SUDCA3~1\\Data\\Packages\\python-pywin32\\st3_windows_x64\\win32comext', 'D:\\SUDCA3~1\\Data\\Packages\\pytz\\all', 'D:\\SUDCA3~1\\Data\\Packages\\pyyaml\\st3', 'D:\\SUDCA3~1\\Data\\Packages\\regex\\ST3_WI~2', 'D:\\SUDCA3~1\\Data\\Packages\\requests\\all', 'D:\\SUDCA3~1\\Data\\Packages\\PY8724~1\\all', 'D:\\SUDCA3~1\\Data\\Packages\\REQUES~1\\all', 'D:\\SUDCA3~1\\Data\\Packages\\mdpopups\\st3', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Cloudup\\requests', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Codec\\idna', 'D:\\Sublime Text 3 x64\\Data\\Packages\\EditorConfig', 'D:\\Sublime Text 3 x64\\Data\\Packages\\EditorConfig', 'D:\\Sublime Text 3 x64\\Data\\Installed Packages\\Emmet.sublime-package', 'D:\\Sublime Text 3 x64\\Data\\Installed Packages\\Emmet.sublime-package\\emmet_completions', 'D:\\Sublime Text 3 x64\\Data\\Installed Packages\\Emmet.sublime-package\\emmet', 'D:\\Sublime Text 3 x64\\Data\\Installed Packages\\IndentX.sublime-package', 'D:\\Sublime Text 3 x64\\Data\\Installed Packages\\Javascript Beautify.sublime-package\\libs', 'D:\\Sublime Text 3 x64\\Data\\Installed Packages\\Javascript Beautify.sublime-package\\libs\\js-beautify\\python', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Pywin32\\lib\\x64\\win32', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Pywin32\\lib\\x64\\win32\\lib', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Pywin32\\lib\\x64', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Pywin32\\lib\\x64\\win32comext', 'D:\\Sublime Text 3 x64\\Data\\Packages\\coverage\\st3_windows_x64', 'D:\\Sublime Text 3 x64\\Data\\Installed Packages\\Web Inspector.sublime-package', 'D:\\Sublime Text 3 x64\\Data\\Packages\\CodeFormatter\\codeformatter\\lib', 'D:\\Sublime Text 3 x64\\Data\\Packages\\CodeFormatter\\codeformatter\\lib\\htmlbeautifier', 'C:\\Python36\\Lib\\site-packages', 'D:\\Sublime Text 3 x64\\Data\\Packages\\Highlight/HighlightLib', 'C:\\Python36', 'C:\\Python36\\Lib\\site-packages', 'C:\\Python36', 'C:\\Python36\\python36.zip', 'C:\\Python36\\DLLs', 'C:\\Python36\\lib', 'C:\\Users\\SashaChernykh\\AppData\\Roaming\\Python\\Python36\\site-packages', 'C:\\Python36\\lib\\site-packages', 'C:\\Python36\\lib\\site-packages\\xgoogle-1.3-py3.6.egg', 'C:\\Python36\\lib\\site-packages\\pyment-0.3.2.dev0-py3.6.egg', 'D:\\Sublime Text 3 x64\\Data\\Installed Packages\\PyV8', 'D:\\Sublime Text 3 x64\\Data\\Installed Packages\\PyV8\\win64-p3', 'D:\\Sublime Text 3 x64\\Data\\Installed Packages\\PyV8\\pyv8-win64-p3', 'C:\\Python36\\Lib\\site-packages', 'C:\\Python36\\Lib\\site-packages']

I remove all C:\\Python36 paths → plugin successful works for me.

3. Questions

  1. How new paths add to sys.path?
  2. Can other plugins work incorrectly, if user remove paths?
  3. Can user or plugin developer prevent the addition of unwanted paths?

@keith-hall, please, post your answer to Stack Overflow. I give bounty for you — small award for you helps.

Thanks.

Kristinita commented 7 years ago

Now after paths removing, I don't reproduce this issue.

Thanks.

Kristinita commented 7 years ago

@keith-hall , bounty end today, tomorrow I can't give you bounty.

Thanks.