Skip to content

Commit

Permalink
remove tomlpp (#294)
Browse files Browse the repository at this point in the history
closes #291 by using tomli instead

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
tlambert03 and pre-commit-ci[bot] authored Jun 8, 2023
1 parent e4aefb2 commit 8fb9e3e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 21 deletions.
4 changes: 2 additions & 2 deletions _docs/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,9 @@ def example_contribution(
if format == "yaml":
return yaml.safe_dump(output, sort_keys=False)
if format == "toml":
import pytomlpp as toml
import tomli_w

return toml.dumps(output)
return tomli_w.dumps(output)
if format == "json":
return json.dumps(output)
raise ValueError("Invalid format: {format}. Must be 'yaml', 'toml' or 'json'.")
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ dependencies = [
"build",
"psygnal>=0.3.0",
"pydantic<2",
"pytomlpp",
"tomli-w",
"tomli; python_version < '3.11'",
"rich",
"typer",
]
Expand Down
12 changes: 0 additions & 12 deletions src/npe2/_inspection/_setuputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,6 @@ def get_package_dir_info(path: Union[Path, str]) -> PackageInfo:
EntryPoint(name.strip(), value.strip(), group)
)

# # check for pyproject.toml
# pyproject_toml = path / "pyproject.toml"
# if pyproject_toml.exists():
# info.pyproject_toml = pyproject_toml
# with open(pyproject_toml, "r") as f:
# data = pytomlpp.load(f)
# if project := data.get("project"):
# info.package_name = project.get("name", "")
# for group, ep in project.get('entry-points', {}).items():
# for name, value in ep.items():
# info.entry_points.append(EntryPoint(name, value, group))

return info


Expand Down
7 changes: 5 additions & 2 deletions src/npe2/_setuptools_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ def trace(*k: object) -> None:


def _lazy_tomli_load(data: str) -> dict[str, Any]:
from pytomlpp import loads
try:
import tomllib
except ImportError:
import tomli as tomllib # type: ignore [no-redef]

return loads(data)
return tomllib.loads(data)


def _read_dist_name_from_setup_cfg() -> str | None:
Expand Down
14 changes: 10 additions & 4 deletions src/npe2/manifest/_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from pathlib import Path
from typing import Callable, Dict, Optional, Union

import pytomlpp as toml
import yaml
from pydantic import BaseModel, PrivateAttr

Expand All @@ -30,10 +29,12 @@ def toml(self, pyproject=False, **kwargs) -> str:
**kwargs
passed to `BaseModel.json()`
"""
import tomli_w

d = self._serialized_data(**kwargs)
if pyproject:
d = {"tool": {"napari": d}}
return toml.dumps(d)
return tomli_w.dumps(d)

def yaml(self, **kwargs) -> str:
"""Generate serialized `yaml` string for this model.
Expand Down Expand Up @@ -74,13 +75,18 @@ def from_file(cls, path: Union[Path, str]):
if path.suffix.lower() == ".json":
loader = json.load
elif path.suffix.lower() == ".toml":
loader = toml.load
try:
import tomllib
except ImportError:
import tomli as tomllib # type: ignore [no-redef]

loader = tomllib.load
elif path.suffix.lower() in (".yaml", ".yml"):
loader = yaml.safe_load
else:
raise ValueError(f"unrecognized file extension: {path}") # pragma: no cover

with open(path, encoding="utf-8") as f:
with open(path, mode="rb") as f:
data = loader(f) or {}

if path.name == "pyproject.toml":
Expand Down

0 comments on commit 8fb9e3e

Please sign in to comment.