Skip to content

Commit

Permalink
Migrate uiri/toml to tomllib / hukkin/tomli
Browse files Browse the repository at this point in the history
  • Loading branch information
Contextualist committed Feb 27, 2022
1 parent fbf5958 commit b896ade
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
9 changes: 6 additions & 3 deletions maturin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", {})


Expand Down
9 changes: 6 additions & 3 deletions maturin/import_hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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 = [
Expand Down
11 changes: 7 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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",
Expand All @@ -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,
)

0 comments on commit b896ade

Please sign in to comment.