[+] improve toml compatibility for python 3.10
This commit is contained in:
parent
1faa511d15
commit
e5af828867
@ -8,12 +8,25 @@ import sys
|
|||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
import tomllib
|
|
||||||
|
|
||||||
from typing import (Self, Optional, Any,)
|
from typing import (Self, Optional, Any,)
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
def toml_load(f: io.BytesIO) -> Any:
|
||||||
|
try:
|
||||||
|
import tomllib
|
||||||
|
return tomllib.load(f)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
try:
|
||||||
|
import tomli
|
||||||
|
return tomli.load(f)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
@dataclasses.dataclass
|
@dataclasses.dataclass
|
||||||
class PyProject:
|
class PyProject:
|
||||||
path: pathlib.Path
|
path: pathlib.Path
|
||||||
@ -28,7 +41,7 @@ def pyproject_load(
|
|||||||
d: pathlib.Path,
|
d: pathlib.Path,
|
||||||
) -> PyProject:
|
) -> PyProject:
|
||||||
with io.open(d, 'rb') as f:
|
with io.open(d, 'rb') as f:
|
||||||
content = tomllib.load(f)
|
content = toml_load(f)
|
||||||
|
|
||||||
assert isinstance(content, dict)
|
assert isinstance(content, dict)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user