Skip to content

Commit d189c0d

Browse files
authored
Merge pull request #697 from Fortran-FOSS-Programmers/fix-docs-fpm-toml
Fix some issues with using `fpm.toml`
2 parents c4ce159 + 119c8fa commit d189c0d

File tree

8 files changed

+68
-51
lines changed

8 files changed

+68
-51
lines changed

docs/user_guide/project_file_options.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ ways:
1111
2. in the ``extra.ford`` table of your `fpm.toml
1212
<https://fpm.fortran-lang.org>`_ file (*new in version 7.0*).
1313

14+
We recommend using ``fpm.toml`` for Ford settings as it allows comments and the
15+
syntax is a bit more forgiving. Ford is still run the same way in either case:
16+
17+
.. code:: console
18+
19+
$ ford <project-file.md>
20+
21+
1422
.. _sec-fpm-toml:
1523

1624
``fpm.toml`` File

example/example-project-file.md

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,3 @@
1-
---
2-
project: Example Project
3-
summary: This is a short example project
4-
that demonstrates many of Ford's features
5-
src_dir: ./src
6-
output_dir: ./doc
7-
project_github: https://github.com/cmacmackin/futility
8-
project_website: https://github.com
9-
summary: Some Fortran program which I wrote.
10-
author: John Doe
11-
author_description: I program stuff in Fortran.
12-
github: https://github.com/cmacmackin
13-
14-
fpp_extensions: fpp
15-
preprocess: true
16-
macro: HAS_DECREMENT
17-
predocmark: >
18-
docmark_alt: #
19-
predocmark_alt: <
20-
display: public
21-
protected
22-
source: false
23-
graph: true
24-
search: true
25-
extra_mods: json_module: http://jacobwilliams.github.io/json-fortran/
26-
futility: http://cmacmackin.github.io
27-
license: by-nc
28-
extra_filetypes: sh #
29-
max_frontpage_items: 4
30-
exclude: src/excluded_file.f90
31-
exclude_dir: src/excluded_directory
32-
page_dir: pages
33-
---
34-
351
Hi, my name is ${USER}.
362

373
This is a project which I wrote. This file will provide the documents. I'm

example/fpm.toml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
[extra.ford]
2+
project = "Example Project"
3+
src_dir = "./src"
4+
output_dir = "./doc"
5+
project_github = "https://github.com/cmacmackin/futility"
6+
project_website = "https://github.com"
7+
summary = "Some Fortran program which I wrote."
8+
author = "John Doe"
9+
author_description = "I program stuff in Fortran."
10+
github = "https://github.com/cmacmackin"
11+
12+
fpp_extensions = ["fpp"]
13+
preprocess = "true"
14+
macro = ["HAS_DECREMENT"]
15+
predocmark = ">"
16+
docmark_alt = "#"
17+
predocmark_alt = "<"
18+
display = ["public", "protected"]
19+
source = false
20+
graph = true
21+
search = true
22+
license = "by-nc"
23+
extra_filetypes = [{extension = "sh", comment="#"}]
24+
max_frontpage_items = "4"
25+
exclude = "src/excluded_file.f90"
26+
exclude_dir = "src/excluded_directory"
27+
page_dir = "pages"
28+
29+
[extra.ford.extra_mods]
30+
json_module = "http://jacobwilliams.github.io/json-fortran/"
31+
futility = "http://cmacmackin.github.io"
32+
iso_fortran_env = "https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fFORTRAN_005fENV.html"

ford/settings.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,12 @@ class ProjectSettings:
147147
extra_vartypes: list = field(default_factory=list)
148148
facebook: Optional[str] = None
149149
favicon: Path = FAVICON_PATH
150-
fixed_extensions: list = field(default_factory=lambda: ["f", "for", "F", "FOR"])
150+
fixed_extensions: List[str] = field(
151+
default_factory=lambda: ["f", "for", "F", "FOR"]
152+
)
151153
fixed_length_limit: bool = True
152154
force: bool = False
153-
fpp_extensions: list = field(
155+
fpp_extensions: List[str] = field(
154156
default_factory=lambda: ["F90", "F95", "F03", "F08", "F15", "F", "FOR"]
155157
)
156158
github: Optional[str] = None
@@ -168,11 +170,11 @@ class ProjectSettings:
168170
license: str = ""
169171
linkedin: Optional[str] = None
170172
lower: bool = False
171-
macro: list = field(default_factory=list)
173+
macro: List[str] = field(default_factory=list)
172174
mathjax_config: Optional[Path] = None
173175
max_frontpage_items: int = 10
174176
md_base_dir: Path = Path(".")
175-
md_extensions: list = field(default_factory=list)
177+
md_extensions: List[str] = field(default_factory=list)
176178
media_dir: Optional[Path] = None
177179
output_dir: Path = Path("./doc")
178180
page_dir: Optional[Path] = None

test/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import pytest
44
from textwrap import dedent
55
import subprocess
6+
from contextlib import contextmanager
7+
import os
68

79
# Ford default src folder
810
DEFAULT_SRC = "src"
@@ -39,3 +41,11 @@ def gfortran_is_not_installed():
3941
"""Returns False if gfortran is not (detectably) installed"""
4042
out = subprocess.run("command -v gfortran", shell=True, check=False)
4143
return out.returncode != 0
44+
45+
46+
@contextmanager
47+
def chdir(directory):
48+
oldwd = os.getcwd()
49+
os.chdir(directory)
50+
yield
51+
os.chdir(oldwd)

test/test_example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import shutil
22
import sys
3-
import os
43
import pathlib
54
import re
65
from urllib.parse import urlparse
@@ -11,6 +10,8 @@
1110
from bs4 import BeautifulSoup
1211
import pytest
1312

13+
from conftest import chdir
14+
1415

1516
pytestmark = pytest.mark.filterwarnings("ignore::bs4.MarkupResemblesLocatorWarning")
1617

@@ -29,15 +30,14 @@ def example_project(tmp_path_factory):
2930
tmp_path = tmp_path_factory.getbasetemp() / "example"
3031
shutil.copytree(this_dir / "../example", tmp_path)
3132

32-
with pytest.MonkeyPatch.context() as m:
33-
os.chdir(tmp_path)
33+
with pytest.MonkeyPatch.context() as m, chdir(tmp_path):
3434
m.setattr(sys, "argv", ["ford", "example-project-file.md"])
3535
ford.run()
3636

3737
with open(tmp_path / "example-project-file.md", "r") as f:
3838
project_file = f.read()
3939

40-
project_file, project_settings = ford.load_settings(project_file)
40+
project_file, project_settings = ford.load_settings(project_file, tmp_path)
4141
settings, _ = ford.parse_arguments({}, project_file, project_settings, tmp_path)
4242

4343
doc_path = tmp_path / "doc"

test/test_initialisation.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ class FakeFile:
1313
name = "test file"
1414

1515

16-
def test_quiet_false():
17-
_, data = ford.load_settings("quiet: False")
16+
def test_quiet_false(tmp_path):
17+
_, data = ford.load_settings("quiet: False", tmp_path)
1818
assert data.quiet is False
19-
_, data2 = ford.load_settings("quiet: True")
19+
_, data2 = ford.load_settings("quiet: True", tmp_path)
2020
assert data2.quiet is True
2121

2222

@@ -54,7 +54,7 @@ def test_quiet_command_line():
5454
assert data.quiet is False
5555

5656

57-
def test_list_input():
57+
def test_list_input(tmp_path):
5858
"""Check that setting a non-list option is turned into a single string"""
5959

6060
settings = """\
@@ -65,7 +65,7 @@ def test_list_input():
6565
one
6666
string
6767
"""
68-
_, data = ford.load_settings(dedent(settings))
68+
_, data = ford.load_settings(dedent(settings), tmp_path)
6969

7070
assert len(data.include) == 2
7171
assert data.summary == "This\nis\none\nstring"

test/test_projects/test_external_project.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from bs4 import BeautifulSoup
1212
import pytest
1313

14+
from conftest import chdir
1415

1516
REMOTE_TYPE_JSON: Dict[str, Any] = {
1617
"name": "remote_type",
@@ -109,17 +110,15 @@ def external_project(tmp_path_factory, monkeymodule):
109110

110111
# Run FORD in the two projects
111112
# First project has "externalize: True" and will generate JSON dump
112-
with monkeymodule.context() as m:
113-
os.chdir(external_project)
113+
with monkeymodule.context() as m, chdir(external_project):
114114
m.setattr(sys, "argv", ["ford", "doc.md"])
115115
ford.run()
116116

117117
def mock_open(*args, **kwargs):
118118
return MockResponse()
119119

120120
# Second project uses JSON from first to link to external modules
121-
with monkeymodule.context() as m:
122-
os.chdir(top_level_project)
121+
with monkeymodule.context() as m, chdir(top_level_project):
123122
m.setattr(sys, "argv", ["ford", "doc.md"])
124123
m.setattr(ford.external_project, "urlopen", mock_open)
125124
ford.run()

0 commit comments

Comments
 (0)