Use tomli for older Pythons, now when RHEL 9 has it

This commit is contained in:
Miro Hrončok 2023-05-26 14:21:14 +02:00
parent 4a38795ceb
commit 5ab7319ece
4 changed files with 30 additions and 31 deletions

View File

@ -159,9 +159,9 @@ echo 'python%{python3_pkgversion}dist(pip) >= 19'
echo 'python%{python3_pkgversion}dist(packaging)'
%{!-N:if [ -f pyproject.toml ]; then
%["%{python3_pkgversion}" == "3"
? "echo '(python%{python3_pkgversion}dist(toml) if python%{python3_pkgversion}-devel < 3.11)'"
? "echo '(python%{python3_pkgversion}dist(tomli) if python%{python3_pkgversion}-devel < 3.11)'"
: "%[v"%{python3_pkgversion}" < v"3.11"
? "echo 'python%{python3_pkgversion}dist(toml)'"
? "echo 'python%{python3_pkgversion}dist(tomli)'"
: "true # will use tomllib, echo nothing"
]"
]

View File

@ -13,8 +13,8 @@ License: MIT
# Increment Y and reset Z when new macros or features are added
# Increment Z when this is a bugfix or a cosmetic change
# Dropping support for EOL Fedoras is *not* considered a breaking change
Version: 1.8.0
Release: 2%{?dist}
Version: 1.8.1
Release: 1%{?dist}
# Macro files
Source001: macros.pyproject
@ -61,7 +61,7 @@ BuildRequires: python3dist(setuptools)
BuildRequires: python3dist(tox-current-env) >= 0.0.6
%endif
BuildRequires: python3dist(wheel)
BuildRequires: (python3dist(toml) if python3-devel < 3.11)
BuildRequires: (python3dist(tomli) if python3-devel < 3.11)
%endif
# We build on top of those:
@ -161,6 +161,9 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856
%changelog
* Wed May 31 2023 Miro Hrončok <mhroncok@redhat.com> - 1.8.1-1
- On Python older than 3.11, use tomli instead of deprecated toml
* Tue May 23 2023 Miro Hrončok <mhroncok@redhat.com> - 1.8.0-2
- Rebuilt for ELN dependency changes

View File

@ -202,19 +202,15 @@ class Requirements:
def toml_load(opened_binary_file):
try:
# tomllib is in the standard library since 3.11.0b1
import tomllib as toml_module
load_from = opened_binary_file
import tomllib
except ImportError:
try:
# note: we could use tomli here,
# but for backwards compatibility with RHEL 9, we use toml instead
import toml as toml_module
load_from = io.TextIOWrapper(opened_binary_file, encoding='utf-8')
import tomli as tomllib
except ImportError as e:
print_err('Import error:', e)
# already echoed by the %pyproject_buildrequires macro
sys.exit(0)
return toml_module.load(load_from)
return tomllib.load(opened_binary_file)
def get_backend(requirements):

View File

@ -17,7 +17,7 @@ Insufficient version of setuptools:
installed:
setuptools: 5
wheel: 1
toml: 1
tomli: 1
pyproject.toml: |
# empty
setup.py: |
@ -42,7 +42,7 @@ Default build system, empty setup.py:
installed:
setuptools: 50
wheel: 1
toml: 1
tomli: 1
include_runtime: false
pyproject.toml: |
# empty
@ -58,7 +58,7 @@ pyproject.toml with build-backend and setup.py:
installed:
setuptools: 50
wheel: 1
toml: 1
tomli: 1
setup.py: |
# empty
pyproject.toml: |
@ -81,7 +81,7 @@ Erroring setup.py:
Bad character in version:
installed:
toml: 1
tomli: 1
pyproject.toml: |
[build-system]
requires = ["pkg == 0.$.^.*"]
@ -89,7 +89,7 @@ Bad character in version:
Single value version with unsupported compatible operator:
installed:
toml: 1
tomli: 1
pyproject.toml: |
[build-system]
requires = ["pkg ~= 42", "foo"]
@ -98,7 +98,7 @@ Single value version with unsupported compatible operator:
Asterisk in version with unsupported compatible operator:
installed:
toml: 1
tomli: 1
pyproject.toml: |
[build-system]
requires = ["pkg ~= 0.1.*", "foo"]
@ -107,7 +107,7 @@ Asterisk in version with unsupported compatible operator:
Local path as requirement:
installed:
toml: 1
tomli: 1
pyproject.toml: |
[build-system]
requires = ["./pkg-1.2.3.tar.gz", "foo"]
@ -116,7 +116,7 @@ Local path as requirement:
Pip's egg=pkgName requirement not in requirements file:
installed:
toml: 1
tomli: 1
pyproject.toml: |
[build-system]
requires = ["git+https://github.com/monty/spam.git@master#egg=spam", "foo"]
@ -125,7 +125,7 @@ Pip's egg=pkgName requirement not in requirements file:
URL without egg fragment as requirement:
installed:
toml: 1
tomli: 1
pyproject.toml: |
[build-system]
requires = ["git+https://github.com/pkg-dev/pkg.git@96dbe5e3", "foo"]
@ -137,7 +137,7 @@ Build system dependencies in pyproject.toml with extras:
installed:
setuptools: 50
wheel: 1
toml: 1
tomli: 1
pyproject.toml: |
[build-system]
requires = [
@ -186,7 +186,7 @@ Build system dependencies in pyproject.toml without extras:
installed:
setuptools: 50
wheel: 1
toml: 1
tomli: 1
pyproject.toml: |
[build-system]
requires = [
@ -654,7 +654,7 @@ With pyproject.toml, requirements file and with -N option:
installed:
setuptools: 50
wheel: 1
toml: 1
tomli: 1
lxml: 3.9
ncclient: 1
cryptography: 2
@ -690,7 +690,7 @@ With pyproject.toml, requirements file and without -N option:
installed:
setuptools: 50
wheel: 1
toml: 1
tomli: 1
lxml: 3.9
ncclient: 1
cryptography: 2
@ -801,7 +801,7 @@ Pre-releases are accepted:
installed:
setuptools: 50
wheel: 1
toml: 1
tomli: 1
cffi: 1.15.0rc2
pyproject.toml: |
[build-system]
@ -841,7 +841,7 @@ pyproject.toml with runtime dependencies:
installed:
setuptools: 50
wheel: 1
toml: 1
tomli: 1
pyproject.toml: |
[build-system]
requires = ["setuptools"]
@ -864,7 +864,7 @@ pyproject.toml with runtime dependencies and partially selected extras:
installed:
setuptools: 50
wheel: 1
toml: 1
tomli: 1
extras:
- tests
pyproject.toml: |
@ -893,7 +893,7 @@ Self-referencing extras (sooner):
installed:
setuptools: 50
wheel: 1
toml: 1
tomli: 1
extras:
- dev # this is deliberately sooner in the alphabet than the referenced ones
pyproject.toml: |
@ -926,7 +926,7 @@ Self-referencing extras (later):
installed:
setuptools: 50
wheel: 1
toml: 1
tomli: 1
extras:
- xdev # this is deliberately later in the alphabet than the referenced ones
pyproject.toml: |
@ -959,7 +959,7 @@ Self-referencing extras (maze):
installed:
setuptools: 50
wheel: 1
toml: 1
tomli: 1
extras:
- start
pyproject.toml: |