jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/853249 )
Change subject: [doc] Use Python 3.7 as basepython for doc tests ......................................................................
[doc] Use Python 3.7 as basepython for doc tests
doc tests is running sphinx and rstcheck but rstcheck throws a warning: /src/.tox/doc/lib/python3.6/site-packages/rstcheck.py:51: FutureWarning: Python versions prior 3.7 are deprecated. Please update your python
- Therefore use Python 3.7 for doc tests note: this is different from doctest test which runs Python doctest) - but also determine whether sphinx is running in backports.py to include its changes. - update documentation - update config string - update requirements
Change-Id: I47f103e9a2f34ce819fda41959f7bc69e801a2da --- M .codecov.yml M docs/requirements.txt M pywikibot/backports.py M tox.ini 4 files changed, 42 insertions(+), 18 deletions(-)
Approvals: Xqt: Looks good to me, approved jenkins-bot: Verified
diff --git a/.codecov.yml b/.codecov.yml index 22f8396..8823dfc 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -18,7 +18,6 @@ enabled: yes
ignore: - - pywikibot/backports.py - pywikibot/daemonize.py - pywikibot/families/__init__.py - pywikibot/scripts/preload_sites.py diff --git a/docs/requirements.txt b/docs/requirements.txt index 57f3cda..ac449c1 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,4 +2,4 @@ # requirements.txt is also needed
sphinx >= 5.2.3 -rstcheck >=3.5.0 \ No newline at end of file +rstcheck >=6.1.0 \ No newline at end of file diff --git a/pywikibot/backports.py b/pywikibot/backports.py index 9773ac6..d68e49c 100644 --- a/pywikibot/backports.py +++ b/pywikibot/backports.py @@ -9,6 +9,7 @@
PYTHON_VERSION = sys.version_info[:3] +SPHINX_RUNNING = 'sphinx' in sys.modules
# functools.cache if PYTHON_VERSION >= (3, 9): @@ -19,19 +20,24 @@
# context -if PYTHON_VERSION < (3, 7): +if PYTHON_VERSION < (3, 7) or SPHINX_RUNNING:
class nullcontext: # noqa: N801
- """Dummy context manager for Python 3.5/3.6 that does nothing.""" + """Context manager that does no additional processing.
- def __init__(self, result: Any = None) -> None: # noqa: D107 - self.result = result + .. seealso:: :python:`contextlib.nullcontext + <library/contextlib.html#contextlib.nullcontext>`, + backported from Python 3.7. + """ + + def __init__(self, enter_result: Any = None) -> None: # noqa: D107 + self.enter_result = enter_result
def __enter__(self) -> Any: - return self.result + return self.enter_result
- def __exit__(self, *args: Any) -> None: + def __exit__(self, *excinfo: Any) -> None: pass else: from contextlib import nullcontext # type: ignore[misc] @@ -102,13 +108,18 @@
# PEP 616 string methods -if PYTHON_VERSION >= (3, 9): - removeprefix = str.removeprefix # type: ignore[attr-defined] - removesuffix = str.removesuffix # type: ignore[attr-defined] -else: +if PYTHON_VERSION < (3, 9) or SPHINX_RUNNING: def removeprefix(string: str, prefix: str) -> str: # skipcq: TYP-053 """Remove prefix from a string or return a copy otherwise.
+ >>> removeprefix('TestHook', 'Test') + 'Hook' + >>> removeprefix('BaseTestCase', 'Test') + 'BaseTestCase' + + .. seealso:: :python:`str.removeprefix + <library/stdtypes.html#str.removeprefix>`, + backported from Python 3.9. .. versionadded:: 5.4 """ if string.startswith(prefix): @@ -116,26 +127,40 @@ return string
def removesuffix(string: str, suffix: str) -> str: # skipcq: TYP-053 - """Remove prefix from a string or return a copy otherwise. + """Remove suffix from a string or return a copy otherwise.
+ >>> removesuffix('MiscTests', 'Tests') + 'Misc' + >>> removesuffix('TmpDirMixin', 'Tests') + 'TmpDirMixin' + + .. seealso:: :python:`str.removesuffix + <library/stdtypes.html#str.removesuffix>`, + backported from Python 3.9. .. versionadded:: 5.4 """ if string.endswith(suffix): return string[:-len(suffix)] return string +else: + removeprefix = str.removeprefix # type: ignore[attr-defined] + removesuffix = str.removesuffix # type: ignore[attr-defined]
# bpo-38200 -if PYTHON_VERSION >= (3, 10): - from itertools import pairwise -else: +if PYTHON_VERSION < (3, 10) or SPHINX_RUNNING: from itertools import tee
def pairwise(iterable): """Return successive overlapping pairs taken from the input iterable.
+ .. seealso:: :python:`itertools.pairwise + <library/itertools.html#itertools.pairwise>`, + backported from Python 3.10. .. versionadded:: 7.6 """ a, b = tee(iterable) next(b, None) return zip(a, b) +else: + from itertools import pairwise diff --git a/tox.ini b/tox.ini index 5d25e64..9f83c57 100644 --- a/tox.ini +++ b/tox.ini @@ -84,8 +84,8 @@ [testenv:doc] commands = sphinx-build -M html ./docs ./docs/_build - rstcheck --recursive --report warning --ignore-roles api,phab . -basepython = python3.6 + rstcheck -r --report-level WARNING --ignore-roles api,phab . +basepython = python3.7 deps = -rrequirements.txt -rdocs/requirements.txt