diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..325ae0e --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,33 @@ +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/c-code +name: pre-commit + +on: + pull_request: + push: + branches: + - master + # Allow to run this workflow manually from the Actions tab + workflow_dispatch: + +env: + FORCE_COLOR: 1 + +jobs: + pre-commit: + name: linting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: 3.x + - uses: pre-commit/action@v3.0.1 + with: + extra_args: --all-files --show-diff-on-failure + env: + PRE_COMMIT_COLOR: always + - uses: pre-commit-ci/lite-action@v1.0.2 + if: always() + with: + msg: Apply pre-commit code formatting diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5a9a697..9d8968a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -9,7 +9,7 @@ # Original comment follows. ### ### -# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# This workflow will install Python dependencies, run tests with a variety of Python versions # For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions ### @@ -81,7 +81,7 @@ jobs: # other people to test/debug), the strategy is to divide the process # into several different jobs. The first builds and saves the binary # wheels. It has dependent jobs that download and install the wheel - # to run tests, build docs, and perform linting. Building the + # to run tests, and build docs. Building the # manylinux wheels is an independent set of jobs. # # This division is time-saving for projects that take awhile to @@ -156,14 +156,13 @@ jobs: if: matrix.python-version == '3.13' run: | pip install -U pip - pip install -U "setuptools<69" wheel twine - # Remove this hack once 'cffi' has a release supporting Python 3.13. - pip install -e "git+https://github.com/python-cffi/cffi.git#egg=cffi" + pip install -U --pre cffi + pip install -U "setuptools<74" wheel twine - name: Install Build Dependencies if: matrix.python-version != '3.13' run: | pip install -U pip - pip install -U "setuptools<69" wheel twine + pip install -U "setuptools<74" wheel twine pip install cffi - name: Build zope.index (macOS x86_64) @@ -327,12 +326,11 @@ jobs: with: name: zope.index-${{ runner.os }}-${{ matrix.python-version }}.whl path: dist/ - - name: Install zope.index 3.13 ${{ matrix.python-version }} + - name: Install zope.index ${{ matrix.python-version }} if: matrix.python-version == '3.13' run: | - pip install -U wheel "setuptools<69" - # Remove this hack once 'cffi' has a release supporting Python 3.13. - pip install -e "git+https://github.com/python-cffi/cffi.git#egg=cffi" + pip install -U --pre cffi + pip install -U wheel "setuptools<74" # coverage might have a wheel on PyPI for a future python version which is # not ABI compatible with the current one, so build it from sdist: pip install -U --no-binary :all: coverage @@ -342,18 +340,18 @@ jobs: unzip -n dist/zope.index-*whl -d src # Use "--pre" here because dependencies with support for this future # Python release may only be available as pre-releases - pip install --pre -U -e .[test] + pip install --pre -e .[test] - name: Install zope.index if: matrix.python-version != '3.13' run: | - pip install -U wheel "setuptools<69" + pip install -U wheel "setuptools<74" pip install -U coverage pip install -U 'cffi; platform_python_implementation == "CPython"' # Unzip into src/ so that testrunner can find the .so files # when we ask it to load tests from that directory. This # might also save some build time? unzip -n dist/zope.index-*whl -d src - pip install -U -e .[test] + pip install -e .[test] - name: Run tests with C extensions if: ${{ !startsWith(matrix.python-version, 'pypy') }} run: | @@ -389,7 +387,7 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - python-version: ["3.9"] + python-version: ["3.11"] os: [ubuntu-latest] steps: @@ -453,80 +451,13 @@ jobs: sphinx-build -b html -d docs/_build/doctrees docs docs/_build/html sphinx-build -b doctest -d docs/_build/doctrees docs docs/_build/doctest - lint: - needs: build-package - runs-on: ${{ matrix.os }} - strategy: - matrix: - python-version: ["3.9"] - os: [ubuntu-latest] - - steps: - - name: checkout - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} - allow-prereleases: true - ### - # Caching. - # This actually *restores* a cache and schedules a cleanup action - # to save the cache. So it must come before the thing we want to use - # the cache. - ### - - name: Get pip cache dir (default) - id: pip-cache-default - if: ${{ !startsWith(runner.os, 'Windows') }} - run: | - echo "dir=$(pip cache dir)" >>$GITHUB_OUTPUT - - - name: Get pip cache dir (Windows) - id: pip-cache-windows - if: ${{ startsWith(runner.os, 'Windows') }} - run: | - echo "dir=$(pip cache dir)" >> $Env:GITHUB_OUTPUT - - - name: pip cache (default) - uses: actions/cache@v4 - if: ${{ !startsWith(runner.os, 'Windows') }} - with: - path: ${{ steps.pip-cache-default.outputs.dir }} - key: ${{ runner.os }}-pip-${{ matrix.python-version }} - restore-keys: | - ${{ runner.os }}-pip- - - - name: pip cache (Windows) - uses: actions/cache@v4 - if: ${{ startsWith(runner.os, 'Windows') }} - with: - path: ${{ steps.pip-cache-windows.outputs.dir }} - key: ${{ runner.os }}-pip-${{ matrix.python-version }} - restore-keys: | - ${{ runner.os }}-pip- - - - name: Download zope.index wheel - uses: actions/download-artifact@v4 - with: - name: zope.index-${{ runner.os }}-${{ matrix.python-version }}.whl - path: dist/ - - name: Install zope.index - run: | - pip install -U pip - pip install -U wheel - pip install -U `ls dist/zope.index-*`[test] - - name: Lint - run: | - pip install -U tox - tox -e lint - manylinux: runs-on: ubuntu-latest if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name # We use a regular Python matrix entry to share as much code as possible. strategy: matrix: - python-version: ["3.9"] + python-version: ["3.11"] image: [manylinux2014_x86_64, manylinux2014_i686, manylinux2014_aarch64] steps: @@ -607,6 +538,8 @@ jobs: name: manylinux_${{ matrix.image }}_wheels.zip - name: Restore pip cache permissions run: sudo chown -R $(whoami) ${{ steps.pip-cache-default.outputs.dir }} + - name: Prevent publishing wheels for unreleased Python versions + run: VER=$(echo '3.13' | tr -d .) && ls -al wheelhouse && sudo rm -f wheelhouse/*-cp${VER}*.whl && ls -al wheelhouse - name: Publish package to PyPI uses: pypa/gh-action-pypi-publish@release/v1 if: > diff --git a/.meta.toml b/.meta.toml index 62edb81..3321989 100644 --- a/.meta.toml +++ b/.meta.toml @@ -2,10 +2,9 @@ # https://github.com/zopefoundation/meta/tree/master/config/c-code [meta] template = "c-code" -commit-id = "8d837c89" +commit-id = "a1e05e74" [python] -with-appveyor = false with-windows = true with-pypy = true with-docs = true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..b5d6386 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,28 @@ +# Generated from: +# https://github.com/zopefoundation/meta/tree/master/config/c-code +minimum_pre_commit_version: '3.6' +repos: + - repo: https://github.com/pycqa/isort + rev: "5.13.2" + hooks: + - id: isort + - repo: https://github.com/hhatto/autopep8 + rev: "v2.3.1" + hooks: + - id: autopep8 + args: [--in-place, --aggressive, --aggressive] + - repo: https://github.com/asottile/pyupgrade + rev: v3.17.0 + hooks: + - id: pyupgrade + args: [--py38-plus] + - repo: https://github.com/isidentical/teyit + rev: 0.4.3 + hooks: + - id: teyit + - repo: https://github.com/PyCQA/flake8 + rev: "7.1.1" + hooks: + - id: flake8 + additional_dependencies: + - flake8-debugger == 4.1.2 diff --git a/MANIFEST.in b/MANIFEST.in index 33bad7b..5fdd82f 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,6 +5,7 @@ include *.rst include *.txt include buildout.cfg include tox.ini +include .pre-commit-config.yaml include .coveragerc recursive-include docs *.py diff --git a/docs/conf.py b/docs/conf.py index a113056..16fdd66 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -# -*- coding: utf-8 -*- # # zope.index documentation build configuration file, created by # sphinx-quickstart on Thu Jan 29 11:31:12 2015. @@ -13,21 +12,24 @@ # All configuration values have a default; values that are commented out # serve to show the default. -import sys import os +import sys + import pkg_resources + + sys.path.append(os.path.abspath('../src')) rqmt = pkg_resources.require('zope.index')[0] # 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 @@ -47,7 +49,7 @@ 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' @@ -67,13 +69,13 @@ # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. -#language = None +# language = None # 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. @@ -81,27 +83,27 @@ # 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' # A list of ignored prefixes for module index sorting. -#modindex_common_prefix = [] +# modindex_common_prefix = [] # If true, keep warnings as "system message" paragraphs in the built documents. -#keep_warnings = False +# keep_warnings = False # -- Options for HTML output ---------------------------------------------- @@ -113,77 +115,77 @@ # 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'] # Add any extra paths that contain custom files (such as robots.txt or # .htaccess) here, relative to this directory. These files are copied # directly to the root of the documentation. -#html_extra_path = [] +# html_extra_path = [] # 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 = 'zopeindexdoc' @@ -192,43 +194,43 @@ # -- Options for LaTeX output --------------------------------------------- latex_elements = { -# The paper size ('letterpaper' or 'a4paper'). -#'papersize': 'letterpaper', + # The paper size ('letterpaper' or 'a4paper'). + # 'papersize': 'letterpaper', -# The font size ('10pt', '11pt' or '12pt'). -#'pointsize': '10pt', + # The font size ('10pt', '11pt' or '12pt'). + # 'pointsize': '10pt', -# Additional stuff for the LaTeX preamble. -#'preamble': '', + # Additional stuff for the LaTeX preamble. + # 'preamble': '', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - ('index', 'zopeindex.tex', 'zope.index Documentation', - 'Zope Foundation and Contributors', 'manual'), + ('index', 'zopeindex.tex', 'zope.index Documentation', + 'Zope Foundation and Contributors', '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 # 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 --------------------------------------- @@ -241,7 +243,7 @@ ] # If true, show URL addresses after external links. -#man_show_urls = False +# man_show_urls = False # -- Options for Texinfo output ------------------------------------------- @@ -250,22 +252,26 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - ('index', 'zopeindex', 'zope.index Documentation', - 'Zope Foundation and Contributors', 'zopeindex', 'One line description of project.', - 'Miscellaneous'), + ('index', + 'zopeindex', + 'zope.index Documentation', + 'Zope Foundation and Contributors', + 'zopeindex', + 'One line description of project.', + 'Miscellaneous'), ] # Documents to append as an appendix to all manuals. -#texinfo_appendices = [] +# texinfo_appendices = [] # If false, no module index is generated. -#texinfo_domain_indices = True +# texinfo_domain_indices = True # How to display URL addresses: 'footnote', 'no', or 'inline'. -#texinfo_show_urls = 'footnote' +# texinfo_show_urls = 'footnote' # If true, do not generate a @detailmenu in the "Top" node's menu. -#texinfo_no_detailmenu = False +# texinfo_no_detailmenu = False # Example configuration for intersphinx: refer to the Python standard library. diff --git a/src/zope/index/field/tests.py b/src/zope/index/field/tests.py index 100d2c6..a890ab7 100644 --- a/src/zope/index/field/tests.py +++ b/src/zope/index/field/tests.py @@ -83,22 +83,22 @@ def test_instance_conforms_to_IStatistics(self): def test_ctor_defaults(self): import BTrees index = self._makeOne() - self.assertTrue(index.family is BTrees.family32) + self.assertIs(index.family, BTrees.family32) self.assertEqual(index.documentCount(), 0) self.assertEqual(index.wordCount(), 0) def test_ctor_explicit_family(self): import BTrees index = self._makeOne(BTrees.family64) - self.assertTrue(index.family is BTrees.family64) + self.assertIs(index.family, BTrees.family64) def test_index_doc_new(self): index = self._makeOne() index.index_doc(1, 'value') self.assertEqual(index.documentCount(), 1) self.assertEqual(index.wordCount(), 1) - self.assertTrue(1 in index._rev_index) - self.assertTrue('value' in index._fwd_index) + self.assertIn(1, index._rev_index) + self.assertIn('value', index._fwd_index) def test_index_doc_existing_same_value(self): index = self._makeOne() @@ -106,8 +106,8 @@ def test_index_doc_existing_same_value(self): index.index_doc(1, 'value') self.assertEqual(index.documentCount(), 1) self.assertEqual(index.wordCount(), 1) - self.assertTrue(1 in index._rev_index) - self.assertTrue('value' in index._fwd_index) + self.assertIn(1, index._rev_index) + self.assertIn('value', index._fwd_index) self.assertEqual(list(index._fwd_index['value']), [1]) def test_index_doc_existing_new_value(self): @@ -116,9 +116,9 @@ def test_index_doc_existing_new_value(self): index.index_doc(1, 'new_value') self.assertEqual(index.documentCount(), 1) self.assertEqual(index.wordCount(), 1) - self.assertTrue(1 in index._rev_index) - self.assertFalse('value' in index._fwd_index) - self.assertTrue('new_value' in index._fwd_index) + self.assertIn(1, index._rev_index) + self.assertNotIn('value', index._fwd_index) + self.assertIn('new_value', index._fwd_index) self.assertEqual(list(index._fwd_index['new_value']), [1]) def test_unindex_doc_nonesuch(self): @@ -131,8 +131,8 @@ def test_unindex_doc_no_residual_fwd_values(self): index.unindex_doc(1) # doesn't raise self.assertEqual(index.documentCount(), 0) self.assertEqual(index.wordCount(), 0) - self.assertFalse(1 in index._rev_index) - self.assertFalse('value' in index._fwd_index) + self.assertNotIn(1, index._rev_index) + self.assertNotIn('value', index._fwd_index) def test_unindex_doc_w_residual_fwd_values(self): index = self._makeOne() @@ -141,9 +141,9 @@ def test_unindex_doc_w_residual_fwd_values(self): index.unindex_doc(1) # doesn't raise self.assertEqual(index.documentCount(), 1) self.assertEqual(index.wordCount(), 1) - self.assertFalse(1 in index._rev_index) - self.assertTrue(2 in index._rev_index) - self.assertTrue('value' in index._fwd_index) + self.assertNotIn(1, index._rev_index) + self.assertIn(2, index._rev_index) + self.assertIn('value', index._fwd_index) self.assertEqual(list(index._fwd_index['value']), [2]) def test_apply_non_tuple_raises(self): diff --git a/src/zope/index/keyword/tests.py b/src/zope/index/keyword/tests.py index e06d247..cace934 100644 --- a/src/zope/index/keyword/tests.py +++ b/src/zope/index/keyword/tests.py @@ -335,12 +335,12 @@ def test_instance_conforms_to_IKeywordQuerying(self): def test_ctor_defaults(self): index = self._makeOne() - self.assertTrue(index.family is self._get_family()) + self.assertIs(index.family, self._get_family()) def test_ctor_explicit_family(self): import BTrees index = self._makeOne(family=BTrees.family64) - self.assertTrue(index.family is BTrees.family64) + self.assertIs(index.family, BTrees.family64) def test_empty_index(self): index = self._makeOne() @@ -358,8 +358,8 @@ def test_index_doc_single(self): self.assertEqual(index.documentCount(), 1) self.assertEqual(index.wordCount(), 2) self.assertTrue(index.has_doc(1)) - self.assertTrue('albatross' in index._fwd_index) - self.assertTrue('cormorant' in index._fwd_index) + self.assertIn('albatross', index._fwd_index) + self.assertIn('cormorant', index._fwd_index) def test_index_doc_existing(self): index = self._makeOne() @@ -368,9 +368,9 @@ def test_index_doc_existing(self): self.assertEqual(index.documentCount(), 1) self.assertEqual(index.wordCount(), 2) self.assertTrue(index.has_doc(1)) - self.assertFalse('albatross' in index._fwd_index) - self.assertTrue('buzzard' in index._fwd_index) - self.assertTrue('cormorant' in index._fwd_index) + self.assertNotIn('albatross', index._fwd_index) + self.assertIn('buzzard', index._fwd_index) + self.assertIn('cormorant', index._fwd_index) def test_index_doc_many(self): index = self._makeOne() diff --git a/src/zope/index/text/parsetree.py b/src/zope/index/text/parsetree.py index 6e17b7e..c4fa0b2 100644 --- a/src/zope/index/text/parsetree.py +++ b/src/zope/index/text/parsetree.py @@ -43,7 +43,7 @@ def getValue(self): return self._value def __repr__(self): - return "{}({!r})".format(self.__class__.__name__, self.getValue()) + return f"{self.__class__.__name__}({self.getValue()!r})" def terms(self): t = [] diff --git a/src/zope/index/text/queryparser.py b/src/zope/index/text/queryparser.py index b068cc0..66370fd 100644 --- a/src/zope/index/text/queryparser.py +++ b/src/zope/index/text/queryparser.py @@ -147,7 +147,7 @@ def parseQueryEx(self, query): def _require(self, tokentype): if not self._check(tokentype): t = self._tokens[self._index] - msg = "Token {!r} required, {!r} found".format(tokentype, t) + msg = f"Token {tokentype!r} required, {t!r} found" raise parsetree.ParseError(msg) def _check(self, tokentype): diff --git a/src/zope/index/text/tests/test_baseindex.py b/src/zope/index/text/tests/test_baseindex.py index 942602e..5cc47d7 100644 --- a/src/zope/index/text/tests/test_baseindex.py +++ b/src/zope/index/text/tests/test_baseindex.py @@ -96,7 +96,7 @@ def test_clear_doesnt_lose_family(self): import BTrees index = self._makeOne(family=BTrees.family64) index.clear() - self.assertTrue(index.family is BTrees.family64) + self.assertIs(index.family, BTrees.family64) def test_wordCount_method_raises_NotImplementedError(self): class DerviedDoesntSet_wordCount(self._getTargetClass()): @@ -124,18 +124,18 @@ def _faux_get_frequencies(wids): self.assertEqual(count, 3) self.assertEqual(index.wordCount(), 3) - self.assertTrue(index._lexicon._wids['one'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['two'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['three'] in index._wordinfo) + self.assertIn(index._lexicon._wids['one'], index._wordinfo) + self.assertIn(index._lexicon._wids['two'], index._wordinfo) + self.assertIn(index._lexicon._wids['three'], index._wordinfo) self.assertEqual(index.documentCount(), 1) self.assertTrue(index.has_doc(1)) - self.assertTrue(1 in index._docwords) - self.assertTrue(1 in index._docweight) + self.assertIn(1, index._docwords) + self.assertIn(1, index._docweight) wids = index.get_words(1) self.assertEqual(len(wids), 3) - self.assertTrue(index._lexicon._wids['one'] in wids) - self.assertTrue(index._lexicon._wids['two'] in wids) - self.assertTrue(index._lexicon._wids['three'] in wids) + self.assertIn(index._lexicon._wids['one'], wids) + self.assertIn(index._lexicon._wids['two'], wids) + self.assertIn(index._lexicon._wids['three'], wids) def test_index_doc_existing_docid(self): index = self._makeOne() @@ -150,16 +150,16 @@ def _faux_get_frequencies(wids): self.assertEqual(count, 3) self.assertEqual(index.wordCount(), 3) - self.assertFalse(index._lexicon._wids['one'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['two'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['three'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['four'] in index._wordinfo) + self.assertNotIn(index._lexicon._wids['one'], index._wordinfo) + self.assertIn(index._lexicon._wids['two'], index._wordinfo) + self.assertIn(index._lexicon._wids['three'], index._wordinfo) + self.assertIn(index._lexicon._wids['four'], index._wordinfo) wids = index.get_words(1) self.assertEqual(len(wids), 3) - self.assertFalse(index._lexicon._wids['one'] in wids) - self.assertTrue(index._lexicon._wids['two'] in wids) - self.assertTrue(index._lexicon._wids['three'] in wids) - self.assertTrue(index._lexicon._wids['four'] in wids) + self.assertNotIn(index._lexicon._wids['one'], wids) + self.assertIn(index._lexicon._wids['two'], wids) + self.assertIn(index._lexicon._wids['three'], wids) + self.assertIn(index._lexicon._wids['four'], wids) def test_index_doc_upgrades_wordCount_documentCount(self): index = self._makeOne() @@ -198,14 +198,14 @@ def _dont_go_here(*args, **kw): self.assertEqual(count, 3) self.assertEqual(index.wordCount(), 3) - self.assertTrue(index._lexicon._wids['one'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['two'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['three'] in index._wordinfo) + self.assertIn(index._lexicon._wids['one'], index._wordinfo) + self.assertIn(index._lexicon._wids['two'], index._wordinfo) + self.assertIn(index._lexicon._wids['three'], index._wordinfo) wids = index.get_words(1) self.assertEqual(len(wids), 3) - self.assertTrue(index._lexicon._wids['one'] in wids) - self.assertTrue(index._lexicon._wids['two'] in wids) - self.assertTrue(index._lexicon._wids['three'] in wids) + self.assertIn(index._lexicon._wids['one'], wids) + self.assertIn(index._lexicon._wids['two'], wids) + self.assertIn(index._lexicon._wids['three'], wids) def test__reindex_doc_disjoint(self): index = self._makeOne() @@ -220,20 +220,20 @@ def _faux_get_frequencies(wids): self.assertEqual(count, 3) self.assertEqual(index.wordCount(), 3) - self.assertFalse(index._lexicon._wids['one'] in index._wordinfo) - self.assertFalse(index._lexicon._wids['two'] in index._wordinfo) - self.assertFalse(index._lexicon._wids['three'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['four'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['five'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['six'] in index._wordinfo) + self.assertNotIn(index._lexicon._wids['one'], index._wordinfo) + self.assertNotIn(index._lexicon._wids['two'], index._wordinfo) + self.assertNotIn(index._lexicon._wids['three'], index._wordinfo) + self.assertIn(index._lexicon._wids['four'], index._wordinfo) + self.assertIn(index._lexicon._wids['five'], index._wordinfo) + self.assertIn(index._lexicon._wids['six'], index._wordinfo) wids = index.get_words(1) self.assertEqual(len(wids), 3) - self.assertFalse(index._lexicon._wids['one'] in wids) - self.assertFalse(index._lexicon._wids['two'] in wids) - self.assertFalse(index._lexicon._wids['three'] in wids) - self.assertTrue(index._lexicon._wids['four'] in wids) - self.assertTrue(index._lexicon._wids['five'] in wids) - self.assertTrue(index._lexicon._wids['six'] in wids) + self.assertNotIn(index._lexicon._wids['one'], wids) + self.assertNotIn(index._lexicon._wids['two'], wids) + self.assertNotIn(index._lexicon._wids['three'], wids) + self.assertIn(index._lexicon._wids['four'], wids) + self.assertIn(index._lexicon._wids['five'], wids) + self.assertIn(index._lexicon._wids['six'], wids) def test__reindex_doc_subset(self): index = self._makeOne() @@ -248,14 +248,14 @@ def _faux_get_frequencies(wids): self.assertEqual(count, 2) self.assertEqual(index.wordCount(), 2) - self.assertFalse(index._lexicon._wids['one'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['two'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['three'] in index._wordinfo) + self.assertNotIn(index._lexicon._wids['one'], index._wordinfo) + self.assertIn(index._lexicon._wids['two'], index._wordinfo) + self.assertIn(index._lexicon._wids['three'], index._wordinfo) wids = index.get_words(1) self.assertEqual(len(wids), 2) - self.assertFalse(index._lexicon._wids['one'] in wids) - self.assertTrue(index._lexicon._wids['two'] in wids) - self.assertTrue(index._lexicon._wids['three'] in wids) + self.assertNotIn(index._lexicon._wids['one'], wids) + self.assertIn(index._lexicon._wids['two'], wids) + self.assertIn(index._lexicon._wids['three'], wids) def test__reindex_doc_superset(self): # TODO index = self._makeOne() @@ -270,20 +270,20 @@ def _faux_get_frequencies(wids): self.assertEqual(count, 6) self.assertEqual(index.wordCount(), 6) - self.assertTrue(index._lexicon._wids['one'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['two'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['three'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['four'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['five'] in index._wordinfo) - self.assertTrue(index._lexicon._wids['six'] in index._wordinfo) + self.assertIn(index._lexicon._wids['one'], index._wordinfo) + self.assertIn(index._lexicon._wids['two'], index._wordinfo) + self.assertIn(index._lexicon._wids['three'], index._wordinfo) + self.assertIn(index._lexicon._wids['four'], index._wordinfo) + self.assertIn(index._lexicon._wids['five'], index._wordinfo) + self.assertIn(index._lexicon._wids['six'], index._wordinfo) wids = index.get_words(1) self.assertEqual(len(wids), 6) - self.assertTrue(index._lexicon._wids['one'] in wids) - self.assertTrue(index._lexicon._wids['two'] in wids) - self.assertTrue(index._lexicon._wids['three'] in wids) - self.assertTrue(index._lexicon._wids['four'] in wids) - self.assertTrue(index._lexicon._wids['five'] in wids) - self.assertTrue(index._lexicon._wids['six'] in wids) + self.assertIn(index._lexicon._wids['one'], wids) + self.assertIn(index._lexicon._wids['two'], wids) + self.assertIn(index._lexicon._wids['three'], wids) + self.assertIn(index._lexicon._wids['four'], wids) + self.assertIn(index._lexicon._wids['five'], wids) + self.assertIn(index._lexicon._wids['six'], wids) def test__get_frequencies_raises_NotImplementedError(self): index = self._makeOne() @@ -299,13 +299,13 @@ def _faux_get_frequencies(wids): index.index_doc(1, 'one two three') index.unindex_doc(1) self.assertEqual(index.wordCount(), 0) - self.assertFalse(index._lexicon._wids['one'] in index._wordinfo) - self.assertFalse(index._lexicon._wids['two'] in index._wordinfo) - self.assertFalse(index._lexicon._wids['three'] in index._wordinfo) + self.assertNotIn(index._lexicon._wids['one'], index._wordinfo) + self.assertNotIn(index._lexicon._wids['two'], index._wordinfo) + self.assertNotIn(index._lexicon._wids['three'], index._wordinfo) self.assertEqual(index.documentCount(), 0) self.assertFalse(index.has_doc(1)) - self.assertFalse(1 in index._docwords) - self.assertFalse(1 in index._docweight) + self.assertNotIn(1, index._docwords) + self.assertNotIn(1, index._docweight) self.assertRaises(KeyError, index.get_words, 1) def test_unindex_doc_upgrades_wordCount_documentCount(self): @@ -321,13 +321,13 @@ def _faux_get_frequencies(wids): del index.documentCount index.unindex_doc(1) self.assertEqual(index.wordCount(), 0) - self.assertFalse(index._lexicon._wids['one'] in index._wordinfo) - self.assertFalse(index._lexicon._wids['two'] in index._wordinfo) - self.assertFalse(index._lexicon._wids['three'] in index._wordinfo) + self.assertNotIn(index._lexicon._wids['one'], index._wordinfo) + self.assertNotIn(index._lexicon._wids['two'], index._wordinfo) + self.assertNotIn(index._lexicon._wids['three'], index._wordinfo) self.assertEqual(index.documentCount(), 0) self.assertFalse(index.has_doc(1)) - self.assertFalse(1 in index._docwords) - self.assertFalse(1 in index._docweight) + self.assertNotIn(1, index._docwords) + self.assertNotIn(1, index._docweight) self.assertRaises(KeyError, index.get_words, 1) def test_search_w_empty_term(self): @@ -454,10 +454,12 @@ def test__add_wordinfo_promotes_dict_to_tree_at_DICT_CUTOFF(self): index.DICT_CUTOFF = 2 index._add_wordinfo(123, 4, 1) index._add_wordinfo(123, 5, 2) - self.assertTrue(isinstance(index._wordinfo[123], dict)) + self.assertIsInstance(index._wordinfo[123], dict) index._add_wordinfo(123, 6, 3) - self.assertTrue(isinstance(index._wordinfo[123], - index.family.IF.BTree)) + self.assertIsInstance( + index._wordinfo[123], + index.family.IF.BTree + ) self.assertEqual(dict(index._wordinfo[123]), {1: 4, 2: 5, 3: 6}) def test__mass_add_wordinfo_promotes_dict_to_tree_at_DICT_CUTOFF(self): @@ -466,8 +468,10 @@ def test__mass_add_wordinfo_promotes_dict_to_tree_at_DICT_CUTOFF(self): index._add_wordinfo(123, 4, 1) index._add_wordinfo(123, 5, 2) index._mass_add_wordinfo({123: 6, 124: 1}, 3) - self.assertTrue(isinstance(index._wordinfo[123], - index.family.IF.BTree)) + self.assertIsInstance( + index._wordinfo[123], + index.family.IF.BTree + ) self.assertEqual(dict(index._wordinfo[123]), {1: 4, 2: 5, 3: 6}) def test__del_wordinfo_no_residual_docscore(self): diff --git a/src/zope/index/text/tests/test_cosineindex.py b/src/zope/index/text/tests/test_cosineindex.py index d9ad51e..b6e7b2c 100644 --- a/src/zope/index/text/tests/test_cosineindex.py +++ b/src/zope/index/text/tests/test_cosineindex.py @@ -89,10 +89,10 @@ def test__search_wids_non_empty_wids(self): relevances = index._search_wids(wids) self.assertEqual(len(relevances), len(wids)) for relevance in relevances: - self.assertTrue(isinstance(relevance[0], index.family.IF.Bucket)) + self.assertIsInstance(relevance[0], index.family.IF.Bucket) self.assertEqual(len(relevance[0]), 1) - self.assertTrue(isinstance(relevance[0][1], float)) - self.assertTrue(isinstance(relevance[1], float)) + self.assertIsInstance(relevance[0][1], float) + self.assertIsInstance(relevance[1], float) def test_query_weight_empty_wids(self): index = self._makeOne() diff --git a/src/zope/index/text/tests/test_index.py b/src/zope/index/text/tests/test_index.py index aaa0c90..7ae2b79 100644 --- a/src/zope/index/text/tests/test_index.py +++ b/src/zope/index/text/tests/test_index.py @@ -45,7 +45,7 @@ def _check_index_has_document(self, index, docid, word_count=5): index.wordCount()) for map in index._wordinfo.values(): self.assertEqual(len(map), 1) - self.assertTrue(docid in map) + self.assertIn(docid, map) def _check_index_is_empty(self, index): self.assertEqual(len(index._docweight), 0) @@ -105,8 +105,8 @@ def test_index_two_documents(self): for wid, map in index._wordinfo.items(): if wid == document_wid: self.assertEqual(len(map), 2) - self.assertTrue(1 in map) - self.assertTrue(2 in map) + self.assertIn(1, map) + self.assertIn(2, map) else: self.assertEqual(len(map), 1) @@ -127,7 +127,7 @@ def test_index_two_unindex_one(self): index.wordCount()) for map in index._wordinfo.values(): self.assertEqual(len(map), 1) - self.assertTrue(2 in map) + self.assertIn(2, map) def test_index_duplicated_words(self): doc = "very simple repeat repeat repeat document test" @@ -144,7 +144,7 @@ def test_index_duplicated_words(self): for _wid, map in index._wordinfo.items(): self.assertEqual(len(map), 1) - self.assertTrue(1 in map) + self.assertIn(1, map) def test_simple_query_oneresult(self): index = self._makeOne() diff --git a/src/zope/index/text/tests/test_lexicon.py b/src/zope/index/text/tests/test_lexicon.py index 1c46d04..9d7eb66 100644 --- a/src/zope/index/text/tests/test_lexicon.py +++ b/src/zope/index/text/tests/test_lexicon.py @@ -53,7 +53,7 @@ def test_wordCount_legacy_instance_no_write_on_read(self): del lexicon.wordCount self.assertEqual(lexicon.wordCount(), 0) # No write-on-read! - self.assertFalse(isinstance(lexicon.wordCount, Length)) + self.assertNotIsInstance(lexicon.wordCount, Length) def test_sourceToWordIds_empty_string(self): lexicon = self._makeOne() @@ -81,7 +81,7 @@ def test_sourceToWordIds_promotes_wordCount_attr(self): wids = lexicon.sourceToWordIds('cats and dogs') self.assertEqual(wids, [1, 2, 3]) self.assertEqual(lexicon.wordCount(), 3) - self.assertTrue(isinstance(lexicon.wordCount, Length)) + self.assertIsInstance(lexicon.wordCount, Length) def test_termToWordIds_hit(self): lexicon = self._makeOne() diff --git a/src/zope/index/text/tests/test_okapiindex.py b/src/zope/index/text/tests/test_okapiindex.py index 02e5319..75cc3e6 100644 --- a/src/zope/index/text/tests/test_okapiindex.py +++ b/src/zope/index/text/tests/test_okapiindex.py @@ -119,10 +119,10 @@ def test__search_wids_non_empty_wids(self): relevances = index._search_wids(wids) self.assertEqual(len(relevances), len(wids)) for relevance in relevances: - self.assertTrue(isinstance(relevance[0], index.family.IF.Bucket)) + self.assertIsInstance(relevance[0], index.family.IF.Bucket) self.assertEqual(len(relevance[0]), 1) - self.assertTrue(isinstance(relevance[0][1], float)) - self.assertTrue(isinstance(relevance[1], int)) + self.assertIsInstance(relevance[0][1], float) + self.assertIsInstance(relevance[1], int) def test_okapiindex__OkapiIndex___search_wids__2(self): """Search also succeeds if there are more than DICT_CUTOFF entries.""" @@ -134,10 +134,10 @@ def test_okapiindex__OkapiIndex___search_wids__2(self): relevances = index._search_wids(wids) self.assertEqual(len(relevances), len(wids)) for relevance in relevances: - self.assertTrue(isinstance(relevance[0], index.family.IF.Bucket)) + self.assertIsInstance(relevance[0], index.family.IF.Bucket) self.assertEqual(len(relevance[0]), 11) - self.assertTrue(isinstance(relevance[0][1], float)) - self.assertTrue(isinstance(relevance[1], int)) + self.assertIsInstance(relevance[0][1], float) + self.assertIsInstance(relevance[1], int) def test__search_wids_old_totaldoclen_no_write_on_read(self): index = self._makeOne() diff --git a/src/zope/index/text/tests/test_textindex.py b/src/zope/index/text/tests/test_textindex.py index 11eb12d..0bf0834 100644 --- a/src/zope/index/text/tests/test_textindex.py +++ b/src/zope/index/text/tests/test_textindex.py @@ -80,37 +80,37 @@ def test_ctor_defaults(self): from zope.index.text.lexicon import Splitter from zope.index.text.lexicon import StopWordRemover from zope.index.text.okapiindex import OkapiIndex - self.assertTrue(isinstance(index.index, OkapiIndex)) - self.assertTrue(isinstance(index.lexicon, Lexicon)) - self.assertTrue(index.index._lexicon is index.lexicon) + self.assertIsInstance(index.index, OkapiIndex) + self.assertIsInstance(index.lexicon, Lexicon) + self.assertIs(index.index._lexicon, index.lexicon) pipeline = index.lexicon._pipeline self.assertEqual(len(pipeline), 3) - self.assertTrue(isinstance(pipeline[0], Splitter)) - self.assertTrue(isinstance(pipeline[1], CaseNormalizer)) - self.assertTrue(isinstance(pipeline[2], StopWordRemover)) + self.assertIsInstance(pipeline[0], Splitter) + self.assertIsInstance(pipeline[1], CaseNormalizer) + self.assertIsInstance(pipeline[2], StopWordRemover) def test_ctor_explicit_lexicon(self): from zope.index.text.okapiindex import OkapiIndex lexicon = object() index = self._makeOne(lexicon) - self.assertTrue(index.lexicon is lexicon) - self.assertTrue(isinstance(index.index, OkapiIndex)) - self.assertTrue(index.index._lexicon is lexicon) + self.assertIs(index.lexicon, lexicon) + self.assertIsInstance(index.index, OkapiIndex) + self.assertIs(index.index._lexicon, lexicon) def test_ctor_explicit_index(self): lexicon = object() okapi = DummyOkapi(lexicon) index = self._makeOne(index=okapi) - self.assertTrue(index.index is okapi) + self.assertIs(index.index, okapi) # See LP #232516 - self.assertTrue(index.lexicon is lexicon) + self.assertIs(index.lexicon, lexicon) def test_ctor_explicit_lexicon_and_index(self): lexicon = object() okapi = object() index = self._makeOne(lexicon, okapi) - self.assertTrue(index.lexicon is lexicon) - self.assertTrue(index.index is okapi) + self.assertIs(index.lexicon, lexicon) + self.assertIs(index.index, okapi) def test_index_doc(self): lexicon = object() diff --git a/src/zope/index/topic/filter.py b/src/zope/index/topic/filter.py index d08728b..dbaa98d 100644 --- a/src/zope/index/topic/filter.py +++ b/src/zope/index/topic/filter.py @@ -63,7 +63,7 @@ def getIds(self): return self._ids def __repr__(self): # pragma: no cover - return '{}: ({}) {}'.format(self.id, self.expr, list(self._ids)) + return f'{self.id}: ({self.expr}) {list(self._ids)}' __str__ = __repr__ diff --git a/src/zope/index/topic/tests/test_filter.py b/src/zope/index/topic/tests/test_filter.py index 29af70d..b7da2e9 100644 --- a/src/zope/index/topic/tests/test_filter.py +++ b/src/zope/index/topic/tests/test_filter.py @@ -49,7 +49,7 @@ def test_instance_conforms_to_ITopicFilteredSet(self): def test_ctor_defaults(self): import BTrees filter = self._makeOne(family=None) - self.assertTrue(filter.family is BTrees.family32) + self.assertIs(filter.family, BTrees.family32) self.assertEqual(filter.getId(), 'test') self.assertEqual(filter.getExpression(), 'True') self.assertEqual(len(filter.getIds()), 0) @@ -57,7 +57,7 @@ def test_ctor_defaults(self): def test_ctor_explicit_family(self): import BTrees filter = self._makeOne(family=BTrees.family64) - self.assertTrue(filter.family is BTrees.family64) + self.assertIs(filter.family, BTrees.family64) def test_index_doc_raises_NotImplementedError(self): filter = self._makeOne() diff --git a/src/zope/index/topic/tests/test_index.py b/src/zope/index/topic/tests/test_index.py index 7fb054b..d18d185 100644 --- a/src/zope/index/topic/tests/test_index.py +++ b/src/zope/index/topic/tests/test_index.py @@ -103,12 +103,12 @@ def test_instance_conforms_to_ITopicQuerying(self): def test_ctor_defaults(self): import BTrees index = self._makeOne(family=None) - self.assertTrue(index.family is BTrees.family32) + self.assertIs(index.family, BTrees.family32) def test_ctor_explicit_family(self): import BTrees index = self._makeOne(family=BTrees.family64) - self.assertTrue(index.family is BTrees.family64) + self.assertIs(index.family, BTrees.family64) def test_clear_erases_filters(self): index = self._makeOne() @@ -122,7 +122,7 @@ def test_addFilter(self): foo = DummyFilter('foo') index.addFilter(foo) self.assertEqual(list(index._filters), ['foo']) - self.assertTrue(index._filters['foo'] is foo) + self.assertIs(index._filters['foo'], foo) def test_addFilter_duplicate_replaces(self): index = self._makeOne() @@ -131,7 +131,7 @@ def test_addFilter_duplicate_replaces(self): foo2 = DummyFilter('foo') index.addFilter(foo2) self.assertEqual(list(index._filters), ['foo']) - self.assertTrue(index._filters['foo'] is foo2) + self.assertIs(index._filters['foo'], foo2) def test_delFilter_nonesuch_raises_KeyError(self): index = self._makeOne() @@ -145,7 +145,7 @@ def test_delFilter(self): index.addFilter(bar) index.delFilter('foo') self.assertEqual(list(index._filters), ['bar']) - self.assertTrue(index._filters['bar'] is bar) + self.assertIs(index._filters['bar'], bar) def test_clearFilters_empty(self): index = self._makeOne() diff --git a/tox.ini b/tox.ini index 5bf7bf4..25099cd 100644 --- a/tox.ini +++ b/tox.ini @@ -15,10 +15,9 @@ envlist = coverage [testenv] -usedevelop = true pip_pre = py313: true deps = - setuptools < 69 + setuptools < 74 py37: urllib3 < 2 Sphinx setenv = @@ -47,6 +46,7 @@ commands = coverage run -m zope.testrunner --test-path=src {posargs:-vc} coverage html -i coverage report -i -m --fail-under=99 + [testenv:release-check] description = ensure that the distribution is ready to release basepython = python3 @@ -65,23 +65,14 @@ commands = twine check dist/* [testenv:lint] +description = This env runs all linters configured in .pre-commit-config.yaml basepython = python3 skip_install = true deps = - isort - flake8 -commands = - isort --check-only --diff {toxinidir}/src {toxinidir}/setup.py - flake8 src setup.py - -[testenv:isort-apply] -basepython = python3 -skip_install = true + pre-commit commands_pre = -deps = - isort commands = - isort {toxinidir}/src {toxinidir}/setup.py [] + pre-commit run --all-files --show-diff-on-failure [testenv:docs] basepython = python3