-
Notifications
You must be signed in to change notification settings - Fork 3
Added prefix argument to keywords tool #492
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b9cb453
Added prefix argument to keywords tool
francescalb 52a1c05
rewrote naming of arguments writing keywords
francescalb 1613664
Updated hook for generating keywords
francescalb 4311eb8
Apply suggestion from @jesper-friis
francescalb 400b21f
Apply suggestions from code review
francescalb ce7f4f8
Apply suggestion from @jesper-friis
francescalb b942034
Apply suggestion from @francescalb
francescalb 5bf7d35
Apply suggestion from @jesper-friis
francescalb 739a0fc
Apply suggestion from @jesper-friis
francescalb 74f8a11
Merge branch 'master' into prefixes-keywords-script
francescalb 6a542f6
Merge branch 'master' into prefixes-keywords-script
francescalb 390960e
pylint disable too many statements in keywords tool
francescalb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1635,6 +1635,10 @@ def save_markdown( | |
| keywords: Sequence of keywords to include. | ||
| classes: Include keywords that have these classes in their domain. | ||
| themes: Include keywords for these themes. | ||
| namespace_filter: A prefix, namespace or a sequence of these. | ||
| Keep only keywords within this namespace. | ||
| It is important that the namespace(s) are defined with | ||
| prefixes in the Keywords object. | ||
| explanation: Whether to include explanation of columns labels. | ||
| special: Whether to generate documentation of special | ||
| JSON-LD keywords. | ||
|
|
@@ -1822,7 +1826,7 @@ def _to_table(self, header: "Sequence", rows: "Iterable") -> list: | |
| return lines | ||
|
|
||
|
|
||
| def main(argv=None): | ||
| def main(argv=None): # pylint: disable=too-many-statements | ||
| """Main function providing CLI access to keywords.""" | ||
| import argparse # pylint: disable=import-outside-toplevel | ||
|
|
||
|
|
@@ -1873,20 +1877,20 @@ def main(argv=None): | |
| help="How to handle redifinition of existing keywords.", | ||
| ) | ||
| parser.add_argument( | ||
| "--context", | ||
| "--write-context", | ||
| "--write-json", | ||
| "-c", | ||
| metavar="FILENAME", | ||
| help="Generate JSON-LD context file.", | ||
| ) | ||
| parser.add_argument( | ||
| "--keywords", | ||
| "--markdown", | ||
| "--write-kw-md", | ||
| "-k", | ||
| metavar="FILENAME", | ||
| help="Generate keywords Markdown documentation.", | ||
| ) | ||
| parser.add_argument( | ||
| "--yaml", | ||
| "--write-kw-yaml", | ||
| "-y", | ||
| metavar="FILENAME", | ||
| help="Generate keywords YAML file.", | ||
|
|
@@ -1912,17 +1916,20 @@ def main(argv=None): | |
| "Keep only keywords with IRIs in " | ||
| "the namespace " | ||
| "provided by this option. Can be provided more that once. " | ||
| "To be used with the --keywords option. " | ||
| "To be used with the --write-kw-md option. " | ||
| "A namespace can be specified by its full IRI or by a pre-defined " | ||
| "prefix." | ||
| "Note that the namespace must be defined with a prefix. " | ||
| "If missing," | ||
| "it can be added with --prefix." | ||
| ), | ||
| ) | ||
| parser.add_argument( | ||
| "--kw", | ||
| metavar="KW1,KW2,...", | ||
| help=( | ||
| "Comma-separated list of keywords to include in generated table. " | ||
| "Implies --keywords." | ||
| "Implies --write-kw-md." | ||
| ), | ||
| ) | ||
| parser.add_argument( | ||
|
|
@@ -1931,7 +1938,7 @@ def main(argv=None): | |
| help=( | ||
| "Generate keywords Markdown documentation for any keywords who's " | ||
| "domain is in the comma-separated list CLASSES. " | ||
| "Implies --keywords." | ||
| "Implies --write-kw-md." | ||
| ), | ||
| ) | ||
| parser.add_argument( | ||
|
|
@@ -1940,15 +1947,25 @@ def main(argv=None): | |
| help=( | ||
| "Generate keywords Markdown documentation for any keywords that " | ||
| "belong to one of the themes in the comma-separated list THEMES. " | ||
| "Implies --keywords." | ||
| "Implies --write-kw-md, --write-kw-json or --write-kw-yaml." | ||
| ), | ||
| ) | ||
| parser.add_argument( | ||
| "--prefixes", | ||
| "-p", | ||
| "--write-prefixes", | ||
| "-w", | ||
francescalb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| metavar="FILENAME", | ||
| help="Generate prefixes Markdown documentation.", | ||
| help="Write prefixes Markdown file.", | ||
| ) | ||
| parser.add_argument( | ||
| "--prefix", | ||
| "-p", | ||
| metavar="PREFIX:NAMESPACE", | ||
| default=[], | ||
| action="append", | ||
| help="Add the prefix given as tuple PREFIX=NAMESPACE, " | ||
| "can be used multiple times.", | ||
| ) | ||
|
|
||
| parser.add_argument( | ||
| "--list-themes", | ||
| action="store_true", | ||
|
|
@@ -1984,6 +2001,16 @@ def main(argv=None): | |
|
|
||
| kw = Keywords(theme=default_theme) | ||
|
|
||
| if args.prefix: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice :-) |
||
| for p in asseq(args.prefix): | ||
| if ":" not in p: | ||
| parser.error( | ||
| f"Invalid prefix definition '{p}'. Must be of the " | ||
| "form PREFIX:NAMESPACE." | ||
| ) | ||
| prefix, namespace = p.split(":", 1) | ||
| kw.add_prefix(prefix, namespace, replace=True) | ||
|
|
||
| for theme in args.theme[1:]: | ||
| if theme: | ||
| kw.add_theme(theme, strict=args.strict, redefine=args.redefine) | ||
|
|
@@ -1995,12 +2022,12 @@ def main(argv=None): | |
|
|
||
| kw.add(args.input, args.format, strict=args.strict, redefine=args.redefine) | ||
|
|
||
| if args.context: | ||
| kw.save_context(args.context) | ||
| if args.write_context: | ||
| kw.save_context(args.write_context) | ||
|
|
||
| if args.keywords or args.kw or args.classes or args.themes: | ||
| if args.write_kw_md or args.kw or args.classes or args.themes: | ||
| kw.save_markdown( | ||
| args.keywords, | ||
| args.write_kw_md, | ||
| keywords=args.kw.split(",") if args.kw else None, | ||
| classes=args.classes.split(",") if args.classes else None, | ||
| themes=args.themes.split(",") if args.themes else None, | ||
|
|
@@ -2009,11 +2036,13 @@ def main(argv=None): | |
| namespace_filter=args.namespace_filter, | ||
| ) | ||
|
|
||
| if args.prefixes: | ||
| kw.save_markdown_prefixes(args.prefixes) | ||
| if args.write_prefixes: | ||
| kw.save_markdown_prefixes(args.write_prefixes) | ||
|
|
||
| if args.yaml: | ||
| kw.save_yaml(args.yaml, namespace_filter=args.namespace_filter) | ||
| if args.write_kw_yaml: | ||
| kw.save_yaml( | ||
| args.write_kw_yaml, namespace_filter=args.namespace_filter | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.