bitst0rm-pub / Formatter

🧜‍♀️ A Sublime Text plugin to beautify, minify, convert code: CSS, SCSS, Sass, HTML, XML, SVG,JS,JavaScript, JSON, GraphQL, Markdown, TypeScript, Vue, Lua, YAML, Go, Perl, PHP, Python, Ruby, Rust, Haskell, Dart, Swift, Crystal, Bash, Shell, SQL, CSV, C, C++, C#, Objective-C, D, Java, Pawn, Julia, Blade, LaTeX, D2, Graphviz, Mermaid, PlantUML, etc
Other
105 stars 22 forks source link

Modify Interpreter Lookup Logic and add warning for Black #13

Closed tomy0000000 closed 1 year ago

tomy0000000 commented 4 years ago
▋[Formatter](Thread-1154:formatter.py#L83): [DEBUG] Target: (view)
▋[Formatter](Thread-1154:formatter.py#L84): [DEBUG] Scope: source.python meta.function.python storage.type.function.python 
▋[Formatter](Thread-1154:formatter.py#L85): [DEBUG] Syntax: python
▋[Formatter](Thread-1154:formatter.py#L86): [DEBUG] Formatter ID: black
▋[Formatter](Thread-1154:common.py#L215): [DEBUG] Interpreter: /usr/local/bin/python
▋[Formatter](Thread-1154:common.py#L226): [DEBUG] Executable: /Users/tomy0000000/.pyenv/versions/3.7.4/bin/black
▋[Formatter](Thread-1154:common.py#L249): [DEBUG] Config [default]: /Users/tomy0000000/Library/Application Support/Sublime Text 3/Packages/User/formatter.assets/config/blackrc.toml
▋[Formatter](Thread-1154:formatter_black.py#L64): [ERROR] File not formatted due to an error (errno=1): "Traceback (most recent call last):
  File "/Users/tomy0000000/.pyenv/versions/3.7.4/bin/black", line 5, in <module>
    from black import patched_main
  File "/Users/tomy0000000/.pyenv/versions/3.7.4/lib/python3.7/site-packages/black.py", line 104
    def from_configuration(cls, *, check: bool, diff: bool) -> "WriteBack":
                                 ^
SyntaxError: invalid syntax
"
▋[Formatter](Thread-1154:main.py#L118): [DEBUG] Formatting failed. 💣💥😢

Black does not support Python 2.

When Formatter resolve interpreter, even python3 exists (perhaps in somewhere far back of PATH) python in the front lines will be returned. Which is Python 2, most of the time.

This can be a huge problem, as user can't even find out simply by observing the debug logs.

Even if they did guess out the problem, editing settings won't solve the problem because the current logic tends to return the wrong interpreter.

A temporarily fix for user would be symlink python3 to first few PATH directory. Say you have a PATH of /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin, symlink python3 to /usr/local/bin will fix the problem for now.

tomy0000000 commented 4 years ago

@bitst0rm Please Review, Thx.