From 34439a1b2103ff8531b743b6b9796c16feacaa37 Mon Sep 17 00:00:00 2001 From: "i.nueske" <i.nueske@indiscale.com> Date: Mon, 16 Dec 2024 17:39:27 +0100 Subject: [PATCH] MNT: Fix pandoc_header_tools.get_header() name collision --- CHANGELOG.md | 2 ++ src/caosadvancedtools/pandoc_header_tools.py | 37 ++++++++++---------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a118d98..825358c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `h5` instead of `h5-crawler` - `dev`, `doc`, `test` and `all` are new, they install the dependencies for developing, testing, documentation and everything. +- The `pandoc_header_tools.get_header()` parameter `add_header` has been renamed to `add_header_to_file` + to resolve a name collision. ### Deprecated ### diff --git a/src/caosadvancedtools/pandoc_header_tools.py b/src/caosadvancedtools/pandoc_header_tools.py index a0191e5a..88cdbc19 100644 --- a/src/caosadvancedtools/pandoc_header_tools.py +++ b/src/caosadvancedtools/pandoc_header_tools.py @@ -68,31 +68,30 @@ description: """ -def get_header(filename, add_header=False): - """Open an md file identified by filename and read out the yaml -header. +def get_header(filename, add_header_to_file=False): + """Open an md file identified by filename and read out the yaml header. -filename can also be a folder. In this case folder/README.md will be used for -getting the header. + filename can also be a folder. In this case folder/README.md will be used + for getting the header. -If a header is found a tuple is returned: (first yaml header line index, last+1 -yaml header line index, header) + If a header is found a tuple is returned: (first yaml header line index, + last+1 yaml header line index, header) -Otherwise, if `add_header` is True, a header is added and the function is called -again. + Otherwise, if `add_header_to_file` is True, a header is added and the + function is called again. -The header is normalized in the following way: + The header is normalized in the following way: -- If the value to a key is a string, a list with that string as only element is - returned. + - If the value to a key is a string, a list with that string as only + element is returned. -From https://pandoc.org/MANUAL.html: - -A YAML metadata block is a valid YAML object, delimited by a line of three -hyphens (---) at the top and a line of three hyphens (---) or three dots (...) -at the bottom. A YAML metadata block may occur anywhere in the document, but if -it is not at the beginning, it must be preceded by a blank line. + From https://pandoc.org/MANUAL.html: + A YAML metadata block is a valid YAML object, delimited by a line of three + hyphens (---) at the top and a line of three hyphens (---) or three + dots (...) at the bottom. A YAML metadata block may occur anywhere in the + document, but if it is not at the beginning, it must be preceded by a blank + line. """ if os.path.isdir(filename): @@ -146,7 +145,7 @@ it is not at the beginning, it must be preceded by a blank line. raise NoValidHeader(filename) return (found_1, found_2, clean_header(yaml_part)) - if not add_header: + if not add_header_to_file: raise NoValidHeader(filename) else: print("Adding header in: {fn}".format(fn=filename)) -- GitLab