Coder Social home page Coder Social logo

joslarson / black-vscode Goto Github PK

View Code? Open in Web Editor NEW
9.0 9.0 1.0 79 KB

Deprecated: VS Code extension to format Python code using Black

Home Page: https://marketplace.visualstudio.com/items?itemName=joslarson.black-vscode

License: BSD 3-Clause "New" or "Revised" License

TypeScript 91.70% Python 8.30%
black deprecated formatter python vscode-extension

black-vscode's People

Contributors

joslarson avatar paddie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

paddie

black-vscode's Issues

RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII

OS: macOs 10.13.4

Stack trace

Failed to format: unhandled error.
Command "/usr/local/Cellar/python/3.6.3/Frameworks/Python.framework/Versions/3.6/bin/python3 -m black -l 80 -" resulted in an exit code of 1.
Error: Command failed: /usr/local/Cellar/python/3.6.3/Frameworks/Python.framework/Versions/3.6/bin/python3 -m black -l 80 -
Traceback (most recent call last):
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/black.py", line 3117, in <module>
    main()
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/click/core.py", line 722, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/click/core.py", line 676, in main
    _verify_python3_env()
  File "/usr/local/Cellar/python3/3.6.3/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/click/_unicodefun.py", line 118, in _verify_python3_env
    'for mitigation steps.' + extra)
RuntimeError: Click will abort further execution because Python 3 was configured to use ASCII as encoding for the environment.  Consult http://click.pocoo.org/python3/for mitigation steps.

This system lists a couple of UTF-8 supporting locales that
you can pick from.  The following suitable locales where
discovered: af_ZA.UTF-8, am_ET.UTF-8, be_BY.UTF-8, bg_BG.UTF-8, ca_ES.UTF-8, cs_CZ.UTF-8, da_DK.UTF-8, de_AT.UTF-8, de_CH.UTF-8, de_DE.UTF-8, el_GR.UTF-8, en_AU.UTF-8, en_CA.UTF-8, en_GB.UTF-8, en_IE.UTF-8, en_NZ.UTF-8, en_US.UTF-8, es_ES.UTF-8, et_EE.UTF-8, eu_ES.UTF-8, fi_FI.UTF-8, fr_BE.UTF-8, fr_CA.UTF-8, fr_CH.UTF-8, fr_FR.UTF-8, he_IL.UTF-8, hr_HR.UTF-8, hu_HU.UTF-8, hy_AM.UTF-8, is_IS.UTF-8, it_CH.UTF-8, it_IT.UTF-8, ja_JP.UTF-8, kk_KZ.UTF-8, ko_KR.UTF-8, lt_LT.UTF-8, nl_BE.UTF-8, nl_NL.UTF-8, no_NO.UTF-8, pl_PL.UTF-8, pt_BR.UTF-8, pt_PT.UTF-8, ro_RO.UTF-8, ru_RU.UTF-8, sk_SK.UTF-8, sl_SI.UTF-8, sr_YU.UTF-8, sv_SE.UTF-8, tr_TR.UTF-8, uk_UA.UTF-8, zh_CN.UTF-8, zh_HK.UTF-8, zh_TW.UTF-8

Broken by black==18.6b0

The new release of black contains changes to its output structure, which causes black-vscode to append the line 1 file reformatted. to every file it reformats.

See psf/black#299

black version 18.4a0 "outdated"

Hello, @joslarson! First, thanks for creating this extension, black is simply awesome. Since I've been rebuilding my dev environment every week, the newest version of black is being flagged as outdated by your extension. I'm working inside a virtualenv and black is only installed there - I already seen #4, I don't think it applies to this case.

$ python -m black --version       
black.py, version 18.4a0

I think the problem would be this line. I don't know if this is related to specific releases of the VSCode extension or the version testing line should be rewritten for major[.minor[.patch]] precedence.

Configurable black path

I'm getting lost in a sea of virtual environments. Can we have "python.formatting.blackPath" not unlike "python.formatting.yapfPath"?

CLI output appended to source file

Hello ๐Ÿ‘‹!

Thanks for making this extension - it works spectacularly!

I'm noticing that when I run the format document command in VSCode, there is a line appended to my source code:

1 file reformatted.

I ran the Black CLI on the same file and noticed the same output from there.

reformatted utils/redis.py
All done! โœจ ๐Ÿฐ โœจ
1 file reformatted.

I am using version 2.0.5 of the extension and version 18.6b0 of Black, running on macOS with VSCode version 1.23.1

Let me know if there are any other details you want - I gave a quick browse of the source here and didn't immediately see where this could be coming from. Happy to give a hand with a PR.

Cheers!

`Failed to format: unknown error.` on every attempt to format

Every source file I've tried so far, when I go to Format -> Document, I get a notification saying: Failed to format: unknown error.

VSCode version: 1.21.1
Python version: 3.6.2
OS: OSX 10.12.6 (Sierra)

Some of the source files I can't share (company owned), but one example that failed that I can share (though as I said every file I've tried produced the same error):

from setuptools import setup


def readme():
    with open('README.md') as f:
        return f.read()


setup(name='thethingy',
      version='0.1.1',
      description='CLI tool for stuff',
      long_description=readme(),
      classifiers=[
          'Development Status :: 3 - Alpha',
          'Programming Language :: Python :: 2.7',
      ],
      keywords='blargyblarg aws',
      url='http://foo.bar/baz',
      author='Me',
      author_email='',
      license='Internal Use',
      install_requires=[
          'beautifulsoup4',
          'awscli',
          'boto',
          'requests-ntlm',
      ],
      scripts=['bin/mytestscript.py'],
      include_package_data=True,
      zip_safe=False)

Support for suppressing unable to parse error message

Hi, is it possible to add an option that suppress the "unable to parse" message?

I often turn on "format-on-save" option in vscode. But every time I save at the middle of work where there is a broken syntax, black will report an error. Given how vscode handles such notifications, that error message persists, until I use my mouse to click "x".

Since black is not a linter, I suppose that it could just silently leave the file unchanged if the file has syntax errors.

Thank you for this amazing tool.

Coudn't make it work in VSCODE

Installed the extension, did a pip install black, put the code below in my workspace:

"python.formatting.provider" : "none",

but nothing happens when I do a "Format document". No output. Turning on debug, just gave me an empty black window in the terminal tab.

Running black from the command line works fine.

Maybe it is in conflict with some of my extensions.

My workspace settings:

{
    "python.pythonPath": "D:\\anaconda3\\envs\\wso2\\python.exe",
    "python.linting.enabled": true,
    "python.unitTest.nosetestArgs": [
        "."
    ],
    "python.unitTest.nosetestsEnabled": true,
    "files.associations": {
        "*.json": "jsonc"
    },
    "python.formatting.provider": "none",
    "[python]": {
        "editor.tabSize": 4,
        "editor.insertSpaces": true
    },
}

Here are my extensions:

akamud.vscode-javascript-snippet-pack
alefragnani.Bookmarks
christian-kohler.npm-intellisense
codezombiech.gitignore
DavidAnson.vscode-markdownlint
dbaeumer.jshint
dbaeumer.vscode-eslint
donjayamanne.githistory
donjayamanne.jupyter
DotJoshJohnson.xml
eamodio.gitlens
eg2.tslint
eg2.vscode-npm-script
felipecaputo.git-project-manager
hbenl.vscode-firefox-debug
himanoa.Python-autopep8
hnw.vscode-auto-open-markdown-preview
HookyQR.beautify
humao.rest-client
joslarson.black-vscode
linw1995.python-traceback-jumper
lonefy.vscode-JS-CSS-HTML-formatter
magicstack.MagicPython
ms-python.python
ms-vscode.Theme-MarkdownKit
msjsdiag.debugger-for-chrome
mtxr.sqltools
PKief.markdown-checkbox
secanis.jenkinsfile-support
sensourceinc.vscode-sql-beautify
t-sauer.autolinting-for-javascript
waderyan.gitblame
yzane.markdown-pdf

Support env variable expansion in "python.pythonPath" setting

Hi there,
I was just trying your extension but unfortunately it doesn't format my code at all. Im using:

$ python --version
Python 3.6.3
$ black --version
black, version 18.3a4
$ code --version
1.21.1
79b44aa704ce542d8ca4a3cc44cfca566e7720f1
x64

and this setting inside my .vscode/settings.json

{
    "python.pythonPath": "${env.VIRTUAL_ENV}/bin/python",
    "python.formatting.provider": "none",
    "python.formatting.autopep8Args": [
        "--max-line-length", "100",
        "--aggressive",
        "--aggressive"
    ],
    "python.linting.pylintEnabled": false,
    "python.linting.flake8Enabled": true,
    "python.linting.flake8Args": ["--max-line-length=100"],
    "editor.snippetSuggestions": "top",
    "[python]": {
        "editor.tabSize": 4,
        "editor.insertSpaces": true
    },
    "[json]": {
        "editor.tabSize": 2,
        "editor.insertSpaces": true
    },
    "black.lineLength": 100
}

Format Document does nothing

Sorry, it's me again :)

Version 1.3.1, picking Format Document from the command palette does nothing. I have debug: true, and the debug output does open (and "Black - Python code formatter" is selected) but only a single empty line gets output.

Can't find black when installed into venv

I installed Black into a virtual environment, and every time I try to format I get:

Command "black" not found in PATH.  Try `pip install black`

If I install systemwide the error goes away. Would be nice to not have to install system-wide, much like I don't with tools like autopep8 or pylint.

Broken on OSX when launching VS Code from finder/dock: not picking up system locale

I can't get this extension to work on OSX.

Noting happens when I run "Format Document" or "Format Selection". When I enable "black.debug" there is no debug output in the debug console.

I've tried setting "black.path" explicitly, I've set "python.formatting.provider" to "none", and other combinations of settings, to no avail. The black commands works from the command line.

What am I missing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.