rupert / pyls-black Goto Github PK
View Code? Open in Web Editor NEWBlack plugin for the Python Language Server
License: MIT License
Black plugin for the Python Language Server
License: MIT License
Hi,
Given that Palantir removed all the community maintenance for both python-language-server (pyls) and python-jsonrpc-server (pyls_jsonrpc), we decided to create a separate organization that now maintains a community-based fork for the aforementioned packages, which can be found at: https://github.com/python-lsp/python-lsp-server and https://github.com/python-lsp/python-lsp-jsonrpc.
Our recommendation is to migrate this plugin to be compatible with the community server instead of the Palantir one. In order to do so, here is a migration guide that should help:
python-language-server
by python-lsp-server
on its requirements.pyls
namespace is now pylsp
, which means that all pyls
imports should be replaced by pylsp
.pyls_*
hookspecs are now pylsp_*
hookspecs.pyls_
prefix on its namespace in order to prevent further administration and release issues that may arise from renaming it.Feel free to ask any question about the migration process or about the new community organization for the server.
The following gets formatted correctly:
# hello
x=1+2
If the comment is removed the code is not formatted:
x=1+2
Tested using Sublime Text.
The documentation says,
To avoid unexpected results you should make sure yapf and autopep8 are not installed.
This seems quite extreme. Do I really have to completely uninstall yapf and autopep8 in order to use pyls-black
? What if other packages I have depend on those tools? Is there any possibility for coexistence?
Hi, I am packaging pyls_black for fedora.
Can you please include the license file in pypi release tarball moving forward?
Thanks!
At the moment we use the find_project_root
, FileMode.from_configuration
, and format_file_contents
functions from the black
package.
At the moment if a new configuration option is added to black
, our call to FileMode.from_configuration
will break as it will be missing an argument. It would be nice if black
exposed a function to create a FileMode
object from a pyproject.toml
configuration file. Then we could pass the FileMode
object to the format_file_contents
function without worrying about the exact configuration options.
See --skip-numeric-underscore-normalization
in #6
At the moment syntax errors or problems calling black are handled silently. It would help with debugging if these errors could be passed back to the Python Language Server and displayed in the editor's UI (e.g. in the Sublime Text status bar).
TypeError: __init__() missing 1 required positional argument: 'workspace'
This is the unittest log
log.txt
I am currently testing pyls 0.33.1
How can I install it in sublime text using the following LSP + pyls setup:
Thank you.
How can I configure LanguageClient to use black?
Hi,
does this integrate with Jupyter Lab notebooks?
Thanks
Philip
The following should be logged:
pyproject.toml
config file.While testing the update to Black 22.1.0 in Guix, we noticed that this program seems to need some adjustments.
After building pyls-black, we run the test suite. Almost all of the tests fails like this:
filename = '/tmp/guix-build-python-pyls-black-0.4.7.drv-0/source/tests/fixtures/example.py'
def load_config(filename: str) -> Dict:
defaults = {
"line_length": 88,
"fast": False,
"pyi": filename.endswith(".pyi"),
"skip_string_normalization": False,
"target_version": set(),
}
root = black.find_project_root((filename,))
> pyproject_filename = root / "pyproject.toml"
E TypeError: unsupported operand type(s) for /: 'tuple' and 'str'
pyls_black/plugin.py:76: TypeError
=========================== short test summary info ============================
FAILED tests/test_plugin.py::test_pylsp_format_document - TypeError: unsuppor...
FAILED tests/test_plugin.py::test_pyls_format_pyi_document - TypeError: unsup...
FAILED tests/test_plugin.py::test_pylsp_format_document_unchanged - TypeError...
FAILED tests/test_plugin.py::test_pyls_format_pyi_document_unchanged - TypeEr...
FAILED tests/test_plugin.py::test_pylsp_format_document_syntax_error - TypeEr...
FAILED tests/test_plugin.py::test_pylsp_format_document_with_config - TypeErr...
FAILED tests/test_plugin.py::test_pylsp_format_range[0-0-a = "hello"\n] - Typ...
FAILED tests/test_plugin.py::test_pylsp_format_range[1-1-b = 42\n] - TypeErro...
FAILED tests/test_plugin.py::test_pylsp_format_range[0-1-a = "hello"\nb = 42\n]
FAILED tests/test_plugin.py::test_pylsp_format_range_unchanged - TypeError: u...
FAILED tests/test_plugin.py::test_pylsp_format_range_syntax_error - TypeError...
FAILED tests/test_plugin.py::test_load_config - TypeError: unsupported operan...
FAILED tests/test_plugin.py::test_load_config_target_version - TypeError: uns...
FAILED tests/test_plugin.py::test_load_config_py36 - TypeError: unsupported o...
FAILED tests/test_plugin.py::test_load_config_defaults - TypeError: unsupport...
========================= 15 failed, 1 passed in 0.47s =========================
My colleague says this about it:
Black changed the return type for find_project_root in this version. It
now returns a tuple instead of a Path object.
When updating black to version 21.04b
in nixos ( NixOS/nixpkgs#120684 ) the tests for pyls-black
fail (result at the end).
As part of psf/black#1717 PY36_VERSIONS
were moved from from src/black/__init__.py
to tests/test_black.py
.
The corresponding commit is psf/black@6dddbd7 .
============================= test session starts ==============================
platform linux -- Python 3.8.9, pytest-6.2.3, py-1.10.0, pluggy-0.13.1
rootdir: /build/source
collected 16 items
tests/test_plugin.py .............F.. [100%]
=================================== FAILURES ===================================
____________________________ test_load_config_py36 _____________________________
def test_load_config_py36():
> config = load_config(str(fixtures_dir / "py36" / "example.py"))
tests/test_plugin.py:192:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
filename = '/build/source/tests/fixtures/py36/example.py'
def load_config(filename: str) -> Dict:
defaults = {
"line_length": 88,
"fast": False,
"pyi": filename.endswith(".pyi"),
"skip_string_normalization": False,
"target_version": set(),
}
root = black.find_project_root((filename,))
pyproject_filename = root / "pyproject.toml"
if not pyproject_filename.is_file():
return defaults
try:
pyproject_toml = toml.load(str(pyproject_filename))
except (toml.TomlDecodeError, OSError):
return defaults
file_config = pyproject_toml.get("tool", {}).get("black", {})
file_config = {
key.replace("--", "").replace("-", "_"): value
for key, value in file_config.items()
}
config = {
key: file_config.get(key, default_value)
for key, default_value in defaults.items()
}
if file_config.get("target_version"):
target_version = set(
black.TargetVersion[x.upper()] for x in file_config["target_version"]
)
elif file_config.get("py36"):
> target_version = black.PY36_VERSIONS
E AttributeError: module 'black' has no attribute 'PY36_VERSIONS'
/nix/store/qqvpg72b33m1pxc5lzjfmx224jp2vrbx-python3.8-pyls-black-0.4.6/lib/python3.8/site-packages/pyls_black/plugin.py:100: AttributeError
=========================== short test summary info ============================
FAILED tests/test_plugin.py::test_load_config_py36 - AttributeError: module '...
========================= 1 failed, 15 passed in 0.66s =========================
Using Black's --diff
option, it should be possible to show inline warnings in the editor.
At the moment I just let Black do its thing and not worry about it too much - so I'm not sure how useful this feature will be in practice.
Test environment:
Python: python 3.6
OS: Ubuntu 18.04 64bit
IDE: atom-ide(ide-python extension)
pyls: 0.25
With newest version black 19.3b0, pyls-black is malfunctioning, the error log in atom suggests that FileMode has no attribute from_configuration. Downgrading to 18.9b0 works.
I suggest specifying a version dependency for black for the time being.
Relevant issue for vim plugin: Link
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.