From 47b206b9a59d08383debb4f55c7bfe8ccbebfc43 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Mon, 8 Jan 2024 09:23:40 +0000 Subject: [PATCH 1/4] Fix broken Ford links that appear in entity descriptions The relative url would be wrong when the summary is shown on the entity list page Fixes #612 --- example/src/ford_test_module.fpp | 2 +- ford/_markdown.py | 10 ++++++- test/test_project.py | 45 ++++++++++++++------------------ 3 files changed, 30 insertions(+), 27 deletions(-) diff --git a/example/src/ford_test_module.fpp b/example/src/ford_test_module.fpp index ab712501..0a64f45b 100644 --- a/example/src/ford_test_module.fpp +++ b/example/src/ford_test_module.fpp @@ -20,7 +20,7 @@ contains #ifdef HAS_DECREMENT subroutine decrement(x) - !! Decrease argument by one + !! Decrease argument by one, the opposite of [[increment]] !! !! Only publicly accessible if `"HAS_DECREMENT"` preprocessor !! macro is defined diff --git a/ford/_markdown.py b/ford/_markdown.py index acf7ce70..2dbeabb6 100644 --- a/ford/_markdown.py +++ b/ford/_markdown.py @@ -117,7 +117,15 @@ def convert( and context is not None and (url := context.get_url()) is not None ): - self.current_path = self.base_url / Path(url).parent + # This is a bit of a pain, but when making `[[ford]]` links, we want + # the link to be relative to the page the link is from. However, we + # use the entity description both on the entity page, and the list + # pages, so the same relative url needs to work from both. Luckily + # we know the directory layout, so just make a relative link from a + # (non-existent) sibling directory + self.current_path = ( + self.base_url / Path(url).parent.parent / "non-existent dir" + ) else: self.current_path = path return super().convert(source) diff --git a/test/test_project.py b/test/test_project.py index 3f181087..dca58e3b 100644 --- a/test/test_project.py +++ b/test/test_project.py @@ -1082,14 +1082,14 @@ def test_make_links(copy_fortran_file): project.markdown(md) expected_links = { - "a": "module/a.html", - "b": "type/b.html", - "c": "type/b.html#variable-c", - "d": "proc/d.html", - "e": "type/b.html#boundprocedure-e", - "f": "proc/f.html", - "g": "module/a.html#variable-g", - "h": "program/h.html", + "a": "../module/a.html", + "b": "../type/b.html", + "c": "../type/b.html#variable-c", + "d": "../proc/d.html", + "e": "../type/b.html#boundprocedure-e", + "f": "../proc/f.html", + "g": "../module/a.html#variable-g", + "h": "../program/h.html", } for item in chain( @@ -1100,12 +1100,8 @@ def test_make_links(copy_fortran_file): ): docstring = BeautifulSoup(item.doc, features="html.parser") link_locations = {a.string: a.get("href", None) for a in docstring("a")} - base_dir = pathlib.Path(item.get_url()).parent - expected_links_rel = { - k: relpath(v, base_dir) for k, v in expected_links.items() - } - assert link_locations == expected_links_rel, (item, item.name) + assert link_locations == expected_links, (item, item.name) def test_link_with_context(copy_fortran_file): @@ -1138,16 +1134,16 @@ def test_link_with_context(copy_fortran_file): project.markdown(md) expected_links = { - "a": "module/a.html", - "b": "type/b.html", - "c": "type/b.html#variable-c", - "d": "proc/d.html", - "e": "type/b.html#boundprocedure-e", - "f": "proc/d.html#proc-f", - "g": "module/a.html#variable-g", - "h": "program/h.html", - "i": "proc/d.html#variable-i", - "x": "proc/d.html#variable-x", + "a": "../module/a.html", + "b": "../type/b.html", + "c": "../type/b.html#variable-c", + "d": "../proc/d.html", + "e": "../type/b.html#boundprocedure-e", + "f": "../proc/d.html#proc-f", + "g": "../module/a.html#variable-g", + "h": "../program/h.html", + "i": "../proc/d.html#variable-i", + "x": "../proc/d.html#variable-x", } for item in chain( @@ -1160,8 +1156,7 @@ def test_link_with_context(copy_fortran_file): for link in docstring("a"): assert link.string in expected_links, (item, item.name, link) - base_dir = pathlib.Path(item.get_url()).parent - expected_link = relpath(expected_links[link.string], base_dir) + expected_link = expected_links[link.string] assert link.get("href", None) == expected_link, ( item, From 0866a40cc3cddf393cf5bd5ba4b4e29f566c64cc Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Mon, 8 Jan 2024 09:25:15 +0000 Subject: [PATCH 2/4] Fix `program` link in nav bar Fixes #613 --- ford/templates/base.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ford/templates/base.html b/ford/templates/base.html index b44124d5..1172ccdf 100644 --- a/ford/templates/base.html +++ b/ford/templates/base.html @@ -98,7 +98,7 @@ {% elif project.programs|length == 1 %} {% endif %} {% if privacy_policy_url %} From 5dfb6e3f159eed62a33314609d90772712d31721 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Mon, 8 Jan 2024 09:59:29 +0000 Subject: [PATCH 3/4] Fix `pcpp` preprocessor clobbering urls in links Add `--passthru-comments` to avoid parsing `http://` as ending in a comment Fixes #611 --- ford/settings.py | 2 +- test/test_reader.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ford/settings.py b/ford/settings.py index d2309135..97c4bdb8 100644 --- a/ford/settings.py +++ b/ford/settings.py @@ -178,7 +178,7 @@ class ProjectSettings: predocmark: str = ">" predocmark_alt: str = "|" preprocess: bool = True - preprocessor: str = "pcpp -D__GFORTRAN__" + preprocessor: str = "pcpp -D__GFORTRAN__ --passthru-comments" print_creation_date: bool = False privacy_policy_url: Optional[str] = None proc_internals: bool = False diff --git a/test/test_reader.py b/test/test_reader.py index 6062b9a5..d2838b64 100644 --- a/test/test_reader.py +++ b/test/test_reader.py @@ -10,6 +10,7 @@ import ford.reader as reader from ford.reader import _contains_unterminated_string +from ford.settings import ProjectSettings RE_WHITE = re.compile(r"\s+") @@ -204,3 +205,19 @@ def test_preprocessor_warning(copy_fortran_file): ) ) assert "foo" in lines + + +def test_preprocessor_leaves_urls(copy_fortran_file): + """Check preprocessor leaves urls, issue #611""" + + data = """\ + !! http://www.example.com + module foo + end + """ + filename = copy_fortran_file(data, ".F90") + preprocessor = ProjectSettings().preprocessor.split() + lines = "\n".join( + list(reader.FortranReader(str(filename), preprocessor=preprocessor)) + ) + assert "http://www.example.com" in lines From 3f2fe4816c76b43c80672f8e5672b38ca214c654 Mon Sep 17 00:00:00 2001 From: Peter Hill Date: Mon, 8 Jan 2024 10:44:10 +0000 Subject: [PATCH 4/4] CI: Fix changed locations of some corpus project files --- test/test_corpus.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_corpus.py b/test/test_corpus.py index 1d515b3b..be5aa2df 100644 --- a/test/test_corpus.py +++ b/test/test_corpus.py @@ -32,12 +32,12 @@ ("https://github.com/fortran-lang/stdlib", "stdlib/API-doc-FORD-file.md", ""), ( "https://github.com/jacobwilliams/Fortran-Astrodynamics-Toolkit", - "Fortran-Astrodynamics-Toolkit/fortran-astrodynamics-toolkit.md", + "Fortran-Astrodynamics-Toolkit/ford.md", "", ), ( "https://github.com/jacobwilliams/bspline-fortran", - "bspline-fortran/bspline-fortran.md", + "bspline-fortran/ford.md", "", ), ("https://github.com/jacobwilliams/dvode", "dvode/ford.md", ""), @@ -49,10 +49,10 @@ ), ( "https://github.com/jacobwilliams/pyplot-fortran", - "pyplot-fortran/pyplot-fortran.md", + "pyplot-fortran/ford.md", "", ), - ("https://github.com/jacobwilliams/quadpack", "quadpack/quadpack.md", ""), + ("https://github.com/jacobwilliams/quadpack", "quadpack/ford.md", ""), ("https://github.com/szaghi/FLAP", "FLAP/doc/main_page.md", ""), ("https://github.com/szaghi/FiNeR", "FiNeR/doc/main_page.md", ""), ("https://github.com/szaghi/VTKFortran", "VTKFortran/doc/main_page.md", ""),