Skip to content

Commit

Permalink
Change: Use conditional import of tomllib
Browse files Browse the repository at this point in the history
  • Loading branch information
NiklasHargarter committed Jul 3, 2024
1 parent b681049 commit ec62dae
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 4 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ repository = "https://github.com/greenbone/troubadix"
homepage = "https://github.com/greenbone/troubadix"

# Full list: https://pypi.org/pypi?%3Aaction=list_classifiers
classifiers=[
classifiers = [
"Development Status :: 4 - Beta",
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", # pylint: disable=line-too-long
"License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", # pylint: disable=line-too-long
"Environment :: Console",
"Intended Audience :: Developers",
"Programming Language :: Python :: 3.9",
Expand All @@ -21,10 +21,7 @@ classifiers=[
"Topic :: Software Development :: Libraries :: Python Modules",
]

packages = [
{ include = "troubadix"},
{ include = "tests", format = "sdist" },
]
packages = [{ include = "troubadix" }, { include = "tests", format = "sdist" }]

[tool.poetry.dependencies]
python = "^3.9"
Expand All @@ -35,7 +32,7 @@ chardet = ">=4,<6"
validators = "0.20.0"
gitpython = "^3.1.31"
charset-normalizer = "^3.2.0"
tomli = "^2.0.1"
tomli = { version = "^2.0.1", python = "<3.11" }

[tool.poetry.dev-dependencies]
autohooks = ">=21.7.0"
Expand Down
8 changes: 6 additions & 2 deletions troubadix/troubadix.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from pathlib import Path
from typing import Iterable, List, Tuple

import tomli
from pontos.terminal import Terminal
from pontos.terminal.terminal import ConsoleTerminal

Expand All @@ -31,6 +30,11 @@
from troubadix.reporter import Reporter
from troubadix.runner import Runner

try:
import tomllib
except ImportError:
import tomli as tomllib


def generate_file_list(
dirs: Iterable[Path],
Expand Down Expand Up @@ -167,7 +171,7 @@ def main(args=None):
# Get the plugins configurations from the external toml file
try:
with open(parsed_args.plugins_config_file, "rb") as file:
plugins_config = tomli.load(file)
plugins_config = tomllib.load(file)
except FileNotFoundError:
term.warning(
f"Config file '{parsed_args.plugins_config_file}' does not exist"
Expand Down

0 comments on commit ec62dae

Please sign in to comment.