From 46ae9b364df499b033fa128209d469e130d29ed2 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Sun, 30 Apr 2023 20:04:48 +0100 Subject: [PATCH 1/2] Use `tomllib/tomli` over `toml` --- pyperformance/__init__.py | 4 ++-- pyperformance/_pyproject_toml.py | 9 +++++++-- pyperformance/data-files/requirements.txt | 10 +++------- pyproject.toml | 6 +++++- requirements.in | 2 +- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/pyperformance/__init__.py b/pyperformance/__init__.py index 647d1072..7248ce02 100644 --- a/pyperformance/__init__.py +++ b/pyperformance/__init__.py @@ -34,10 +34,10 @@ def _is_devel_install(): # This means it creates a link back to the checkout instead # of copying the files. try: - import toml + import packaging except ModuleNotFoundError: return False - sitepackages = os.path.dirname(os.path.dirname(toml.__file__)) + sitepackages = os.path.dirname(os.path.dirname(packaging.__file__)) if os.path.isdir(os.path.join(sitepackages, 'pyperformance')): return False if not os.path.exists(os.path.join(sitepackages, 'pyperformance.egg-link')): diff --git a/pyperformance/_pyproject_toml.py b/pyperformance/_pyproject_toml.py index e7c6563c..dad391d6 100644 --- a/pyperformance/_pyproject_toml.py +++ b/pyperformance/_pyproject_toml.py @@ -12,13 +12,18 @@ import os.path import re +import sys import urllib.parse import packaging.requirements import packaging.specifiers import packaging.utils import packaging.version -import toml + +if sys.version_info >= (3, 11): + import tomllib +else: + import tomli as tomllib from ._utils import check_name @@ -52,7 +57,7 @@ def parse_pyproject_toml(text, rootdir, name=None, *, tools=None, requirefiles=True, ): - data = toml.loads(text) + data = tomllib.loads(text) unused = list(data) for section, normalize in SECTIONS.items(): diff --git a/pyperformance/data-files/requirements.txt b/pyperformance/data-files/requirements.txt index 9c1bbf8f..4da6b34e 100644 --- a/pyperformance/data-files/requirements.txt +++ b/pyperformance/data-files/requirements.txt @@ -2,17 +2,13 @@ # This file is autogenerated by pip-compile with Python 3.11 # by the following command: # -# pip-compile --output-file=requirements.txt requirements.in +# pip-compile --output-file=pyperformance/data-files/requirements.txt requirements.in # -packaging==21.3 +packaging==23.1 # via -r requirements.in -psutil==5.9.0 +psutil==5.9.5 # via # -r requirements.in # pyperf -pyparsing==3.0.8 - # via packaging pyperf==2.6.0 # via -r requirements.in -toml==0.10.2 - # via -r requirements.in diff --git a/pyproject.toml b/pyproject.toml index f69c39c4..369ea0b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,11 @@ classifiers = [ 'Programming Language :: Python', ] requires-python = ">=3.7" -dependencies = ["pyperf", "toml", "packaging"] +dependencies = [ + "pyperf", + "tomli; python_version < '3.11'", + "packaging", +] [project.optional-dependencies] dev = [ diff --git a/requirements.in b/requirements.in index 0d76bbd8..55f432ef 100644 --- a/requirements.in +++ b/requirements.in @@ -13,7 +13,7 @@ pyperf # for benchmark metadata: packaging -toml +tomli; python_version < '3.11' # Optional dependencies From a081f40411028451b593ba9b03a1b5a3fffcb8ca Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Mon, 1 May 2023 09:04:59 +0100 Subject: [PATCH 2/2] Use EAFP --- pyperformance/_pyproject_toml.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pyperformance/_pyproject_toml.py b/pyperformance/_pyproject_toml.py index dad391d6..ab6f6f85 100644 --- a/pyperformance/_pyproject_toml.py +++ b/pyperformance/_pyproject_toml.py @@ -12,7 +12,6 @@ import os.path import re -import sys import urllib.parse import packaging.requirements @@ -20,9 +19,9 @@ import packaging.utils import packaging.version -if sys.version_info >= (3, 11): +try: import tomllib -else: +except ImportError: import tomli as tomllib from ._utils import check_name