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)' echo 'python%{python3_pkgversion}dist(packaging)'
%{!-N:if [ -f pyproject.toml ]; then %{!-N:if [ -f pyproject.toml ]; then
%["%{python3_pkgversion}" == "3" %["%{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" : "%[v"%{python3_pkgversion}" < v"3.11"
? "echo 'python%{python3_pkgversion}dist(toml)'" ? "echo 'python%{python3_pkgversion}dist(tomli)'"
: "true # will use tomllib, echo nothing" : "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 Y and reset Z when new macros or features are added
# Increment Z when this is a bugfix or a cosmetic change # Increment Z when this is a bugfix or a cosmetic change
# Dropping support for EOL Fedoras is *not* considered a breaking change # Dropping support for EOL Fedoras is *not* considered a breaking change
Version: 1.8.0 Version: 1.8.1
Release: 2%{?dist} Release: 1%{?dist}
# Macro files # Macro files
Source001: macros.pyproject Source001: macros.pyproject
@ -61,7 +61,7 @@ BuildRequires: python3dist(setuptools)
BuildRequires: python3dist(tox-current-env) >= 0.0.6 BuildRequires: python3dist(tox-current-env) >= 0.0.6
%endif %endif
BuildRequires: python3dist(wheel) BuildRequires: python3dist(wheel)
BuildRequires: (python3dist(toml) if python3-devel < 3.11) BuildRequires: (python3dist(tomli) if python3-devel < 3.11)
%endif %endif
# We build on top of those: # We build on top of those:
@ -161,6 +161,9 @@ export HOSTNAME="rpmbuild" # to speedup tox in network-less mock, see rhbz#1856
%changelog %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 * Tue May 23 2023 Miro Hrončok <mhroncok@redhat.com> - 1.8.0-2
- Rebuilt for ELN dependency changes - Rebuilt for ELN dependency changes

View File

@ -202,19 +202,15 @@ class Requirements:
def toml_load(opened_binary_file): def toml_load(opened_binary_file):
try: try:
# tomllib is in the standard library since 3.11.0b1 # tomllib is in the standard library since 3.11.0b1
import tomllib as toml_module import tomllib
load_from = opened_binary_file
except ImportError: except ImportError:
try: try:
# note: we could use tomli here, import tomli as tomllib
# 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')
except ImportError as e: except ImportError as e:
print_err('Import error:', e) print_err('Import error:', e)
# already echoed by the %pyproject_buildrequires macro # already echoed by the %pyproject_buildrequires macro
sys.exit(0) sys.exit(0)
return toml_module.load(load_from) return tomllib.load(opened_binary_file)
def get_backend(requirements): def get_backend(requirements):

View File

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