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

Split project options out into separate file #449

Closed
ZedThree opened this issue Sep 15, 2022 · 2 comments · Fixed by #547
Closed

Split project options out into separate file #449

ZedThree opened this issue Sep 15, 2022 · 2 comments · Fixed by #547

Comments

@ZedThree
Copy link
Member

See #448 for one motivation (separate encoding for options file and index page).

Another motivation is that the markdown metadata processing extension is a bit awkward, and using a proper config file format would make both parsing and writing the options a bit easier (for example, lists are currently a pain to write).

@awvwgk
Copy link

awvwgk commented Oct 23, 2022

Maybe FORD could leverage the fpm package manifest using the free table extra:

[extra.ford]
project = "Example Project"
src_dir = ["./src"]
output_dir = ["./doc"]
project_github = "https://github.com/cmacmackin/futility"
project_website = "https://github.com/"
summary = "Some Fortran program which I wrote."
author = "John Doe"
author_description = "I program stuff in Fortran."
github = "https://github.com/cmacmackin"
email = "john.doe@example.com"
fpp_extensions = ["fpp"]
preprocess = true
macro = ["HAS_DECREMENT"]
predocmark = ">"
docmark_alt = "#"
predocmark_alt = "<"
display = ["public", "protected"]
source = false
graph= true
search = true
extra_mods.json_module = "http://jacobwilliams.github.io/json-fortran/"
extra_mods.futility = "http://cmacmackin.github.io/"
extra_mods.iso_fortran_env = "https://gcc.gnu.org/onlinedocs/gfortran/ISO_005fFORTRAN_005fENV.html"
license = "by-nc"
extra_filetypes = "sh"
max_frontpage_items = 4
exclude = ["excluded_file.f90"]
exclude_dir = ["src/excluded_directory"]

With a library like tomli, tomlkit or pytomlpp it should be straight-forward to read as well if you are okay with an additional dependency:

from pathlib import Path
# Choose any available TOML library in Python (alternatively decide for one)
for impl in ["tomllib", "tomli", "tomlkit", "pytomlpp"]:
    try:
        tomllib = __import__(impl)
        break
    except ModuleNotFoundError:
        tomllib = None

with open(Path("fpm.toml"), "rb") as fd:
    data = tomllib.load(fd)

ford_data = data.get("extra", {}).get("ford")

There is also fpm.metadata which allows to directly load the complete manifest:

from pathlib import Path
from fpm.metadata import load_manifest

manifest = load_manifest(Path("fpm.toml"))
ford_data = manifest.extra.get("ford")

@ZedThree
Copy link
Member Author

That sounds like a great idea @awvwgk! PRs welcome 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants