Code Monkey home page Code Monkey logo

pyls-black's People

Contributors

auscompgeek avatar betaboon avatar bryanforbes avatar dbarrosop avatar fsouza avatar rupert avatar sveitser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

pyls-black's Issues

Update plugin to use python-lsp-server instead of python-language-server

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:

  1. The plugin should replace python-language-server by python-lsp-server on its requirements.
  2. The pyls namespace is now pylsp, which means that all pyls imports should be replaced by pylsp.
  3. The pyls_* hookspecs are now pylsp_* hookspecs.
  4. The plugin can preserve the 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.

Compatibility with yapf and autopep8

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?

Remove configuration parsing

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

Return errors to pyls

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).

Log black config options

The following should be logged:

  • The directories we're searching to find the pyproject.toml config file.
  • The path to the config file (if found).
  • Each config option and its value.

Incompatibility with black 22.1.0

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. 

And we can compare the Black versions 21.12b0 and 22.1.0.

Test failure with black version 21.04b

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 =========================

Add support for using black as a linter

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.

Regression on black 19.3b0

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

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.