diff --git a/conservancy_beancount/plugin/meta_repo_links.py b/conservancy_beancount/plugin/meta_repo_links.py index fdf1fc279c07cd912b70265f2cbe8a45f4df00c8..b2cac413546b833b554add22cdb075ff74fc2e83 100644 --- a/conservancy_beancount/plugin/meta_repo_links.py +++ b/conservancy_beancount/plugin/meta_repo_links.py @@ -20,6 +20,7 @@ from . import core from .. import config as configmod from .. import data from .. import errors as errormod +from .. import rtutil from ..beancount_types import ( MetaKey, MetaValue, @@ -35,7 +36,6 @@ from typing import ( class MetaRepoLinks(core.TransactionHook): HOOK_GROUPS = frozenset(['linkcheck']) LINK_METADATA = data.LINK_METADATA.difference('rt-id') - PATH_PUNCT_RE = re.compile(r'[:/]') SKIP_FLAGS = '!' def __init__(self, config: configmod.Config) -> None: @@ -57,8 +57,20 @@ class MetaRepoLinks(core.TransactionHook): yield errormod.InvalidMetadataError(txn, key, meta[key], post) else: for link in links: - match = self.PATH_PUNCT_RE.search(link) - if match and match.group(0) == ':': + # FUTURE DEVELOPMENT NOTE: As of this writing we have two + # link checkers. Right now the division of reporting + # responsibility is: MetaRTLinks reports problems with any + # link that starts with `rt:`, while this checker reports + # problems with anything else. + # If we add more link checkers in the future, we might need + # to give more thought about which checker is responsible + # for flagging links in "unknown formats." But today, I + # can't write better code that anticipates that need + # without having any idea of what future link formats will + # look like. Today, asking the RT parser "can you handle + # this?" is the safest way to make sure all bad links get + # reported. + if rtutil.RT.parse(link) is not None: pass elif not (self.repo_path / link).exists(): yield errormod.BrokenLinkError(txn, key, link) diff --git a/setup.py b/setup.py index a590f6aaa9ac3fa928477804e4bd723be3e0e615..97fb540a3a60f3ed1a953dd9e9a0ac74b2901b3d 100755 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ from setuptools import setup setup( name='conservancy_beancount', description="Plugin, library, and reports for reading Conservancy's books", - version='1.9.6', + version='1.9.7', author='Software Freedom Conservancy', author_email='info@sfconservancy.org', license='GNU AGPLv3+', diff --git a/tests/test_meta_repo_links.py b/tests/test_meta_repo_links.py index 68c2c2b0e10e9778ca8446faf666e5f210613f35..fbaaf81c8bee1233f81b16c4ea1b2c9393b9e1f8 100644 --- a/tests/test_meta_repo_links.py +++ b/tests/test_meta_repo_links.py @@ -45,6 +45,12 @@ GOOD_LINKS = [Path(s) for s in [ BAD_LINKS = [Path(s) for s in [ 'NonexistentDirectory/NonexistentFile1.txt', 'NonexistentDirectory/NonexistentFile2.txt', + 'egproto:', + 'egproto:123', + 'egproto:123/456', + 'egproto:foo' + 'egproto:/foo/bar', + ';egproto::', ]] NOT_FOUND_MSG = '{} not found in repository: {}'.format