akalongman / sublimetext-codeformatter

Code Formatter plugin for ST2/ST3
MIT License
770 stars 131 forks source link

bug(htmlbeautifier): Global installed BeaufitulSoup #362

Open Kristinita opened 6 years ago

Kristinita commented 6 years ago

1. Summary

If:

  1. I globally install BeautifulSoup,
  2. path to site-packages folder add to my local Sublime Text environment,
  3. "formatter_version": "bs4" in my "codeformatter_html_options".

I can't format any HTML file. I get an error in Sublime Text console:

command: code_formatter
error: CodeFormatter

Format error:
prettify() got an unexpected keyword argument 'indent_size'

2. Environment

3. Steps to reproduce

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

3.1. Without global site-packages path

I install CodeFormatter → I restart Sublime Text → I print in Sublime Text console:

>>> import sys; sys.path
['D:\\Sublime Text Build 3143 x64 For Debug', 'D:\\Sublime Text Build 3143 x64 For Debug\\python3.3.zip', 'D:\\Sublime Text Build 3143 x64 For Debug\\Data\\Lib\\python3.3', 'D:\\Sublime Text Build 3143 x64 For Debug\\Data\\Packages', 'D:\\SUB044~1\\Data\\Packages\\pyyaml\\st3', 'D:\\Sublime Text Build 3143 x64 For Debug\\Data\\Packages\\CodeFormatter\\codeformatter\\lib', 'D:\\Sublime Text Build 3143 x64 For Debug\\Data\\Packages\\CodeFormatter\\codeformatter\\lib\\htmlbeautifier']

3.2. With global site-packages path

See manual, how use global Python packages in Sublime Text environment.

For example, my package KristinitaLuckyLink contains lines:

site_packages = (os.environ['PYTHONPACKAGES'])
if site_packages not in sys.path:
    sys.path.append(site_packages)

These lines add 'C:\\Python36\\Lib\\site-packages' path to Sublime Text environment in Sublime Text start.

Package Control: Add Repository → I paste https://github.com/Kristinita/KristinitaLuckyLinkEnterPackage Control: Install Package → I select KristinitaLuckyLink → I restart Sublime Text → I print in Sublime Text console:

>>> import sys; sys.path
['D:\\Sublime Text Build 3143 x64 For Debug', 'D:\\Sublime Text Build 3143 x64 For Debug\\python3.3.zip', 'D:\\Sublime Text Build 3143 x64 For Debug\\Data\\Lib\\python3.3', 'D:\\Sublime Text Build 3143 x64 For Debug\\Data\\Packages', 'D:\\SUB044~1\\Data\\Packages\\pyyaml\\st3', 'C:\\Python36\\Lib\\site-packages', 'D:\\Sublime Text Build 3143 x64 For Debug\\Data\\Packages\\CodeFormatter\\codeformatter\\lib', 'D:\\Sublime Text Build 3143 x64 For Debug\\Data\\Packages\\CodeFormatter\\codeformatter\\lib\\htmlbeautifier']

Pay attention to 'C:\\Python36\\Lib\\site-packages'.


Then I open any valid HTML file → Ctrl+Shift+P (⌘⇧p for Mac) → CodeFormatter.

4. Expected behavior

If no 'C:\\Python36\\Lib\\site-packages'

or

"formatter_version": "regexp", in User/CodeFormatter.sublime-settings:

    HTML file successful beautify.

5. Actual behavior

Else 'C:\\Python36\\Lib\\site-packages'

and

"formatter_version": "bs4", in User/CodeFormatter.sublime-settings:

I get an error:

command: code_formatter
error: CodeFormatter

Format error:
prettify() got an unexpected keyword argument 'indent_size'

Thanks.

lizzietliu commented 6 years ago

same here

mkormendy commented 5 years ago

Same here. This is SUPER frustrating. What's the point of even installing this?

desean1625 commented 5 years ago

Getting same error on linux. Tried removing the package and reinstalling.

Changing my user settings to "formatter_version": "regex", prevents the error, but it doesn't run the beautiful soup formatter.

To get the beautiful soup formatter to run I removed indent_size from the args in CodeFormatter/codeformatter/htmlformatter.py.

BarbzYHOOL commented 5 years ago

Same and what @desean1625 suggested didn't change anything

BarbzYHOOL commented 5 years ago

I did this and it works but the result sux for my case so I'm not gonna use it anyway

        if formatter == 'bs4' and use_bs4:
            p_indent_size = 4
            options = htmlbeautifier.default_options()
        #     # if 'indent_size' in self.opts:
        #     #     p_indent_size = self.opts['indent_size']

        #     try:
        #         soup = BeautifulSoup(text, 'html.parser')
        #         stdout = soup.prettify(
        #             formatter=None, indent_size=p_indent_size)
        #     except Exception as e:
        #         stderr = str(e)