From a8da8e814ecb176fa72857756895888ee05bff88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Kreuzberger?= Date: Tue, 2 Apr 2024 22:58:09 +0200 Subject: [PATCH] [#69] fix deprecation warning (#70) * [#69] remove deprecation warnings from sphinx * differ between sphinx-versions 6 and 7 * linting issues * use exact versions from sphinx changelog * upgrade to sphinx 7.2.6 * fix deprecations due to version checking * fix lint issues --- noxfile.py | 2 +- .../test_reports/directives/test_env.py | 4 ++-- sphinxcontrib/test_reports/environment.py | 12 ++++++---- sphinxcontrib/test_reports/test_reports.py | 4 ++-- tests/conftest.py | 22 ++++++++++++++----- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/noxfile.py b/noxfile.py index 3ad6fb3..bb0b81f 100644 --- a/noxfile.py +++ b/noxfile.py @@ -2,7 +2,7 @@ from nox import session PYTHON_VERSIONS = ["3.8", "3.9", "3.10"] -SPHINX_VERSIONS = ["5.0"] +SPHINX_VERSIONS = ["5.0", "6.2.1", "7.1.2", "7.2.5"] TEST_DEPENDENCIES = [ "pytest", "pytest-xdist", diff --git a/sphinxcontrib/test_reports/directives/test_env.py b/sphinxcontrib/test_reports/directives/test_env.py index de05467..dea4ade 100644 --- a/sphinxcontrib/test_reports/directives/test_env.py +++ b/sphinxcontrib/test_reports/directives/test_env.py @@ -5,10 +5,10 @@ import sphinx from docutils import nodes from docutils.parsers.rst import Directive, directives -from pkg_resources import parse_version +from packaging.version import Version sphinx_version = sphinx.__version__ -if parse_version(sphinx_version) >= parse_version("1.6"): +if Version(sphinx_version) >= Version("1.6"): from sphinx.util import logging else: import logging diff --git a/sphinxcontrib/test_reports/environment.py b/sphinxcontrib/test_reports/environment.py index 35e2537..2c37e1f 100644 --- a/sphinxcontrib/test_reports/environment.py +++ b/sphinxcontrib/test_reports/environment.py @@ -1,13 +1,17 @@ import os import sphinx -from pkg_resources import parse_version +from packaging.version import Version + from sphinx.util.console import brown from sphinx.util.osutil import copyfile, ensuredir sphinx_version = sphinx.__version__ -if parse_version(sphinx_version) >= parse_version("1.6"): - from sphinx.util import status_iterator # NOQA Sphinx 1.5 +if Version(sphinx_version) >= Version("1.6"): + if Version(sphinx_version) >= Version("6.1"): + from sphinx.util.display import status_iterator + else: + from sphinx.util import status_iterator # NOQA Sphinx 1.5 STATICS_DIR_NAME = "_static" @@ -80,7 +84,7 @@ def install_styles_static_files(app, env): # Be sure no "old" css layout is already set safe_remove_file("sphinx-test-reports/common.css", app) - if parse_version(sphinx_version) < parse_version("1.6"): + if Version(sphinx_version) < Version("1.6"): global status_iterator status_iterator = app.status_iterator diff --git a/sphinxcontrib/test_reports/test_reports.py b/sphinxcontrib/test_reports/test_reports.py index 25621c9..118c464 100644 --- a/sphinxcontrib/test_reports/test_reports.py +++ b/sphinxcontrib/test_reports/test_reports.py @@ -2,8 +2,8 @@ import os import sphinx +from packaging.version import Version # from docutils import nodes -from pkg_resources import parse_version from sphinx_needs.api import (add_dynamic_function, add_extra_option, add_need_type) @@ -23,7 +23,7 @@ from sphinxcontrib.test_reports.functions import tr_link sphinx_version = sphinx.__version__ -if parse_version(sphinx_version) >= parse_version("1.6"): +if Version(sphinx_version) >= Version("1.6"): from sphinx.util import logging else: import logging diff --git a/tests/conftest.py b/tests/conftest.py index d9fd8d1..584c4b6 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,30 +1,40 @@ """Pytest conftest module containing common test configuration and fixtures.""" import shutil +from pathlib import Path from tempfile import mkdtemp import pytest -from sphinx.testing.path import path +from packaging.version import Version +from sphinx import __version__ as sphinx_version + +if Version(sphinx_version) < Version("7.2"): + from sphinx.testing.path import path + pytest_plugins = "sphinx.testing.fixtures" def copy_srcdir_to_tmpdir(srcdir, tmp): - srcdir = path(__file__).parent.abspath() / srcdir - tmproot = tmp / path(srcdir).basename() + srcdir = Path(__file__).parent.absolute() / srcdir + tmproot = tmp / Path(srcdir).name shutil.copytree(srcdir, tmproot) - return tmproot + return ( + tmproot + if Version(sphinx_version) >= Version("7.2") + else path(tmproot.absolute()) + ) @pytest.fixture(scope="function") def test_app(make_app, request): # We create a temp-folder on our own, as the util-functions from sphinx and pytest make troubles. # It seems like they reuse certain-temp names - sphinx_test_tempdir = path(mkdtemp()) + sphinx_test_tempdir = Path(mkdtemp()) builder_params = request.param # copy plantuml.jar, xml files and json files to current test temdir - util_files = path(__file__).parent.abspath() / "doc_test/utils" + util_files = Path(__file__).parent.absolute() / "doc_test/utils" shutil.copytree(util_files, sphinx_test_tempdir / "utils") # copy test srcdir to test temporary directory sphinx_test_tempdir