From b896ade1ba3e004879ed394b575e05f8be8cd66c Mon Sep 17 00:00:00 2001 From: Contextualist Date: Sat, 26 Feb 2022 22:30:49 -0500 Subject: [PATCH] Migrate `uiri/toml` to `tomllib` / `hukkin/tomli` --- maturin/__init__.py | 9 ++++++--- maturin/import_hook.py | 9 ++++++--- pyproject.toml | 4 ++-- setup.py | 11 +++++++---- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/maturin/__init__.py b/maturin/__init__.py index 24ba21964..9b364b936 100644 --- a/maturin/__init__.py +++ b/maturin/__init__.py @@ -17,12 +17,15 @@ from subprocess import SubprocessError from typing import Dict -import toml +try: + import tomllib +except ModuleNotFoundError: + import tomli as tomllib def get_config() -> Dict[str, str]: - with open("pyproject.toml", encoding="utf-8") as fp: - pyproject_toml = toml.load(fp) + with open("pyproject.toml", "rb") as fp: + pyproject_toml = tomllib.load(fp) return pyproject_toml.get("tool", {}).get("maturin", {}) diff --git a/maturin/import_hook.py b/maturin/import_hook.py index a989c511a..2c4e04fa5 100644 --- a/maturin/import_hook.py +++ b/maturin/import_hook.py @@ -10,7 +10,10 @@ import subprocess from typing import Optional -import toml +try: + import tomllib +except ModuleNotFoundError: + import tomli as tomllib class Importer(abc.MetaPathFinder): @@ -64,8 +67,8 @@ def load_module(self, fullname): def _is_cargo_project(cargo_toml: pathlib.Path, module_name: str) -> bool: with contextlib.suppress(FileNotFoundError): - with open(cargo_toml) as f: - cargo = toml.load(f) + with open(cargo_toml, "rb") as f: + cargo = tomllib.load(f) package_name = cargo.get("package", {}).get("name") if ( package_name == module_name diff --git a/pyproject.toml b/pyproject.toml index 20aa7debc..207ceb756 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ # Workaround to bootstrap maturin on non-manylinux platforms [build-system] -requires = ["setuptools~=53.0.0", "wheel~=0.36.2", "toml~=0.10.2"] +requires = ["setuptools~=53.0.0", "wheel~=0.36.2", "tomli>=1.1.0 ; python_version<'3.11'"] build-backend = "setuptools.build_meta" [project] @@ -12,7 +12,7 @@ classifiers = [ "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ] -dependencies = ["toml~=0.10.2"] +dependencies = ["tomli>=1.1.0 ; python_version<'3.11'"] [project.optional-dependencies] zig = [ diff --git a/setup.py b/setup.py index 0d6c8a3db..7d0c2edd4 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,10 @@ import subprocess import sys -import toml +try: + import tomllib +except ModuleNotFoundError: + import tomli as tomllib from setuptools import setup from setuptools.command.install import install @@ -109,8 +112,8 @@ def run(self): with open("Readme.md", encoding="utf-8", errors="ignore") as fp: long_description = fp.read() -with open("Cargo.toml") as fp: - version = toml.load(fp)["package"]["version"] +with open("Cargo.toml", "rb") as fp: + version = tomllib.load(fp)["package"]["version"] setup( name="maturin", @@ -131,6 +134,6 @@ def run(self): "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", ], - install_requires=["toml~=0.10.0"], + install_requires=["tomli>=1.1.0 ; python_version<'3.11'"], zip_safe=False, )