-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for wrapper & merge_vocab Closes #17 See merge request nfdi4cat/ta1-ontologies/voc4cat-tool!43
- Loading branch information
Showing
15 changed files
with
774 additions
and
119 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# -*- coding: utf-8 -*- | ||
from importlib.metadata import PackageNotFoundError, version | ||
|
||
try: | ||
__version__ = version("voc4cat") | ||
except PackageNotFoundError: | ||
# package is not installed | ||
try: | ||
from ._version import version as __version__ | ||
except ImportError: | ||
__version__ = "0.0.0" |
This file contains 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 |
---|---|---|
@@ -1,52 +1,55 @@ | ||
# -*- coding: utf-8 -*- | ||
# This script is mainly useful for CI. | ||
import os | ||
import shutil | ||
import subprocess | ||
import sys | ||
from pathlib import Path | ||
|
||
VOCAB_DIR = Path("vocabularies") | ||
OUTBOX = Path("outbox") | ||
|
||
|
||
def main(outbox, vocab): | ||
def main(ttl_inbox, vocab): | ||
""" | ||
Sync ttl-files in outbox and vocab folder | ||
Sync ttl-files from ttl_inbox into vocab folder | ||
New files are copied, existing files are synced by git merge-file. | ||
""" | ||
retcode = 0 | ||
for p in os.listdir(outbox): | ||
new = outbox / Path(p) | ||
for p in os.listdir(ttl_inbox): | ||
new = ttl_inbox / Path(p) | ||
if not new.suffix == ".ttl" or new.is_dir(): | ||
print(f'skipping "{new}"') | ||
print(f'Skipping "{new}"') | ||
continue | ||
if os.path.exists(vocab / Path(new).name): | ||
exists = vocab / Path(new).name | ||
cmd = ["git", "merge-file", "--theirs", str(exists), str(exists), str(new)] | ||
print(" ".join(cmd)) | ||
print("Running cmd: {0}".format(" ".join(cmd))) | ||
outp = subprocess.run(cmd, capture_output=True) | ||
print(outp.stdout) | ||
if retcode := outp.returncode != 0: | ||
break | ||
else: | ||
print(f'copying "{new}" to "{vocab}"') | ||
print(f'Copying "{new}" to "{vocab}"') | ||
shutil.copy(new, vocab) | ||
return retcode | ||
|
||
|
||
def run(): | ||
if len(sys.argv) != 3: | ||
print('Usage: "python merge_vocab.py outbox_dir vocab_dir') | ||
sys.exit(1) | ||
outbox, vocab = sys.argv[1:3] | ||
def main_cli(args=None): | ||
|
||
if args is None: # script run via entrypoint | ||
args = sys.argv[1:] | ||
|
||
if len(args) != 2: | ||
print("Usage: python merge_vocab.py <outbox_dir> <vocab_dir>") | ||
return 1 | ||
outbox, vocab = args | ||
if os.path.exists(outbox) and os.path.exists(vocab): | ||
retcode = main(Path(outbox), Path(vocab)) | ||
sys.exit(retcode) | ||
else: | ||
print(f'This script requires both folders to exist: "{outbox}" and "{vocab}"') | ||
sys.exit(1) | ||
return retcode | ||
|
||
print(f'This script requires both folders to exist: "{outbox}" and "{vocab}"') | ||
return 1 | ||
|
||
|
||
if __name__ == "__main__": | ||
run() | ||
err = main_cli(sys.argv[1:]) | ||
sys.exit(err) |
This file contains 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
Oops, something went wrong.