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

Use stdlib tomllib instead of tomli for Python 3.11+ #748

Merged
merged 4 commits into from
Jul 11, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions .github/workflows/python-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
push:
branches:
- main
- "*"
tags:
- "v*"
release:
Expand All @@ -14,6 +14,9 @@ concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true

env:
FORCE_COLOR: 1

jobs:
test:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -79,9 +82,9 @@ jobs:
test_legacy_setuptools:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: "3.7"
architecture: x64
Expand All @@ -98,7 +101,7 @@ jobs:
steps:
- uses: actions/checkout@v3
- name: Setup python
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python_version }}
architecture: x64
Expand All @@ -118,8 +121,8 @@ jobs:
needs: [test]
name: Python sdist/wheel
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install dependencies
Expand All @@ -129,7 +132,7 @@ jobs:

- name: Build package
run: python -m build -o dist/
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
name: dist
path: dist
Expand All @@ -139,12 +142,12 @@ jobs:
runs-on: ubuntu-latest
needs: [dist]
steps:
- uses: actions/setup-python@v2
- uses: actions/setup-python@v4
with:
python-version: "3.8"
- name: Install dependencies
run: pip install twine
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v3
with:
name: dist
path: dist
Expand All @@ -156,7 +159,7 @@ jobs:
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
needs: [dist_check]
steps:
- uses: actions/download-artifact@v2
- uses: actions/download-artifact@v3
with:
name: dist
path: dist
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ packages = find:
install_requires =
packaging>=20.0
setuptools
tomli>=1.0.0 # keep in sync
typing-extensions
importlib-metadata;python_version < '3.8'
tomli>=1.0.0;python_version < '3.11' # keep in sync
python_requires = >=3.7
package_dir =
=src
Expand Down
10 changes: 7 additions & 3 deletions src/setuptools_scm/_integration/pyproject_reading.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import sys
import warnings
from typing import Any
from typing import Callable
Expand Down Expand Up @@ -28,8 +29,11 @@ def project_name(self) -> str | None:
return self.project.get("name")


def lazy_tomli_load(data: str) -> TOML_RESULT:
from tomli import loads
def lazy_toml_load(data: str) -> TOML_RESULT:
if sys.version_info >= (3, 11):
from tomllib import loads
else:
from tomli import loads

return loads(data)

Expand All @@ -40,7 +44,7 @@ def read_pyproject(
_load_toml: TOML_LOADER | None = None,
) -> PyProjectData:
if _load_toml is None:
_load_toml = lazy_tomli_load
_load_toml = lazy_toml_load
with open(name, encoding="UTF-8") as strm:
data = strm.read()
defn = _load_toml(data)
Expand Down
6 changes: 4 additions & 2 deletions testing/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ def wd(wd: WorkDir) -> WorkDir:


def test_pyproject_support(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None:
pytest.importorskip("tomli")
if sys.version_info <= (3, 10):
pytest.importorskip("tomli")
monkeypatch.delenv("SETUPTOOLS_SCM_DEBUG")
pkg = tmp_path / "package"
pkg.mkdir()
Expand Down Expand Up @@ -83,7 +84,8 @@ def test_pyproject_support(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> N

@with_metadata_in
def test_pyproject_support_with_git(wd: WorkDir, metadata_in: str) -> None:
pytest.importorskip("tomli")
if sys.version_info <= (3, 10):
pytest.importorskip("tomli")
wd.write("pyproject.toml", PYPROJECT_FILES[metadata_in])
wd.write("setup.py", SETUP_PY_FILES[metadata_in])
wd.write("setup.cfg", SETUP_CFG_FILES[metadata_in])
Expand Down
3 changes: 1 addition & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist=py{37,38,39,310}-{test,selfcheck},check_readme,check-dist,check-bootstrap
envlist=py{37,38,39,310,311}-{test,selfcheck},check_readme,check-dist,check-bootstrap

[pytest]
testpaths=testing
Expand Down Expand Up @@ -27,7 +27,6 @@ skip_install=
deps=
pytest
setuptools >= 45
tomli
virtualenv>20
typing_extensions
commands=
Expand Down