Skip to content

Commit 37a1421

Browse files
authored
Merge pull request #725 from Fortran-FOSS-Programmers/better-externalise-docs
Always export `modules.json` for external projects
2 parents 8109b9d + 5836114 commit 37a1421

File tree

4 files changed

+82
-18
lines changed

4 files changed

+82
-18
lines changed

docs/user_guide/project_file_options.rst

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -862,13 +862,28 @@ external
862862

863863
Paths or URLs of external projects to link to. If an entity is not found in the
864864
sources, FORD will try to look it up in those external projects. If those have
865-
documentation generated by FORD with the externalize option, a link will be
866-
placed into the documentation wherever this entity is referred to. FORD will
867-
look in the provided paths for a ``modules.json`` file.
865+
documentation generated by FORD with the `externalize <option-externalize>`
866+
option, a link will be placed into the documentation wherever this entity is
867+
referred to. FORD will look in the provided paths for a ``modules.json`` file.
868868

869-
The difference between ``external`` between ``extra_mods`` is that FORD can link
870-
directly to entities (functions, types, and so on) with ``external``, while only
871-
modules will be linked to using ``extra_mods``.
869+
The difference between ``external`` between `extra_mods <option-extra_mods>` is
870+
that FORD can link directly to entities (functions, types, and so on) with
871+
``external``, while only modules will be linked to using ``extra_mods``.
872+
873+
.. tab:: fpm.toml
874+
875+
.. code:: toml
876+
877+
[extra.ford.external]
878+
example_project = "https://docs.example.com"
879+
fmin = "https://jacobwilliams.github.io/fmin/"
880+
881+
.. tab:: Markdown metadata
882+
883+
.. code:: yaml
884+
885+
external: example_project=https://docs.example.com
886+
fmin=https://jacobwilliams.github.io/fmin/
872887
873888
.. _option-extra_mods:
874889

@@ -1152,6 +1167,9 @@ Create a ``modules.json`` file under `option-output_dir` containing information
11521167
about entities and the URL of their documentation. This allows this project to
11531168
be used as an `option-external` link in another project.
11541169

1170+
.. versionchanged:: 7.0.13
1171+
This option is now ``True`` by default
1172+
11551173
.. _option-graph_dir:
11561174

11571175
graph_dir

docs/user_guide/writing_documentation.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,42 @@ constructor.
352352
``my_subroutine``, while now it will be left as: ``call
353353
[[my_subroutine]]``.
354354

355+
.. _external_projects:
356+
357+
Linking to External Projects
358+
----------------------------
359+
360+
FORD can look up references to modules, routines, and types in other projects if
361+
they also use FORD for documentation.
362+
This works in two steps:
363+
364+
- the external project exports the information about each entity, including
365+
links, to a ``modules.json`` file, which is hosted along with the rest of the
366+
documentation.
367+
368+
.. versionchanged:: 7.0.13
369+
Prior to 7.0.13, the external project has to set `externalize = True
370+
<option-externalize>` in order to create the ``modules.json`` file. In
371+
7.0.13, this is now the default behaviour.
372+
373+
- the downstream project imports the external project using the `external
374+
<option-external>` setting, specifying the name of the project and (usually)
375+
the top-level URL of the project's documentation. For example, if the front
376+
page of your FORD docs is at ``project.github.io``, you would set:
377+
378+
.. tab:: fpm.toml
379+
380+
.. code:: toml
381+
382+
[extra.ford.external]
383+
name = "https://project.github.io"
384+
385+
.. tab:: Markdown metadata
386+
387+
.. code:: yaml
388+
389+
external: name=https://project.github.io
390+
355391
.. _non-fortran-source-files:
356392

357393
Non-Fortran Source Files

ford/__init__.py

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,30 @@ def get_command_line_arguments() -> argparse.Namespace:
271271
help="list of directories to be searched for ``include`` files",
272272
)
273273
parser.add_argument(
274+
"--config",
275+
type=str,
276+
default=None,
277+
help="Any other FORD options as a semicolon-separated TOML string. "
278+
"Options set through this have lower precedence than other command line options",
279+
)
280+
281+
external_group = parser.add_argument_group("external projects")
282+
externalize_group = external_group.add_mutually_exclusive_group()
283+
externalize_group.add_argument(
274284
"--externalize",
275285
action="store_true",
276-
default=None,
277-
help="provide information about Fortran objects in a json database for "
278-
"other FORD projects to refer to.",
286+
default=True,
287+
help="export information about Fortran objects to JSON file for "
288+
"other FORD projects to use (default: True)",
279289
)
280-
parser.add_argument(
290+
externalize_group.add_argument(
291+
"--no-externalize",
292+
action="store_false",
293+
dest="externalize",
294+
help="don't export information to JSON file",
295+
)
296+
297+
external_group.add_argument(
281298
"-L",
282299
"--external_links",
283300
dest="external",
@@ -290,13 +307,6 @@ def get_command_line_arguments() -> argparse.Namespace:
290307
FORD will look in the provided paths for a modules.json file.
291308
""",
292309
)
293-
parser.add_argument(
294-
"--config",
295-
type=str,
296-
default=None,
297-
help="Any other FORD options as a semicolon-separated TOML string. "
298-
"Options set through this have lower precedence than other command line options",
299-
)
300310

301311
return parser.parse_args()
302312

ford/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class ProjectSettings:
142142
default_factory=lambda: ["f90", "f95", "f03", "f08", "f15"]
143143
)
144144
external: Dict[str, str] = field(default_factory=dict)
145-
externalize: bool = False
145+
externalize: bool = True
146146
extra_filetypes: Dict[str, ExtraFileType] = field(default_factory=dict)
147147
extra_mods: Dict[str, str] = field(default_factory=dict)
148148
extra_vartypes: list = field(default_factory=list)

0 commit comments

Comments
 (0)