-
Notifications
You must be signed in to change notification settings - Fork 23
handle default prefixes #1304
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
base: develop
Are you sure you want to change the base?
handle default prefixes #1304
Changes from all commits
eb15446
427767f
c2a63ce
e5989c9
433436c
001471a
b66cb08
cd2cc13
e5d6068
bcc3974
2797780
53c9e01
4320ed9
997eaad
2ba471c
1f735d3
0c088a6
a31296b
630ac12
1d23091
008060d
933b4b2
cf2dc5b
616fb9c
904368f
a294254
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ### Patch Updates | ||
|
|
||
| - Refactored the git pre-commit to make sure the latest version is always used. Issue [#891](https://github.com/semanticarts/gist/issues/891) | ||
| - Updated setup.cmd to install tools/pre-commit-hook as .git/hooks/pre-commit | ||
| - New file tools/pre-commit-hook which just calls ./tools/pre-commit-code. | ||
| - Renamed tools/pre-commit to tools/pre-commit-code | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| ### Patch Updates | ||
|
|
||
| - Added a test in the git pre-commit hook to check for default PREFIX declarations in ontology files and cause the commit to fail if it finds one. For this to work, the setup.cmd command needs to be re-run to update the git hook. Issue [#898](https://github.com/semanticarts/gist/issues/898). | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| #!/usr/bin/env python3 | ||
| import re, sys, pathlib | ||
|
|
||
| # Get command line arguments | ||
| verbose = False | ||
| if "--verbose" in sys.argv: | ||
| sys.argv.remove("--verbose") | ||
| verbose = True | ||
|
|
||
| if len(sys.argv) != 2: | ||
| print("INVALID ARGUMENTS! Usage: ", sys.argv[0], " path/to/ontology/files [--verbose]") | ||
| sys.exit(1) | ||
|
|
||
| # Regex matches both Turtle (@prefix) and SPARQL (PREFIX) default declarations. | ||
| pattern = re.compile( | ||
| r'(?mi)^\s*(?:@prefix|prefix)\s*:\s*<[^>]+>\s*(?:\.\s*)?(?:#.*)?$' | ||
| ) | ||
|
|
||
| changed = False | ||
| for filePath in pathlib.Path(sys.argv[1]).glob("*.ttl"): | ||
| if verbose: | ||
| print("Checking for a default prefix in file: ", filePath) | ||
| currentText = filePath.read_text(encoding="utf-8") | ||
| newText = pattern.sub("", currentText).strip() | ||
| # Preserve the original file's trailing newlines | ||
| if currentText.endswith("\n\n"): | ||
| newText += "\n\n" | ||
| elif currentText.endswith("\n"): | ||
| newText += "\n" | ||
| if newText != currentText: | ||
| print("ERROR: there is a default PREFIX statement in file: ", filePath) | ||
| print("It must be removed from the file before you can commit your other changes.") | ||
| changed = True | ||
| # The following line would fix the file, then you would need to "git add filename" | ||
|
Collaborator
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. The serializer modifies files without having to re-add them. |
||
| # filePath.write_text(newText, encoding="utf-8") | ||
| # Exit 1 if anything changed, so you re-stage before committing. | ||
|
|
||
| # Exit 1 to indicate there are default PREFIX to remove | ||
| # If no change was needed, exit 0 and let the commit proceed. | ||
| sys.exit(1 if changed else 0) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,14 @@ | ||
| #!/usr/bin/env sh | ||
|
|
||
| # This file should be copied into the .git/hooks directory of the project. | ||
| # This file performs all the actual git pre-commit checks. | ||
| # It should be called by .git/hooks/pre-commit, which should be a copy of tools/pre-commit-hook. | ||
|
|
||
| # Get absolute path to this script | ||
| # SCRIPT=$(readlink -f "$0") | ||
| # SCRIPTPATH=$(dirname "$SCRIPT") | ||
|
|
||
| # Get root directory of this git repository | ||
| base_dir=$(git rev-parse --show-toplevel) | ||
|
|
||
| # Stops accidental commits to branches master, main, or develop. | ||
| BRANCH=`git rev-parse --abbrev-ref HEAD` | ||
|
|
@@ -11,24 +19,29 @@ then | |
| exit 1 | ||
| fi | ||
|
|
||
| # Get absolute path to this script | ||
| # SCRIPT=$(readlink -f "$0") | ||
| # SCRIPTPATH=$(dirname "$SCRIPT") | ||
| # Verify that there are no default PREFIX statements in the ontology files | ||
| "${base_dir}/tools/check_default_prefix/check_default_prefix.py" "${base_dir}/ontologies/" | ||
| rc=$? | ||
| if [ ! ${rc} -eq 0 ] ; then | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Get root directory of this git repository | ||
| base_dir=$(git rev-parse --show-toplevel) | ||
| # For repositories that have their ontology files in the project root directory | ||
|
Collaborator
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. I understand that you want to make this general, but since in this repository the ontologies are stored in the |
||
| "${base_dir}/tools/check_default_prefix/check_default_prefix.py" "${base_dir}/" | ||
| rc=$? | ||
| if [ ! ${rc} -eq 0 ] ; then | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Run the serializer | ||
| set -x | ||
|
|
||
| "${base_dir}/tools/serializer/pre-commit" | ||
|
|
||
| rc=$? | ||
| set +x | ||
|
|
||
| # echo "RESULT == ${rc}" | ||
| if [ ! ${rc} -eq 0 ] ; then | ||
| exit 1 | ||
| fi | ||
|
|
||
| exit 0 | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,18 @@ | ||||||
| #!/usr/bin/env sh | ||||||
|
|
||||||
| # This file should be copied into the .git/hooks directory of the project. | ||||||
|
Collaborator
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.
Suggested change
|
||||||
| # All it does is call ./tools/pre-commit-code | ||||||
|
|
||||||
| # Get root directory of this git repository | ||||||
| base_dir=$(git rev-parse --show-toplevel) | ||||||
|
|
||||||
| # Run the pre-commit code from the ./tools/ directory | ||||||
| "${base_dir}/tools/pre-commit-code" | ||||||
| rc=$? | ||||||
|
|
||||||
| # Return the response code from previous command | ||||||
| if [ ! ${rc} -eq 0 ] ; then | ||||||
| exit 1 | ||||||
| fi | ||||||
|
|
||||||
| exit 0 | ||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we have the pre-commit hook remove the prefix declaration, in the same way that the serializer reformats and makes some modifications?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more issue: the pre-commit hook issues an error and blocks the commit when I have a file either in the ontologies directory or the root directory that is not being committed. It should be looking only at the files being committed, like the serializer.
This is another reason not to include the base directory (comment below), but that will not fully address it, since such a file could exist in my ontologies directory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mainly because it was faster/easier to just block the commit and I was trying to get this done so the release could get done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. That's why I want to postpone this to the next release when we can take the time to do it right. There's no need for it to go into 14.0.0.