Modernize extension

- update dependencies
- use tox for testing
- use type hints
- use pathlib and ipaddress from standard library instead of path and
  ipcalc
- fix Sphinx deprecation warnings
This commit is contained in:
Jan Dittberner 2023-01-28 17:43:04 +01:00
parent c721d1bf9c
commit 7c675a6fdb
13 changed files with 801 additions and 465 deletions

View file

@ -12,14 +12,14 @@
#
# All configuration values have a default; values that are commented out
# serve to show the default.
# import sys
# import os
import os
import sys
from typing import Dict
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
# sys.path.insert(0, os.path.abspath('..'))
sys.path.insert(0, os.path.abspath(os.path.join("..", "..")))
# -- General configuration ------------------------------------------------
@ -47,7 +47,7 @@ master_doc = "index"
# General information about the project.
project = "Sphinxext IP Tests"
copyright = "2016-2021, Jan Dittberner"
copyright = "2016-2023, Jan Dittberner"
author = "Jan Dittberner"
# The version info for the project you're documenting, acts as replacement for
@ -104,7 +104,6 @@ pygments_style = "sphinx"
# If true, `todo` and `todoList` produce output, else they produce nothing.
todo_include_todos = False
# -- Options for HTML output ----------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
@ -207,15 +206,15 @@ htmlhelp_basename = "SphinxextIPTestsdoc"
# -- Options for LaTeX output ---------------------------------------------
latex_elements = {
latex_elements: Dict[str, str] = {
# The paper size ('letterpaper' or 'a4paper').
#'papersize': 'letterpaper',
# 'papersize': 'letterpaper',
# The font size ('10pt', '11pt' or '12pt').
#'pointsize': '10pt',
# 'pointsize': '10pt',
# Additional stuff for the LaTeX preamble.
#'preamble': '',
# 'preamble': '',
# Latex figure (float) alignment
#'figure_align': 'htbp',
# 'figure_align': 'htbp',
}
# Grouping the document tree into LaTeX files. List of tuples

View file

@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
import shutil
import unittest
from io import StringIO
@ -23,7 +23,7 @@ class TestIPExtension(unittest.TestCase):
def tearDown(self):
self.app.cleanup()
(test_root / "_build").rmtree(True)
shutil.rmtree((test_root / "_build"))
def test_ip_domaindata(self):
self.assertIn("ip", self.app.env.domaindata)

View file

@ -12,8 +12,8 @@ import shutil
import sys
import tempfile
from functools import wraps
from pathlib import Path
from path import Path
from sphinx import application
__all__ = [
@ -25,14 +25,13 @@ __all__ = [
"SphinxTestApplication",
"with_app",
"gen_with_app",
"Path",
"with_tempdir",
"write_file",
"sprint",
]
test_root = Path(__file__).parent.joinpath("root").abspath()
test_root = Path(__file__).parent.joinpath("root").absolute()
def _excstr(exc):
@ -96,9 +95,9 @@ class SphinxTestApplication(application.Sphinx):
def __init__(
self,
srcdir=None,
src_dir=None,
confdir=None,
outdir=None,
out_dir=None,
doctreedir=None,
buildername="html",
confoverrides=None,
@ -115,26 +114,26 @@ class SphinxTestApplication(application.Sphinx):
self.cleanup_trees = [test_root / "generated"]
if srcdir is None:
srcdir = test_root
if srcdir == "(temp)":
if src_dir is None:
src_dir = test_root
if src_dir == "(temp)":
tempdir = Path(tempfile.mkdtemp())
self.cleanup_trees.append(tempdir)
temproot = tempdir / "root"
test_root.copytree(temproot)
srcdir = temproot
temp_root = tempdir / "root"
shutil.copytree(test_root.resolve(), temp_root.resolve())
src_dir = temp_root
else:
srcdir = Path(srcdir)
self.builddir = srcdir.joinpath("_build")
src_dir = Path(src_dir)
self.builddir = src_dir.joinpath("_build")
if confdir is None:
confdir = srcdir
if outdir is None:
outdir = srcdir.joinpath(self.builddir, buildername)
if not outdir.isdir():
outdir.makedirs()
self.cleanup_trees.insert(0, outdir)
confdir = src_dir
if out_dir is None:
out_dir = src_dir.joinpath(self.builddir, buildername)
if not out_dir.is_dir():
out_dir.mkdir(parents=True)
self.cleanup_trees.insert(0, out_dir)
if doctreedir is None:
doctreedir = srcdir.joinpath(srcdir, self.builddir, "doctrees")
doctreedir = src_dir.joinpath(src_dir, self.builddir, "doctrees")
if cleanenv:
self.cleanup_trees.insert(0, doctreedir)
if confoverrides is None:
@ -150,9 +149,9 @@ class SphinxTestApplication(application.Sphinx):
application.Sphinx.__init__(
self,
srcdir,
str(src_dir),
confdir,
outdir,
out_dir,
doctreedir,
buildername,
confoverrides,
@ -211,7 +210,7 @@ def with_tempdir(func):
def new_func():
tempdir = Path(tempfile.mkdtemp())
func(tempdir)
tempdir.rmtree()
tempdir.rmdir()
new_func.__name__ = func.__name__
return new_func