chore: use tomllib on Python 3.11 (#1047)
* Use tomllib on Python 3.11 * delint Co-authored-by: hauntsaninja <>
This commit is contained in:
co-authored by
hauntsaninja <>
parent
9ae6ae2756
commit
6d4431306e
@@ -5,13 +5,19 @@ from __future__ import annotations
|
|||||||
import copy
|
import copy
|
||||||
import difflib
|
import difflib
|
||||||
import logging
|
import logging
|
||||||
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Union
|
from typing import Any, Union
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import requests
|
import requests
|
||||||
import rich
|
import rich
|
||||||
import tomli
|
|
||||||
|
if sys.version_info >= (3, 11):
|
||||||
|
import tomllib
|
||||||
|
else:
|
||||||
|
import tomli as tomllib
|
||||||
|
|
||||||
from packaging.specifiers import Specifier
|
from packaging.specifiers import Specifier
|
||||||
from packaging.version import Version
|
from packaging.version import Version
|
||||||
from rich.logging import RichHandler
|
from rich.logging import RichHandler
|
||||||
@@ -296,7 +302,7 @@ def update_pythons(force: bool, level: str) -> None:
|
|||||||
|
|
||||||
original_toml = toml_file_path.read_text()
|
original_toml = toml_file_path.read_text()
|
||||||
with toml_file_path.open("rb") as f:
|
with toml_file_path.open("rb") as f:
|
||||||
configs = tomli.load(f)
|
configs = tomllib.load(f)
|
||||||
|
|
||||||
for config in configs["windows"]["python_configurations"]:
|
for config in configs["windows"]["python_configurations"]:
|
||||||
all_versions.update_config(config)
|
all_versions.update_config(config)
|
||||||
|
|||||||
@@ -5,12 +5,18 @@ from __future__ import annotations
|
|||||||
import difflib
|
import difflib
|
||||||
import logging
|
import logging
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import NamedTuple
|
from typing import NamedTuple
|
||||||
|
|
||||||
import click
|
import click
|
||||||
import rich
|
import rich
|
||||||
import tomli
|
|
||||||
|
if sys.version_info >= (3, 11):
|
||||||
|
import tomllib
|
||||||
|
else:
|
||||||
|
import tomli as tomllib
|
||||||
|
|
||||||
from packaging.version import InvalidVersion, Version
|
from packaging.version import InvalidVersion, Version
|
||||||
from rich.logging import RichHandler
|
from rich.logging import RichHandler
|
||||||
from rich.syntax import Syntax
|
from rich.syntax import Syntax
|
||||||
@@ -78,7 +84,7 @@ def update_virtualenv(force: bool, level: str) -> None:
|
|||||||
|
|
||||||
original_toml = toml_file_path.read_text()
|
original_toml = toml_file_path.read_text()
|
||||||
with toml_file_path.open("rb") as f:
|
with toml_file_path.open("rb") as f:
|
||||||
loaded_file = tomli.load(f)
|
loaded_file = tomllib.load(f)
|
||||||
version = str(loaded_file["version"])
|
version = str(loaded_file["version"])
|
||||||
versions = git_ls_remote_versions(GET_VIRTUALENV_GITHUB)
|
versions = git_ls_remote_versions(GET_VIRTUALENV_GITHUB)
|
||||||
if versions[0].version > Version(version):
|
if versions[0].version > Version(version):
|
||||||
|
|||||||
@@ -18,7 +18,10 @@ from typing import (
|
|||||||
Union,
|
Union,
|
||||||
)
|
)
|
||||||
|
|
||||||
import tomli
|
if sys.version_info >= (3, 11):
|
||||||
|
import tomllib
|
||||||
|
else:
|
||||||
|
import tomli as tomllib
|
||||||
from packaging.specifiers import SpecifierSet
|
from packaging.specifiers import SpecifierSet
|
||||||
|
|
||||||
from .architecture import Architecture
|
from .architecture import Architecture
|
||||||
@@ -244,7 +247,7 @@ class OptionsReader:
|
|||||||
Load a toml file, returns global and platform as separate dicts.
|
Load a toml file, returns global and platform as separate dicts.
|
||||||
"""
|
"""
|
||||||
with filename.open("rb") as f:
|
with filename.open("rb") as f:
|
||||||
config = tomli.load(f)
|
config = tomllib.load(f)
|
||||||
|
|
||||||
global_options = config.get("tool", {}).get("cibuildwheel", {})
|
global_options = config.get("tool", {}).get("cibuildwheel", {})
|
||||||
platform_options = global_options.get(self.platform, {})
|
platform_options = global_options.get(self.platform, {})
|
||||||
|
|||||||
@@ -4,7 +4,10 @@ from configparser import ConfigParser
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Optional
|
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):
|
if sys.version_info < (3, 8):
|
||||||
Constant = ast.Str
|
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
|
# Read in from pyproject.toml:project.requires-python
|
||||||
try:
|
try:
|
||||||
with (package_dir / "pyproject.toml").open("rb") as f1:
|
with (package_dir / "pyproject.toml").open("rb") as f1:
|
||||||
info = tomli.load(f1)
|
info = tomllib.load(f1)
|
||||||
return str(info["project"]["requires-python"])
|
return str(info["project"]["requires-python"])
|
||||||
except (FileNotFoundError, KeyError, IndexError, TypeError):
|
except (FileNotFoundError, KeyError, IndexError, TypeError):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -32,7 +32,12 @@ from typing import (
|
|||||||
|
|
||||||
import bracex
|
import bracex
|
||||||
import certifi
|
import certifi
|
||||||
import tomli
|
|
||||||
|
if sys.version_info >= (3, 11):
|
||||||
|
import tomllib
|
||||||
|
else:
|
||||||
|
import tomli as tomllib
|
||||||
|
|
||||||
from filelock import FileLock
|
from filelock import FileLock
|
||||||
from packaging.requirements import InvalidRequirement, Requirement
|
from packaging.requirements import InvalidRequirement, Requirement
|
||||||
from packaging.specifiers import SpecifierSet
|
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]]:
|
def read_python_configs(config: PlatformName) -> List[Dict[str, str]]:
|
||||||
input_file = resources_dir / "build-platforms.toml"
|
input_file = resources_dir / "build-platforms.toml"
|
||||||
with input_file.open("rb") as f:
|
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"])
|
results: List[Dict[str, str]] = list(loaded_file[config]["python_configurations"])
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@@ -460,7 +465,7 @@ def get_pip_version(env: Dict[str, str]) -> str:
|
|||||||
def _ensure_virtualenv() -> Path:
|
def _ensure_virtualenv() -> Path:
|
||||||
input_file = resources_dir / "virtualenv.toml"
|
input_file = resources_dir / "virtualenv.toml"
|
||||||
with input_file.open("rb") as f:
|
with input_file.open("rb") as f:
|
||||||
loaded_file = tomli.load(f)
|
loaded_file = tomllib.load(f)
|
||||||
version = str(loaded_file["version"])
|
version = str(loaded_file["version"])
|
||||||
url = str(loaded_file["url"])
|
url = str(loaded_file["url"])
|
||||||
path = CIBW_CACHE_PATH / f"virtualenv-{version}.pyz"
|
path = CIBW_CACHE_PATH / f"virtualenv-{version}.pyz"
|
||||||
|
|||||||
@@ -37,8 +37,8 @@ install_requires =
|
|||||||
filelock
|
filelock
|
||||||
packaging
|
packaging
|
||||||
platformdirs
|
platformdirs
|
||||||
tomli
|
|
||||||
dataclasses;python_version < '3.7'
|
dataclasses;python_version < '3.7'
|
||||||
|
tomli;python_version < '3.11'
|
||||||
typing-extensions>=3.10.0.0;python_version < '3.8'
|
typing-extensions>=3.10.0.0;python_version < '3.8'
|
||||||
python_requires = >=3.6
|
python_requires = >=3.6
|
||||||
include_package_data = True
|
include_package_data = True
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
|
import sys
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
import tomli
|
if sys.version_info >= (3, 11):
|
||||||
|
import tomllib
|
||||||
|
else:
|
||||||
|
import tomli as tomllib
|
||||||
|
|
||||||
from packaging.version import Version
|
from packaging.version import Version
|
||||||
|
|
||||||
from cibuildwheel.extra import Printable, dump_python_configurations
|
from cibuildwheel.extra import Printable, dump_python_configurations
|
||||||
@@ -12,7 +17,7 @@ def test_compare_configs():
|
|||||||
txt = f1.read()
|
txt = f1.read()
|
||||||
|
|
||||||
with open(resources_dir / "build-platforms.toml", "rb") as f2:
|
with open(resources_dir / "build-platforms.toml", "rb") as f2:
|
||||||
dict_txt = tomli.load(f2)
|
dict_txt = tomllib.load(f2)
|
||||||
|
|
||||||
new_txt = dump_python_configurations(dict_txt)
|
new_txt = dump_python_configurations(dict_txt)
|
||||||
print(new_txt)
|
print(new_txt)
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ from fnmatch import fnmatch
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
import tomli
|
|
||||||
|
if sys.version_info >= (3, 11):
|
||||||
|
import tomllib
|
||||||
|
else:
|
||||||
|
import tomli as tomllib
|
||||||
|
|
||||||
from cibuildwheel.__main__ import main
|
from cibuildwheel.__main__ import main
|
||||||
from cibuildwheel.environment import ParsedEnvironment
|
from cibuildwheel.environment import ParsedEnvironment
|
||||||
@@ -314,7 +318,7 @@ def test_defaults(platform, intercepted_build_args):
|
|||||||
build_options: BuildOptions = intercepted_build_args.args[0].build_options(identifier=None)
|
build_options: BuildOptions = intercepted_build_args.args[0].build_options(identifier=None)
|
||||||
defaults_config_path = resources_dir / "defaults.toml"
|
defaults_config_path = resources_dir / "defaults.toml"
|
||||||
with defaults_config_path.open("rb") as f:
|
with defaults_config_path.open("rb") as f:
|
||||||
defaults_toml = tomli.load(f)
|
defaults_toml = tomllib.load(f)
|
||||||
|
|
||||||
root_defaults = defaults_toml["tool"]["cibuildwheel"]
|
root_defaults = defaults_toml["tool"]["cibuildwheel"]
|
||||||
platform_defaults = defaults_toml["tool"]["cibuildwheel"][platform]
|
platform_defaults = defaults_toml["tool"]["cibuildwheel"][platform]
|
||||||
|
|||||||
Reference in New Issue
Block a user