Skip to content

Replace the obsolete toml package with tomllib/tomli #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
rev: v0.942
hooks:
- id: mypy
additional_dependencies: [black, types-pkg_resources, types-setuptools, types-toml]
additional_dependencies: [black, types-pkg_resources, types-setuptools]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
hooks:
Expand Down
12 changes: 9 additions & 3 deletions pylsp_black/plugin.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import logging
import os
import sys
from functools import lru_cache
from pathlib import Path
from typing import Dict, Optional

import black
import toml
from pylsp import hookimpl
from pylsp._utils import get_eol_chars
from pylsp.config.config import Config

if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -154,8 +159,9 @@ def _load_config(filename: str, client_config: Config) -> Dict:
return defaults

try:
pyproject_toml = toml.load(str(pyproject_filename))
except (toml.TomlDecodeError, OSError):
with open(pyproject_filename, "rb") as f:
pyproject_toml = tomllib.load(f)
except (tomllib.TOMLDecodeError, OSError):
logger.warning(
"Error decoding pyproject.toml, using defaults: %r",
defaults,
Expand Down
7 changes: 5 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ classifiers =

[options]
packages = find:
install_requires = python-lsp-server>=1.4.0; black>=22.3.0; toml
install_requires =
python-lsp-server>=1.4.0
black>=22.3.0
tomli; python_version<'3.11'
python_requires = >= 3.7

[options.entry_points]
pylsp = pylsp_black = pylsp_black.plugin

[options.extras_require]
# add any types-* packages to .pre-commit-config.yaml mypy additional_dependencies
dev = isort>=5.0; flake8; pre-commit; pytest; mypy; pytest; types-pkg_resources; types-setuptools; types-toml
dev = isort>=5.0; flake8; pre-commit; pytest; mypy; pytest; types-pkg_resources; types-setuptools

[flake8]
max-line-length = 88
Expand Down