Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate Python dependency uiri/toml to tomllib / hukkin/tomli #821

Merged
merged 1 commit into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
)