Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch default preprocessor to pcpp #570

Merged
merged 1 commit into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/user_guide/project_file_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -487,8 +487,7 @@ preprocessor
The preproccessor command to use on files with extensions in `fpp_extensions
<option-fpp_extensions>`. Can include flags as needed. Preprocessor macros and
include paths specified in the project file will automatically be appended using
the CPP interface, which is fairly standard. (*default*:
``cpp -traditional-cpp -E -D__GFORTRAN__``)
the CPP interface, which is fairly standard. (*default*: ``pcpp -D__GFORTRAN__``)

Documentation Markers
---------------------
Expand Down
7 changes: 4 additions & 3 deletions docs/user_guide/writing_documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ parsing them for documentation. This behaviour can `be disabled
<option-preprocess>` or `different extensions <option-fpp_extensions>`
can be specified, if desired. Note that any syntax-highlighted source
code which is displayed in the output will be shown in its
non-preprocessed form. The default preprocessor is CPP in legacy mode
(the same as used by gfortran), but arbitrary preprocessors may be
specified.
non-preprocessed form. The default preprocessor is `pcpp
<https://github.com/ned14/pcpp>`_, which is a C preprocessor
implemented in Python, but you can `customise this command
<option-preprocessor>`.

Markdown
--------
Expand Down
2 changes: 1 addition & 1 deletion ford/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ class ProjectSettings:
predocmark: str = ">"
predocmark_alt: str = "|"
preprocess: bool = True
preprocessor: str = "cpp -traditional-cpp -E -D__GFORTRAN__"
preprocessor: str = "pcpp -D__GFORTRAN__"
print_creation_date: bool = False
privacy_policy_url: Optional[str] = None
proc_internals: bool = False
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ dependencies = [
"tqdm ~= 4.64.0",
"tomli >= 1.1.0 ; python_version < '3.11'",
"rich >= 12.0.0",
"pcpp >= 1.30",
]
dynamic = ["version"]

Expand Down
17 changes: 2 additions & 15 deletions test/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@

import ford.reader as reader
from ford.reader import _contains_unterminated_string
import pytest

from conftest import gfortran_is_not_installed

RE_WHITE = re.compile(r"\s+")

Expand Down Expand Up @@ -168,9 +165,6 @@ def test_multiline_string(copy_fortran_file):
assert lines == expected


@pytest.mark.skipif(
gfortran_is_not_installed(), reason="Requires gfortran to be installed"
)
def test_preprocessor(copy_fortran_file):
"""Check some basic preprocessing is applied"""

Expand All @@ -184,18 +178,13 @@ def test_preprocessor(copy_fortran_file):
lines = "\n".join(
list(
reader.FortranReader(
str(filename),
preprocessor=["cpp", "-traditional-cpp", "-E"],
macros=["SUB_NAME=foo"],
str(filename), preprocessor=["pcpp"], macros=["SUB_NAME=foo"]
)
)
)
assert "foo" in lines


@pytest.mark.skipif(
gfortran_is_not_installed(), reason="Requires gfortran to be installed"
)
def test_preprocessor_warning(copy_fortran_file):
"""Check preprocessing is still done even if there are warnings"""

Expand All @@ -210,9 +199,7 @@ def test_preprocessor_warning(copy_fortran_file):
lines = "\n".join(
list(
reader.FortranReader(
str(filename),
preprocessor=["cpp", "-traditional-cpp", "-E"],
macros=["SUB_NAME=foo"],
str(filename), preprocessor=["pcpp"], macros=["SUB_NAME=foo"]
)
)
)
Expand Down