Repository: jaraco/pytest-checkdocs (language: python)

Issue:
README with 8 spaces of indentation breaks dedent check
In v2.6.0, [repair_field](https://github.com/jaraco/pytest-checkdocs/blob/74d70d4fd6e021a0defe7e37f488458e320cf2af/pytest_checkdocs/__init__.py#L30) was updated to only repair if it appears to need dedenting, but the detection will over-match if the text is dedented _and_ the original field has `'\n' + ' '*8`.


Discussion / hints:

Fix patch:
diff --git a/setup.cfg b/setup.cfg
index af8525a..af4bd84 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -22,7 +22,7 @@ python_requires = >=3.6
 install_requires =
 	docutils >= 0.15
 	pep517
-	jaraco.functools
+	importlib_metadata >= 4
 setup_requires = setuptools_scm[toml] >= 3.4.1
 
 [options.packages.find]


Test patch:
diff --git a/pytest_checkdocs/__init__.py b/pytest_checkdocs/__init__.py
index fda6b46..689c22e 100644
--- a/pytest_checkdocs/__init__.py
+++ b/pytest_checkdocs/__init__.py
@@ -1,11 +1,10 @@
-import textwrap
 import contextlib
 import re
 
 import pytest
 import docutils.core
 import pep517.meta
-from jaraco.functools import pass_none
+import importlib_metadata
 
 
 project_files = 'setup.py', 'setup.cfg', 'pyproject.toml'
@@ -20,24 +19,10 @@ def pytest_collect_file(path, parent):
 class Description(str):
     @classmethod
     def from_md(cls, md):
-        cleaned = cls.repair_field(md.get('Description')) or md.get_payload()
-        desc = cls(cleaned)
+        desc = cls(md.get('Description'))
         desc.content_type = md.get('Description-Content-Type', 'text/x-rst')
         return desc
 
-    @staticmethod
-    @pass_none
-    def repair_field(raw):
-        """
-        When the description is found as a field, the first
-        line is not indented, but subsequent lines are indented
-        with 8 spaces. Adjust by indenting the first line
-        8 spaces and then dedent.
-        """
-        indent = ' ' * 8
-        needs_dedent = '\n' + indent in raw
-        return textwrap.dedent(indent + raw) if needs_dedent else raw
-
 
 class CheckdocsItem(pytest.Item):
     def runtest(self):
@@ -72,7 +57,7 @@ def system_message(reporter, level, message, *children, **kwargs):
         docutils.utils.Reporter.system_message = orig
 
     def get_long_description(self):
-        return Description.from_md(pep517.meta.load('.').metadata)
+        return Description.from_md(ensure_clean(pep517.meta.load('.').metadata))
 
     @staticmethod
     def rst2html(value):
@@ -81,3 +66,16 @@ def rst2html(value):
             source=value, writer_name="html4css1", settings_overrides=docutils_settings
         )
         return parts['whole']
+
+
+def ensure_clean(metadata):
+    """
+    On Python 3.8 and later, pep517.meta returns a PathDistribution
+    without clean metadata. Employ the adapter that comes with
+    importlib_metadata 4 to get clean metadata.
+    """
+    try:
+        metadata.json
+    except AttributeError:
+        metadata = importlib_metadata._adapters.Message(metadata)
+    return metadata