chore: use tomllib on Python 3.11 (#1047)

* Use tomllib on Python 3.11

* delint

Co-authored-by: hauntsaninja <>
This commit is contained in:
Shantanu
2022-04-16 00:00:57 -04:00
committed by GitHub
co-authored by hauntsaninja <>
parent 9ae6ae2756
commit 6d4431306e
8 changed files with 48 additions and 16 deletions
+5 -2
View File
@@ -18,7 +18,10 @@ from typing import (
Union,
)
import tomli
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib
from packaging.specifiers import SpecifierSet
from .architecture import Architecture
@@ -244,7 +247,7 @@ class OptionsReader:
Load a toml file, returns global and platform as separate dicts.
"""
with filename.open("rb") as f:
config = tomli.load(f)
config = tomllib.load(f)
global_options = config.get("tool", {}).get("cibuildwheel", {})
platform_options = global_options.get(self.platform, {})
+5 -2
View File
@@ -4,7 +4,10 @@ from configparser import ConfigParser
from pathlib import Path
from typing import Any, Optional
import tomli
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib
if sys.version_info < (3, 8):
Constant = ast.Str
@@ -56,7 +59,7 @@ def get_requires_python_str(package_dir: Path) -> Optional[str]:
# Read in from pyproject.toml:project.requires-python
try:
with (package_dir / "pyproject.toml").open("rb") as f1:
info = tomli.load(f1)
info = tomllib.load(f1)
return str(info["project"]["requires-python"])
except (FileNotFoundError, KeyError, IndexError, TypeError):
pass
+8 -3
View File
@@ -32,7 +32,12 @@ from typing import (
import bracex
import certifi
import tomli
if sys.version_info >= (3, 11):
import tomllib
else:
import tomli as tomllib
from filelock import FileLock
from packaging.requirements import InvalidRequirement, Requirement
from packaging.specifiers import SpecifierSet
@@ -203,7 +208,7 @@ def get_build_verbosity_extra_flags(level: int) -> List[str]:
def read_python_configs(config: PlatformName) -> List[Dict[str, str]]:
input_file = resources_dir / "build-platforms.toml"
with input_file.open("rb") as f:
loaded_file = tomli.load(f)
loaded_file = tomllib.load(f)
results: List[Dict[str, str]] = list(loaded_file[config]["python_configurations"])
return results
@@ -460,7 +465,7 @@ def get_pip_version(env: Dict[str, str]) -> str:
def _ensure_virtualenv() -> Path:
input_file = resources_dir / "virtualenv.toml"
with input_file.open("rb") as f:
loaded_file = tomli.load(f)
loaded_file = tomllib.load(f)
version = str(loaded_file["version"])
url = str(loaded_file["url"])
path = CIBW_CACHE_PATH / f"virtualenv-{version}.pyz"