From fe11679c1f92052f523662c18482a7acd4f04902 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 19 Dec 2024 10:54:03 -0500 Subject: [PATCH 1/7] fix history checker to look for main not master --- tools/history-update.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/history-update.sh b/tools/history-update.sh index 6fe77a5..f60c01e 100755 --- a/tools/history-update.sh +++ b/tools/history-update.sh @@ -9,7 +9,7 @@ git branch -a # We only look at the files that have changed in the current PR, to # avoid problems when the template is changed in a way that is # incompatible with existing documents. -if git log --name-only --pretty= "origin/master.." -- \ +if git log --name-only --pretty= "origin/main.." -- \ | grep -q '^docs/source/history.rst$'; then echo "Found a change to history file." exit 0 From daa7989cf8f5e0411c2b0a6af42d1ca4468ecad6 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 19 Dec 2024 10:57:07 -0500 Subject: [PATCH 2/7] drop support for python 3.7-3.9 and add 3.12 --- .github/workflows/test.yml | 4 +--- .mergify.yml | 33 +++++++++++++++------------------ pyproject.toml | 26 ++++++-------------------- 3 files changed, 22 insertions(+), 41 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 19f9c44..7f8cef2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,11 +13,9 @@ jobs: fail-fast: false matrix: python-version: - - 3.7 - - 3.8 - - 3.9 - '3.10' - '3.11' + - '3.12' steps: - uses: actions/checkout@v4 diff --git a/.mergify.yml b/.mergify.yml index cc20f5b..b8bab2c 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -1,5 +1,4 @@ pull_request_rules: - - name: Add CI label conditions: - or: @@ -25,23 +24,21 @@ pull_request_rules: - name: Automatic merge on approval conditions: - and: - - "check-success=build (docs)" - - "check-success=build (isolated)" - - "check-success=build (linter)" - - "check-success=build (spelling)" - - "check-success=django" - - "check-success=build (3.7)" - - "check-success=build (3.8)" - - "check-success=build (3.9)" - - "check-success=build (3.10)" - - "check-success=build (3.11)" - - "-draft" - - or: - - "check-success=history-update" - - "label=ci" - - or: - - "approved-reviews-by=dhellmann" - - "author=dhellmann" + - "check-success=build (docs)" + - "check-success=build (isolated)" + - "check-success=build (linter)" + - "check-success=build (spelling)" + - "check-success=django" + - "check-success=build (3.10)" + - "check-success=build (3.11)" + - "check-success=build (3.12)" + - "-draft" + - or: + - "check-success=history-update" + - "label=ci" + - or: + - "approved-reviews-by=dhellmann" + - "author=dhellmann" actions: merge: method: merge diff --git a/pyproject.toml b/pyproject.toml index 153c727..d141dea 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,9 +5,7 @@ build-backend = "setuptools.build_meta" [project] name = "sphinxcontrib-spelling" readme = "README" -authors = [ - {name = "Doug Hellmann", email = "doug@doughellmann.com"}, -] +authors = [{ name = "Doug Hellmann", email = "doug@doughellmann.com" }] description = "Sphinx spelling extension" dynamic = ["version"] @@ -22,30 +20,20 @@ classifiers = [ "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.7", - "Programming Language :: Python :: 3.8", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: Implementation :: CPython", "Topic :: Documentation", "Topic :: Utilities", ] -requires-python = ">=3.7" +requires-python = ">=3.10" -dependencies = [ - "PyEnchant>=3.1.1", - "Sphinx>=3.0.0", - "importlib_metadata>=1.7.0;python_version<'3.8'", -] +dependencies = ["PyEnchant>=3.1.1", "Sphinx>=3.0.0"] [project.optional-dependencies] -test = [ - "pytest", - "pytest-cov", - "coverage!=4.4,>=4.0", -] +test = ["pytest", "pytest-cov", "coverage!=4.4,>=4.0"] [project.entry-points."sphinx.builders"] spelling = "sphinxcontrib.spelling" @@ -61,6 +49,4 @@ write_to = "sphinxcontrib/spelling/version.py" [tool.setuptools] # Be explicit to avoid an error because build finds cover, # sphinxcontrib, and integration_tests as potential packages. -packages = [ - "sphinxcontrib.spelling", -] +packages = ["sphinxcontrib.spelling"] From 585b2f15ecd6dafadaa2dce182aaa7f617b7f588 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 19 Dec 2024 11:01:05 -0500 Subject: [PATCH 3/7] disable extension to use xml-rpc to find pypi package names The XML-RPC interface is discontinued, so stop using it by default. --- docs/source/conf.py | 120 ++++++++++++++++++++++------------------ docs/source/history.rst | 13 +++++ 2 files changed, 78 insertions(+), 55 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 83ed97e..cb73891 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -14,204 +14,209 @@ # 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('.')) # -- General configuration ----------------------------------------------------- # If your documentation needs a minimal Sphinx version, state it here. -#needs_sphinx = '1.0' +# needs_sphinx = '1.0' # Add any Sphinx extension module names here, as strings. They can be extensions # coming with Sphinx (named 'sphinx.ext.*') or your custom ones. extensions = [ - 'sphinxcontrib.spelling', + "sphinxcontrib.spelling", ] spelling_word_list_filename = [ - 'spelling_wordlist.txt', + "spelling_wordlist.txt", ] spelling_show_suggestions = True -spelling_ignore_pypi_package_names = True +spelling_ignore_pypi_package_names = False spelling_ignore_contributor_names = True # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # The suffix of source filenames. -source_suffix = '.rst' +source_suffix = ".rst" # The encoding of source files. -#source_encoding = 'utf-8-sig' +# source_encoding = 'utf-8-sig' # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = 'sphinxcontrib.spelling' -copyright = '2011, Doug Hellmann' +project = "sphinxcontrib.spelling" +copyright = "2011, Doug Hellmann" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = '1.4' +version = "1.4" # The full version, including alpha/beta/rc tags. release = version # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -language = 'en' +language = "en" # There are two options for replacing |today|: either, you set today to some # non-false value, then it is used: -#today = '' +# today = '' # Else, today_fmt is used as the format for a strftime call. -#today_fmt = '%B %d, %Y' +# today_fmt = '%B %d, %Y' # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. exclude_patterns = [] # The reST default role (used for this markup: `text`) to use for all documents. -#default_role = None +# default_role = None # If true, '()' will be appended to :func: etc. cross-reference text. -#add_function_parentheses = True +# add_function_parentheses = True # If true, the current module name will be prepended to all description # unit titles (such as .. function::). -#add_module_names = True +# add_module_names = True # If true, sectionauthor and moduleauthor directives will be shown in the # output. They are ignored by default. -#show_authors = False +# show_authors = False # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # -- Options for HTML output --------------------------------------------------- # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. -html_theme = 'default' +html_theme = "default" # Theme options are theme-specific and customize the look and feel of a theme # further. For a list of options available for each theme, see the # documentation. -#html_theme_options = {} +# html_theme_options = {} # Add any paths that contain custom themes here, relative to this directory. -#html_theme_path = [] +# html_theme_path = [] # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -#html_title = None +# html_title = None # A shorter title for the navigation bar. Default is the same as html_title. -#html_short_title = None +# html_short_title = None # The name of an image file (relative to this directory) to place at the top # of the sidebar. -#html_logo = None +# html_logo = None # The name of an image file (within the static path) to use as favicon of the # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. -#html_favicon = None +# html_favicon = None # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -#html_static_path = ['_static'] +# html_static_path = ['_static'] # If not '', a 'Last updated on:' timestamp is inserted at every page bottom, # using the given strftime format. -#html_last_updated_fmt = '%b %d, %Y' +# html_last_updated_fmt = '%b %d, %Y' # If true, SmartyPants will be used to convert quotes and dashes to # typographically correct entities. -#html_use_smartypants = True +# html_use_smartypants = True # Custom sidebar templates, maps document names to template names. -#html_sidebars = {} +# html_sidebars = {} # Additional templates that should be rendered to pages, maps page names to # template names. -#html_additional_pages = {} +# html_additional_pages = {} # If false, no module index is generated. -#html_domain_indices = True +# html_domain_indices = True # If false, no index is generated. -#html_use_index = True +# html_use_index = True # If true, the index is split into individual pages for each letter. -#html_split_index = False +# html_split_index = False # If true, links to the reST sources are added to the pages. -#html_show_sourcelink = True +# html_show_sourcelink = True # If true, "Created using Sphinx" is shown in the HTML footer. Default is True. -#html_show_sphinx = True +# html_show_sphinx = True # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. -#html_show_copyright = True +# html_show_copyright = True # If true, an OpenSearch description file will be output, and all pages will # contain a tag referring to it. The value of this option must be the # base URL from which the finished HTML is served. -#html_use_opensearch = '' +# html_use_opensearch = '' # This is the file name suffix for HTML files (e.g. ".xhtml"). -#html_file_suffix = None +# html_file_suffix = None # Output file base name for HTML help builder. -htmlhelp_basename = 'sphinxcontribspellingdoc' +htmlhelp_basename = "sphinxcontribspellingdoc" # -- Options for LaTeX output -------------------------------------------------- # The paper size ('letter' or 'a4'). -#latex_paper_size = 'letter' +# latex_paper_size = 'letter' # The font size ('10pt', '11pt' or '12pt'). -#latex_font_size = '10pt' +# latex_font_size = '10pt' # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, author, documentclass [howto/manual]). latex_documents = [ - ('index', 'sphinxcontribspelling.tex', 'sphinxcontrib.spelling Documentation', - 'Doug Hellmann', 'manual'), + ( + "index", + "sphinxcontribspelling.tex", + "sphinxcontrib.spelling Documentation", + "Doug Hellmann", + "manual", + ), ] # The name of an image file (relative to this directory) to place at the top of # the title page. -#latex_logo = None +# latex_logo = None # For "manual" documents, if this is true, then toplevel headings are parts, # not chapters. -#latex_use_parts = False +# latex_use_parts = False # If true, show page references after internal links. -#latex_show_pagerefs = False +# latex_show_pagerefs = False # If true, show URL addresses after external links. -#latex_show_urls = False +# latex_show_urls = False # Additional stuff for the LaTeX preamble. -#latex_preamble = '' +# latex_preamble = '' # Documents to append as an appendix to all manuals. -#latex_appendices = [] +# latex_appendices = [] # If false, no module index is generated. -#latex_domain_indices = True +# latex_domain_indices = True # -- Options for manual page output -------------------------------------------- @@ -219,6 +224,11 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - ('index', 'sphinxcontribspelling', 'sphinxcontrib.spelling Documentation', - ['Doug Hellmann'], 1) + ( + "index", + "sphinxcontribspelling", + "sphinxcontrib.spelling Documentation", + ["Doug Hellmann"], + 1, + ) ] diff --git a/docs/source/history.rst b/docs/source/history.rst index 080ec22..e68c72e 100644 --- a/docs/source/history.rst +++ b/docs/source/history.rst @@ -4,11 +4,24 @@ .. spelling:word-list:: + arg + commandline + config + docstring + emacs + env Homebrew libenchant macOS + namespace + pbr + pyenchant + repo scm setuptools + testrepository + tox + unicode unmaintained Next From 35da0e76119f7601ddd64da33f95288c590e42a5 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 19 Dec 2024 11:06:44 -0500 Subject: [PATCH 4/7] use latest python version in check jobs --- .github/workflows/check.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index f681610..34e92cd 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -26,6 +26,8 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 + with: + python-version: '3.x' - name: Install dependencies run: python -m pip install tox From 4fb2cc8ee204bf68122c114c498d08b49884108c Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 19 Dec 2024 11:15:53 -0500 Subject: [PATCH 5/7] move development dependencies to a requirements file This makes it easier to update the pinned versions using pip freeze output. --- requirements-dev.txt | 7 +++++++ tox.ini | 8 ++------ 2 files changed, 9 insertions(+), 6 deletions(-) create mode 100644 requirements-dev.txt diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..f821fcc --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,7 @@ +astpretty==2.1.0 +flake8==7.1.1 +flake8-debug==0.2.0 +isort==5.13.2 +mccabe==0.7.0 +pycodestyle==2.12.1 +pyflakes==3.2.0 diff --git a/tox.ini b/tox.ini index 4a29251..76edfd6 100644 --- a/tox.ini +++ b/tox.ini @@ -34,17 +34,13 @@ commands= --log-level DEBUG [testenv:style] -deps = - isort>=5.0.1 +deps = -r requirements-dev.txt commands = isort . skip_install = true [testenv:linter] -deps= - flake8==4.0.1 - flake8-debug==0.1.0 - isort>=5.0.1 +deps = -r requirements-dev.txt setenv = BUILD=linter commands = From 596dfc2521c925ee5d0cdbd9e2fb8df2c3f38f4c Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 19 Dec 2024 11:31:22 -0500 Subject: [PATCH 6/7] switch linter to ruff --- requirements-dev.txt | 8 +- tests/test_builder.py | 386 +++++++++++++++++++++++++++--------------- tests/test_checker.py | 62 +++---- tox.ini | 9 +- 4 files changed, 288 insertions(+), 177 deletions(-) diff --git a/requirements-dev.txt b/requirements-dev.txt index f821fcc..af3ee57 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,7 +1 @@ -astpretty==2.1.0 -flake8==7.1.1 -flake8-debug==0.2.0 -isort==5.13.2 -mccabe==0.7.0 -pycodestyle==2.12.1 -pyflakes==3.2.0 +ruff diff --git a/tests/test_builder.py b/tests/test_builder.py index d76c305..25c4155 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -1,8 +1,8 @@ # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # -"""Tests for SpellingBuilder -""" +"""Tests for SpellingBuilder""" + import contextlib import io import os @@ -10,18 +10,21 @@ import textwrap import pytest -import sphinx from sphinx.application import Sphinx from tests import helpers # isort:skip def _make_sphinx_project(tmpdir): - srcdir = tmpdir.mkdir('src') - outdir = tmpdir.mkdir('out') - add_file(srcdir, 'conf.py', ''' + srcdir = tmpdir.mkdir("src") + outdir = tmpdir.mkdir("out") + add_file( + srcdir, + "conf.py", + """ extensions = [ 'sphinxcontrib.spelling' ] - ''') + """, + ) return (srcdir, outdir) @@ -53,27 +56,32 @@ def import_path(new_path): def add_file(thedir, filename, content): - with open(thedir.join(filename), 'w') as f: + with open(thedir.join(filename), "w") as f: f.write(textwrap.dedent(content)) -def get_sphinx_app(srcdir, outdir, docname, builder='spelling'): +def get_sphinx_app(srcdir, outdir, docname, builder="spelling"): stdout = io.StringIO() stderr = io.StringIO() app = Sphinx( - srcdir, srcdir, outdir, outdir, builder, - status=stdout, warning=stderr, + srcdir, + srcdir, + outdir, + outdir, + builder, + status=stdout, + warning=stderr, freshenv=True, ) return (stdout, stderr, app) -def get_sphinx_output(srcdir, outdir, docname, builder='spelling'): +def get_sphinx_output(srcdir, outdir, docname, builder="spelling"): stdout, stderr, app = get_sphinx_app(srcdir, outdir, docname, builder) app.build() - path = os.path.join(outdir, f'{docname}.spelling') + path = os.path.join(outdir, f"{docname}.spelling") try: - with open(path, 'r') as f: + with open(path, "r") as f: output_text = f.read() except FileNotFoundError: output_text = None @@ -88,38 +96,54 @@ def test_setup(sphinx_project): # trying to use it with the Sphinx app class will # generate an exception. Sphinx( - str(srcdir), str(srcdir), str(outdir), str(outdir), 'spelling', - status=stdout, warning=stderr, + str(srcdir), + str(srcdir), + str(outdir), + str(outdir), + "spelling", + status=stdout, + warning=stderr, freshenv=True, ) def test_title(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ Welcome to Speeling Checker documentation! ========================================== - ''') - stdout, stderr, output_text = get_sphinx_output(srcdir, outdir, 'contents') - assert '(Speeling)' in output_text + """, + ) + stdout, stderr, output_text = get_sphinx_output(srcdir, outdir, "contents") + assert "(Speeling)" in output_text def test_body(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ Welcome to Spelling Checker documentation! ========================================== There are several mispelled words in this txt. - ''') - stdout, stderr, output_text = get_sphinx_output(srcdir, outdir, 'contents') - assert '(mispelled)' in output_text - assert '(txt)' in output_text + """, + ) + stdout, stderr, output_text = get_sphinx_output(srcdir, outdir, "contents") + assert "(mispelled)" in output_text + assert "(txt)" in output_text def test_ignore_literals(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ Welcome to Spelling Checker documentation! ========================================== @@ -131,8 +155,9 @@ def test_ignore_literals(sphinx_project): Inline ``litterals`` are ignored, too. - ''') - stdout, stderr, output_text = get_sphinx_output(srcdir, outdir, 'contents') + """, + ) + stdout, stderr, output_text = get_sphinx_output(srcdir, outdir, "contents") # The 'contents.spelling' output file should not have been # created, because the errors are ignored. assert output_text is None @@ -140,69 +165,93 @@ def test_ignore_literals(sphinx_project): def test_several_word_lists(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'conf.py', ''' + add_file( + srcdir, + "conf.py", + """ extensions = ['sphinxcontrib.spelling'] spelling_word_list_filename=['test_wordlist.txt','test_wordlist2.txt'] - ''') + """, + ) - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ Welcome to Spelling Checker documentation! ========================================== There are several mispelled words in tihs txt. - ''') + """, + ) - add_file(srcdir, 'test_wordlist.txt', ''' + add_file( + srcdir, + "test_wordlist.txt", + """ txt - ''') + """, + ) - add_file(srcdir, 'test_wordlist2.txt', ''' + add_file( + srcdir, + "test_wordlist2.txt", + """ mispelled - ''') - stdout, stderr, output_text = get_sphinx_output(srcdir, outdir, 'contents') + """, + ) + stdout, stderr, output_text = get_sphinx_output(srcdir, outdir, "contents") # Both of these should be fine now - assert '(mispelled)' not in output_text - assert '(txt)' not in output_text + assert "(mispelled)" not in output_text + assert "(txt)" not in output_text # But not this one - assert '(tihs)' in output_text + assert "(tihs)" in output_text def _wordlist_sphinx_project(tmpdir, conf_contents): srcdir, outdir = _make_sphinx_project(tmpdir) - add_file(srcdir, 'conf.py', conf_contents) - add_file(srcdir, 'test_wordlist.txt', ''' + add_file(srcdir, "conf.py", conf_contents) + add_file( + srcdir, + "test_wordlist.txt", + """ txt - ''') - add_file(srcdir, 'test_wordlist2.txt', ''' + """, + ) + add_file( + srcdir, + "test_wordlist2.txt", + """ mispelled - ''') - stdout, stderr, app = get_sphinx_app(srcdir, outdir, 'contents') + """, + ) + stdout, stderr, app = get_sphinx_app(srcdir, outdir, "contents") return (srcdir, outdir, stdout, stderr, app) def test_word_list_default(tmpdir): srcdir, outdir, stdout, stderr, app = _wordlist_sphinx_project( tmpdir, - ''' + """ extensions = ['sphinxcontrib.spelling'] - ''', + """, ) results = app.builder.get_configured_wordlist_filenames() assert len(results) == 1 - assert os.path.basename(results[0]) == 'spelling_wordlist.txt' + assert os.path.basename(results[0]) == "spelling_wordlist.txt" def test_one_word_list_str(tmpdir): srcdir, outdir, stdout, stderr, app = _wordlist_sphinx_project( tmpdir, - ''' + """ extensions = ['sphinxcontrib.spelling'] spelling_word_list_filename='test_wordlist.txt' - ''', + """, ) results = app.builder.get_configured_wordlist_filenames() assert len(results) == 1 - assert os.path.basename(results[0]) == 'test_wordlist.txt' + assert os.path.basename(results[0]) == "test_wordlist.txt" def test_multiple_word_list_str(tmpdir): @@ -211,44 +260,52 @@ def test_multiple_word_list_str(tmpdir): # using -D. srcdir, outdir, stdout, stderr, app = _wordlist_sphinx_project( tmpdir, - ''' + """ extensions = ['sphinxcontrib.spelling'] spelling_word_list_filename='test_wordlist.txt,test_wordlist2.txt' - ''', + """, ) results = app.builder.get_configured_wordlist_filenames() assert len(results) == 2 - assert os.path.basename(results[0]) == 'test_wordlist.txt' - assert os.path.basename(results[1]) == 'test_wordlist2.txt' + assert os.path.basename(results[0]) == "test_wordlist.txt" + assert os.path.basename(results[1]) == "test_wordlist2.txt" def test_multiple_word_list_list(tmpdir): srcdir, outdir, stdout, stderr, app = _wordlist_sphinx_project( tmpdir, - ''' + """ extensions = ['sphinxcontrib.spelling'] spelling_word_list_filename=['test_wordlist.txt', 'test_wordlist2.txt'] - ''', + """, ) results = app.builder.get_configured_wordlist_filenames() assert len(results) == 2 - assert os.path.basename(results[0]) == 'test_wordlist.txt' - assert os.path.basename(results[1]) == 'test_wordlist2.txt' + assert os.path.basename(results[0]) == "test_wordlist.txt" + assert os.path.basename(results[1]) == "test_wordlist2.txt" def test_ignore_file(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'conf.py', ''' + add_file( + srcdir, + "conf.py", + """ extensions = ['sphinxcontrib.spelling'] spelling_exclude_patterns=['con*'] - ''') + """, + ) - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ Welcome to Speeling Checker documentation! ========================================== - ''') + """, + ) - stdout, stderr, output_text = get_sphinx_output(srcdir, outdir, 'contents') + stdout, stderr, output_text = get_sphinx_output(srcdir, outdir, "contents") # The 'contents.spelling' output file should not have been # created, because the file is ignored. assert output_text is None @@ -258,11 +315,18 @@ def test_ignore_file(sphinx_project): def test_docstrings(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'conf.py', ''' + add_file( + srcdir, + "conf.py", + """ extensions = ['sphinxcontrib.spelling', 'sphinx.ext.autodoc'] - ''') + """, + ) - add_file(srcdir / '..', 'the_source.py', ''' + add_file( + srcdir / "..", + "the_source.py", + ''' #!/usr/bin/env python3 def public_function(arg_name): @@ -271,81 +335,100 @@ def public_function(arg_name): :param arg_name: Pass a vaule """ return 1 - ''') + ''', + ) - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ The Module ========== .. automodule:: the_source :members: - ''') + """, + ) - with working_dir(srcdir / '..'): - with import_path(['.'] + sys.path): + with working_dir(srcdir / ".."): + with import_path(["."] + sys.path): stdout, stderr, output_text = get_sphinx_output( srcdir, outdir, - 'contents', + "contents", ) # Sphinx 5.1.0 and later reports line numbers for docstring # content. - line_num = 'None:' + line_num = "None:" if sphinx.version_info[:3] >= (5, 1, 0): - line_num = '1:' + line_num = "1:" # Expected string is too long for one line expected = ( - 'the_source.py:' - 'docstring of the_source.public_function:' - ) + line_num + ( - ' (vaule)' + ("the_source.py:" "docstring of the_source.public_function:") + + line_num + + (" (vaule)") ) assert expected in output_text def test_get_suggestions_to_show_all(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'conf.py', ''' + add_file( + srcdir, + "conf.py", + """ extensions = ['sphinxcontrib.spelling'] spelling_show_suggestions = True spelling_suggestion_limit = 0 - ''') - stdout, stderr, app = get_sphinx_app(srcdir, outdir, 'contents') - results = app.builder.get_suggestions_to_show(['a', 'b', 'c']) + """, + ) + stdout, stderr, app = get_sphinx_app(srcdir, outdir, "contents") + results = app.builder.get_suggestions_to_show(["a", "b", "c"]) assert len(results) == 3 def test_get_suggestions_to_show_limit(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'conf.py', ''' + add_file( + srcdir, + "conf.py", + """ extensions = ['sphinxcontrib.spelling'] spelling_show_suggestions = True spelling_suggestion_limit = 1 - ''') - stdout, stderr, app = get_sphinx_app(srcdir, outdir, 'contents') - results = app.builder.get_suggestions_to_show(['a', 'b', 'c']) + """, + ) + stdout, stderr, app = get_sphinx_app(srcdir, outdir, "contents") + results = app.builder.get_suggestions_to_show(["a", "b", "c"]) assert len(results) == 1 def test_get_suggestions_to_show_disabled(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'conf.py', ''' + add_file( + srcdir, + "conf.py", + """ extensions = ['sphinxcontrib.spelling'] spelling_show_suggestions = False spelling_suggestion_limit = 0 - ''') - stdout, stderr, app = get_sphinx_app(srcdir, outdir, 'contents') - results = app.builder.get_suggestions_to_show(['a', 'b', 'c']) + """, + ) + stdout, stderr, app = get_sphinx_app(srcdir, outdir, "contents") + results = app.builder.get_suggestions_to_show(["a", "b", "c"]) assert len(results) == 0 def test_captions(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ The Module ========== @@ -353,20 +436,24 @@ def test_captions(sphinx_project): Teh caption - ''') + """, + ) stdout, stderr, output_text = get_sphinx_output( srcdir, outdir, - 'contents', + "contents", ) - assert '(Teh)' in output_text + assert "(Teh)" in output_text def test_legacy_directive(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ The Module ========== @@ -376,12 +463,13 @@ def test_legacy_directive(sphinx_project): teh is OK - ''') + """, + ) stdout, stderr, output_text = get_sphinx_output( srcdir, outdir, - 'contents', + "contents", ) assert output_text is None @@ -389,7 +477,10 @@ def test_legacy_directive(sphinx_project): def test_domain_directive(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ The Module ========== @@ -399,12 +490,13 @@ def test_domain_directive(sphinx_project): teh is OK - ''') + """, + ) stdout, stderr, output_text = get_sphinx_output( srcdir, outdir, - 'contents', + "contents", ) assert output_text is None @@ -412,18 +504,22 @@ def test_domain_directive(sphinx_project): def test_domain_role(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ The Module ========== :spelling:word:`teh` is OK - ''') + """, + ) stdout, stderr, output_text = get_sphinx_output( srcdir, outdir, - 'contents', + "contents", ) assert output_text is None @@ -431,18 +527,22 @@ def test_domain_role(sphinx_project): def test_domain_role_multiple_words(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ The Module ========== :spelling:word:`teh is KO` - ''') + """, + ) stdout, stderr, output_text = get_sphinx_output( srcdir, outdir, - 'contents', + "contents", ) assert output_text is None @@ -450,24 +550,28 @@ def test_domain_role_multiple_words(sphinx_project): def test_domain_role_output(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ The Module ========== :spelling:word:`teh` is OK - ''') + """, + ) stdout, stderr, output_text = get_sphinx_output( srcdir, outdir, - 'contents', - 'text', + "contents", + "text", ) - path = os.path.join(outdir, 'contents.txt') + path = os.path.join(outdir, "contents.txt") try: - with open(path, 'r') as f: + with open(path, "r") as f: output_text = f.read() except FileNotFoundError: output_text = None @@ -478,18 +582,22 @@ def test_domain_role_output(sphinx_project): def test_domain_ignore(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ The Module ========== :spelling:ignore:`baddddd` is OK - ''') + """, + ) stdout, stderr, output_text = get_sphinx_output( srcdir, outdir, - 'contents', + "contents", ) assert output_text is None @@ -497,7 +605,10 @@ def test_domain_ignore(sphinx_project): def test_domain_ignore_multiple_words(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ The Module ========== @@ -506,38 +617,43 @@ def test_domain_ignore_multiple_words(sphinx_project): But, baddddd is not OK here. Nor, here baddddd. - ''') + """, + ) stdout, stderr, output_text = get_sphinx_output( srcdir, outdir, - 'contents', + "contents", ) - assert '(baddddd)' in output_text - assert output_text.count('\n') == 2 # Only expect 2 errors, not 3. + assert "(baddddd)" in output_text + assert output_text.count("\n") == 2 # Only expect 2 errors, not 3. def test_domain_ignore_output(sphinx_project): srcdir, outdir = sphinx_project - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ The Module ========== :spelling:ignore:`teh` is OK - ''') + """, + ) stdout, stderr, output_text = get_sphinx_output( srcdir, outdir, - 'contents', - 'text', + "contents", + "text", ) - path = os.path.join(outdir, 'contents.txt') + path = os.path.join(outdir, "contents.txt") try: - with open(path, 'r') as f: + with open(path, "r") as f: output_text = f.read() except FileNotFoundError: output_text = None @@ -550,7 +666,10 @@ def test_only_directive(sphinx_project): # https://github.com/sphinx-contrib/spelling/issues/204 srcdir, outdir = sphinx_project - add_file(srcdir, 'contents.rst', ''' + add_file( + srcdir, + "contents.rst", + """ The Module ========== @@ -559,12 +678,13 @@ def test_only_directive(sphinx_project): teh is ok whaat is not ok - ''') + """, + ) stdout, stderr, output_text = get_sphinx_output( srcdir, outdir, - 'contents', + "contents", ) - assert '(whaat)' in output_text - assert '(teh)' not in output_text + assert "(whaat)" in output_text + assert "(teh)" not in output_text diff --git a/tests/test_checker.py b/tests/test_checker.py index 49b63e5..eeb48af 100644 --- a/tests/test_checker.py +++ b/tests/test_checker.py @@ -1,8 +1,7 @@ # # Copyright (c) 2010 Doug Hellmann. All rights reserved. # -"""Tests for SpellingChecker. -""" +"""Tests for SpellingChecker.""" import os @@ -10,50 +9,55 @@ def test_errors_only(): - checker = SpellingChecker(lang='en_US', - suggest=False, - word_list_filename=None, - ) - for word, suggestions, line, offset in checker.check('This txt is wrong'): - assert not suggestions, 'Suggesting' - assert word == 'txt' + checker = SpellingChecker( + lang="en_US", + suggest=False, + word_list_filename=None, + ) + for word, suggestions, line, offset in checker.check("This txt is wrong"): + assert not suggestions, "Suggesting" + assert word == "txt" assert line == "" assert offset == 0 def test_with_suggestions(): - checker = SpellingChecker(lang='en_US', - suggest=True, - word_list_filename=None, - ) - for word, suggestions, line, offset in checker.check('This txt is wrong'): - assert suggestions, 'Not suggesting' - assert word == 'txt' + checker = SpellingChecker( + lang="en_US", + suggest=True, + word_list_filename=None, + ) + for word, suggestions, line, offset in checker.check("This txt is wrong"): + assert suggestions, "Not suggesting" + assert word == "txt" assert line == "" assert offset == 0 + def test_with_wordlist(): checker = SpellingChecker( - lang='en_US', + lang="en_US", suggest=False, - word_list_filename=os.path.join(os.path.dirname(__file__), - 'test_wordlist.txt') + word_list_filename=os.path.join(os.path.dirname(__file__), "test_wordlist.txt"), ) - words = [w for w, s, l, o in checker.check('This txt is wrong')] - assert not words, 'Did not use personal word list file' + words = [ + word for word, suggestions, line, offset in checker.check("This txt is wrong") + ] + assert not words, "Did not use personal word list file" def test_with_context_line(): - checker = SpellingChecker(lang='en_US', - suggest=False, - word_list_filename=None, - context_line=True, - ) + checker = SpellingChecker( + lang="en_US", + suggest=False, + word_list_filename=None, + context_line=True, + ) - text = 'Line one\nThis txt is wrong\nLine two' + text = "Line one\nThis txt is wrong\nLine two" for word, suggestions, line, offset in checker.check(text): - assert not suggestions, 'Suggesting' - assert word == 'txt' + assert not suggestions, "Suggesting" + assert word == "txt" assert line == "This txt is wrong" assert offset == 1 diff --git a/tox.ini b/tox.ini index 76edfd6..f323c92 100644 --- a/tox.ini +++ b/tox.ini @@ -33,19 +33,12 @@ commands= --cov-report term-missing \ --log-level DEBUG -[testenv:style] -deps = -r requirements-dev.txt -commands = - isort . -skip_install = true - [testenv:linter] deps = -r requirements-dev.txt setenv = BUILD=linter commands = - flake8 sphinxcontrib integration_tests - isort --check --diff . + ruff check sphinxcontrib integration_tests tests skip_install = true [testenv:pkglint] From b86d87a9ee05f1121af7bc15b43133b555c3d554 Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 19 Dec 2024 11:25:09 -0500 Subject: [PATCH 7/7] fix docstring test The logic for finding the docstring line number seems to no longer work. --- tests/test_builder.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/tests/test_builder.py b/tests/test_builder.py index 25c4155..8380b0a 100644 --- a/tests/test_builder.py +++ b/tests/test_builder.py @@ -359,18 +359,7 @@ def public_function(arg_name): "contents", ) - # Sphinx 5.1.0 and later reports line numbers for docstring - # content. - line_num = "None:" - if sphinx.version_info[:3] >= (5, 1, 0): - line_num = "1:" - - # Expected string is too long for one line - expected = ( - ("the_source.py:" "docstring of the_source.public_function:") - + line_num - + (" (vaule)") - ) + expected = "src/contents.rst:3: (vaule) Pass a vaule\n" assert expected in output_text