Skip to content
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

Replace tomli with tomllib for Python 3.11+ #214

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CHANGELOG

### 6.0.0

* Replace dependency on `tomli` with builtin `tomllib` for Python 3.11+

### 5.0.0

* Dropped support Python 3.8
Expand Down
15 changes: 10 additions & 5 deletions piplicenses.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,17 @@
from pathlib import Path
from typing import TYPE_CHECKING, Iterable, List, Type, cast

import tomli
from prettytable import ALL as RULE_ALL
from prettytable import FRAME as RULE_FRAME
from prettytable import HEADER as RULE_HEADER
from prettytable import NONE as RULE_NONE
from prettytable import PrettyTable

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

Check warning on line 54 in piplicenses.py

View check run for this annotation

Codecov / codecov/patch

piplicenses.py#L54

Added line #L54 was not covered by tests

if TYPE_CHECKING:
from email.message import Message
from typing import Callable, Dict, Iterator, Optional, Sequence
Expand Down Expand Up @@ -174,15 +178,16 @@
}


SYSTEM_PACKAGES = (
SYSTEM_PACKAGES = [
__pkgname__,
"pip",
"prettytable",
"wcwidth",
"setuptools",
"tomli",
"wheel",
)
]
if sys.version_info < (3, 11):
SYSTEM_PACKAGES.append("tomli")

Check warning on line 190 in piplicenses.py

View check run for this annotation

Codecov / codecov/patch

piplicenses.py#L190

Added line #L190 was not covered by tests

LICENSE_UNKNOWN = "UNKNOWN"

Expand Down Expand Up @@ -905,7 +910,7 @@
def load_config_from_file(pyproject_path: str):
if Path(pyproject_path).exists():
with open(pyproject_path, "rb") as f:
return tomli.load(f).get("tool", {}).get(__pkgname__, {})
return tomllib.load(f).get("tool", {}).get(__pkgname__, {})
return {}


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ classifiers = [
]
dependencies = [
"prettytable >= 2.3.0",
"tomli >= 2"
"tomli >= 2;python_version<'3.11'"
]

[project.optional-dependencies]
Expand Down