sublimetext-codeformatter
sublimetext-codeformatter copied to clipboard
bug(htmlbeautifier): Global installed BeaufitulSoup
1. Summary
If:
- I globally install BeautifulSoup,
-
path to
site-packages
folder add to my local Sublime Text environment, -
"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
- Windows 10 Enterprise LTSB 64-bit EN,
- Python 3.6.4,
- Sublime Text Build 3143,
- BeautifulSoup4 4.6.0,
- CodeFormatter 4.1.0.
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/KristinitaLuckyLink
→ Enter → Package 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.
same here
Same here. This is SUPER frustrating. What's the point of even installing this?
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.
Same and what @desean1625 suggested didn't change anything
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)