summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2021-11-19 06:56:08 -0500
committerNed Batchelder <ned@nedbatchelder.com>2021-11-19 06:56:08 -0500
commit9b66c98b6bac5bdb8f6154dd31532c82e5d9f38b (patch)
tree848bcf3b1a1388694ccd06a862a09bf77bd196fb
parentd61a04c3442f73735492b2e34a54b4bc2b80fb34 (diff)
downloadpython-coveragepy-git-9b66c98b6bac5bdb8f6154dd31532c82e5d9f38b.tar.gz
docs: use cog instead of manually copying and checking the copy
-rw-r--r--Makefile2
-rw-r--r--doc/check_copied_from.py113
-rw-r--r--doc/dbschema.rst22
-rw-r--r--doc/requirements.in1
-rw-r--r--doc/requirements.pip4
-rw-r--r--requirements/dev.pip6
-rw-r--r--requirements/kit.pip2
-rw-r--r--requirements/pip-tools.pip2
-rw-r--r--requirements/pytest.pip2
-rw-r--r--tox.ini2
10 files changed, 28 insertions, 128 deletions
diff --git a/Makefile b/Makefile
index 681e6bf1..666d445e 100644
--- a/Makefile
+++ b/Makefile
@@ -135,7 +135,7 @@ cmd_help: $(DOCBIN)
done
dochtml: $(DOCBIN) cmd_help ## Build the docs HTML output.
- $(DOCBIN)/python doc/check_copied_from.py doc/*.rst
+ $(DOCBIN)/python -m cogapp -rP --verbosity=1 doc/*.rst
$(SPHINXBUILD) -b html doc doc/_build/html
docdev: dochtml ## Build docs, and auto-watch for changes.
diff --git a/doc/check_copied_from.py b/doc/check_copied_from.py
deleted file mode 100644
index 79ec005b..00000000
--- a/doc/check_copied_from.py
+++ /dev/null
@@ -1,113 +0,0 @@
-# Licensed under the Apache License: http://www.apache.org/licenses/LICENSE-2.0
-# For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
-
-"""Find lines in files that should be faithful copies, and check that they are.
-
-Inside a comment-marked section, any chunk of indented lines should be
-faithfully copied from FILENAME. The indented lines are dedented before
-comparing.
-
-The section is between these comments:
-
- .. copied_from <FILENAME>
-
- .. end_copied_from
-
-This tool will print any mismatches, and then exit with a count of mismatches.
-
-"""
-
-import glob
-from itertools import groupby
-from operator import itemgetter
-import re
-import sys
-import textwrap
-
-
-def check_copied_from(rst_name):
- """Check copies in a .rst file.
-
- Prints problems. Returns count of bad copies.
- """
- bad_copies = 0
- file_read = None
- file_text = None
- with open(rst_name) as frst:
- for filename, first_line, text in find_copied_chunks(frst):
- if filename != file_read:
- with open(filename) as f:
- file_text = f.read()
- file_read = filename
- if text not in file_text:
- print("{}:{}: Bad copy from {}, starting with {!r}".format(
- rst_name, first_line, filename, text.splitlines()[0]
- ))
- bad_copies += 1
-
- return bad_copies
-
-
-def find_copied_chunks(frst):
- """Find chunks of text that are meant to be faithful copies.
-
- `frst` is an iterable of strings, the .rst text.
-
- Yields (source_filename, first_line, text) tuples.
- """
- for (_, filename), chunks in groupby(find_copied_lines(frst), itemgetter(0)):
- chunks = list(chunks)
- first_line = chunks[0][1]
- text = textwrap.dedent("\n".join(map(itemgetter(2), chunks)))
- yield filename, first_line, text
-
-
-def find_copied_lines(frst):
- """Find lines of text that are meant to be faithful copies.
-
- `frst` is an iterable of strings, the .rst text.
-
- Yields tuples ((chunk_num, file_name), line_num, line).
-
- `chunk_num` is an integer that is different for each distinct (blank
- line separated) chunk of text, but has no meaning other than that.
-
- `file_name` is the file the chunk should be copied from. `line_num`
- is the line number in the .rst file, and `line` is the text of the line.
-
- """
- in_section = False
- source_file = None
- chunk_num = 0
-
- for line_num, line in enumerate(frst, start=1):
- line = line.rstrip()
- if in_section:
- m = re.search(r"^.. end_copied_from", line)
- if m:
- in_section = False
- else:
- if re.search(r"^\s+\S", line):
- # Indented line
- yield (chunk_num, source_file), line_num, line
- elif not line.strip():
- # Blank line
- chunk_num += 1
- else:
- m = re.search(r"^.. copied_from: (.*)", line)
- if m:
- in_section = True
- source_file = m.group(1)
-
-
-def main(args):
- """Check all the files in `args`, return count of bad copies."""
- bad_copies = 0
- for arg in args:
- for fname in glob.glob(arg):
- bad_copies += check_copied_from(fname)
- return bad_copies
-
-
-if __name__ == "__main__":
- sys.exit(main(sys.argv[1:]))
diff --git a/doc/dbschema.rst b/doc/dbschema.rst
index 42cf26cc..a2fa2f38 100644
--- a/doc/dbschema.rst
+++ b/doc/dbschema.rst
@@ -18,13 +18,18 @@ The schema can change without changing the major version of coverage.py, so be
careful when accessing the database directly. The `coverage_schema` table has
the schema number of the database. The schema described here corresponds to:
-.. copied_from: coverage/sqldata.py
-
+.. [[[cog
+ from coverage.sqldata import SCHEMA_VERSION
+ print(".. code::")
+ print()
+ print(f" SCHEMA_VERSION = {SCHEMA_VERSION}")
+ print()
+.. ]]]
.. code::
SCHEMA_VERSION = 7
-.. end_copied_from
+.. [[[end]]]
You can use SQLite tools such as the :mod:`sqlite3 <python:sqlite3>` module in
the Python standard library to access the data. Some data is stored in a
@@ -37,8 +42,13 @@ Database schema
This is the database schema:
-.. copied_from: coverage/sqldata.py
-
+.. [[[cog
+ import textwrap
+ from coverage.sqldata import SCHEMA
+ print(".. code::")
+ print()
+ print(textwrap.indent(SCHEMA, " "))
+.. ]]]
.. code::
CREATE TABLE coverage_schema (
@@ -101,7 +111,7 @@ This is the database schema:
foreign key (file_id) references file (id)
);
-.. end_copied_from
+.. [[[end]]]
.. _numbits:
diff --git a/doc/requirements.in b/doc/requirements.in
index fb3c27ad..3a9088c7 100644
--- a/doc/requirements.in
+++ b/doc/requirements.in
@@ -6,6 +6,7 @@
-c ../requirements/pins.pip
+cogapp
doc8
pyenchant
sphinx
diff --git a/doc/requirements.pip b/doc/requirements.pip
index 0025493b..392f502c 100644
--- a/doc/requirements.pip
+++ b/doc/requirements.pip
@@ -12,6 +12,8 @@ certifi==2021.10.8
# via requests
charset-normalizer==2.0.7
# via requests
+cogapp==3.2.0
+ # via -r doc/requirements.in
colorama==0.4.4
# via sphinx-autobuild
doc8==0.10.1
@@ -97,5 +99,5 @@ urllib3==1.26.7
# via requests
# The following packages are considered to be unsafe in a requirements file:
-setuptools==59.1.1
+setuptools==59.2.0
# via sphinx
diff --git a/requirements/dev.pip b/requirements/dev.pip
index 06010a93..d3072d0a 100644
--- a/requirements/dev.pip
+++ b/requirements/dev.pip
@@ -60,7 +60,7 @@ future==0.18.2
# pycontracts
greenlet==1.1.2
# via -r requirements/dev.in
-hypothesis==6.24.6
+hypothesis==6.25.0
# via -r requirements/pytest.pip
idna==3.3
# via requests
@@ -95,7 +95,7 @@ parso==0.8.2
# via jedi
pep517==0.12.0
# via build
-pkginfo==1.7.1
+pkginfo==1.8.0
# via twine
platformdirs==2.4.0
# via
@@ -212,7 +212,7 @@ zipp==3.6.0
# The following packages are considered to be unsafe in a requirements file:
pip==21.3.1
# via -r requirements/pip.pip
-setuptools==59.1.1
+setuptools==59.2.0
# via
# astroid
# check-manifest
diff --git a/requirements/kit.pip b/requirements/kit.pip
index 4fba8c2e..24eb772e 100644
--- a/requirements/kit.pip
+++ b/requirements/kit.pip
@@ -35,5 +35,5 @@ wheel==0.37.0
# via -r requirements/kit.in
# The following packages are considered to be unsafe in a requirements file:
-setuptools==59.1.1
+setuptools==59.2.0
# via -r requirements/kit.in
diff --git a/requirements/pip-tools.pip b/requirements/pip-tools.pip
index 3a5d1bdc..93f04661 100644
--- a/requirements/pip-tools.pip
+++ b/requirements/pip-tools.pip
@@ -18,5 +18,5 @@ wheel==0.37.0
# The following packages are considered to be unsafe in a requirements file:
pip==21.3.1
# via pip-tools
-setuptools==59.1.1
+setuptools==59.2.0
# via pip-tools
diff --git a/requirements/pytest.pip b/requirements/pytest.pip
index 1732be28..11dbcc19 100644
--- a/requirements/pytest.pip
+++ b/requirements/pytest.pip
@@ -18,7 +18,7 @@ flaky==3.7.0
# via -r requirements/pytest.in
future==0.18.2
# via pycontracts
-hypothesis==6.24.6
+hypothesis==6.25.0
# via -r requirements/pytest.in
iniconfig==1.1.1
# via pytest
diff --git a/tox.ini b/tox.ini
index 31162ac7..4ed7729d 100644
--- a/tox.ini
+++ b/tox.ini
@@ -65,7 +65,7 @@ whitelist_externals =
make
commands =
make cmd_help
- python doc/check_copied_from.py doc/*.rst
+ python -m cogapp -rP --verbosity=1 doc/*.rst
doc8 -q --ignore-path 'doc/_*' doc CHANGES.rst README.rst
sphinx-build -b html -aEnqW doc doc/_build/html
rst2html.py --strict README.rst doc/_build/trash