ose-cli 0.2.5__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
ose_cli/__init__.py ADDED
@@ -0,0 +1,38 @@
1
+ """
2
+ OSE CLI - Command Line Interface for OntoSpreadEd
3
+
4
+ This package provides CLI commands for the OntoSpreadEd
5
+ ontology spreadsheet editor.
6
+ """
7
+
8
+ __version__ = "0.1.0"
9
+
10
+ import functools
11
+
12
+ from flask import Flask
13
+ from flask.cli import AppGroup
14
+ from injector import Injector, inject
15
+
16
+
17
+ def init_app(app: Flask, injector: Injector):
18
+ ose_group = AppGroup("ose", help="Commands for OntoSpreadEd")
19
+
20
+ cli_groups = []
21
+
22
+ from .release import init_commands as release
23
+ cli_groups.append(release)
24
+
25
+ from .externals import init_commands as externals
26
+ cli_groups.append(externals)
27
+
28
+ def with_injector(fn):
29
+ @functools.wraps(fn)
30
+ def wrapper(*args, **kwargs):
31
+ return injector.call_with_injection(callable=inject(fn), args=args, kwargs=kwargs)
32
+
33
+ return wrapper
34
+
35
+ for init_group in cli_groups:
36
+ init_group(ose_group, with_injector)
37
+
38
+ app.cli.add_command(ose_group)
ose_cli/externals.py ADDED
@@ -0,0 +1,65 @@
1
+ import json
2
+ import logging
3
+ import os
4
+ import shutil
5
+ from typing import Callable, Any, Dict, Tuple, Optional
6
+
7
+ import click
8
+ from flask.cli import AppGroup
9
+
10
+ from ..commands.CLICommandContext import CLICommandContext
11
+ from ..commands.ImportExternalCommand import ImportExternalCommand
12
+ from ..model.ReleaseScript import ReleaseScript
13
+
14
+ logger = logging.getLogger(__name__)
15
+
16
+
17
+ def init_commands(cli: AppGroup, inject: Callable[[Any], Callable[[Tuple[Any, ...], Dict[str, Any]], Any]]):
18
+ @cli.group("externals")
19
+ def group():
20
+ pass
21
+
22
+ @group.command("build")
23
+ @click.option("--out", "-o", default=None)
24
+ @click.option("--release-script", "-r", default=".onto-ed/release_script.json")
25
+ @click.option("--local-path", "-l", default=".")
26
+ @click.option('-v', '--verbose', count=True, default=2)
27
+ @inject
28
+ def build(release_script: str, local_path: str, verbose: int, out: Optional[str]):
29
+ # set log level
30
+ log_level = logging.WARN if verbose == 1 else (
31
+ logging.INFO if verbose == 2 else (
32
+ logging.DEBUG if verbose >= 3 else logging.ERROR))
33
+
34
+ if not isinstance(log_level, int):
35
+ raise ValueError('Invalid log level: %s' % log_level)
36
+ logging.basicConfig(level=log_level)
37
+ logging.root.setLevel(log_level)
38
+
39
+ logger.info(f"Loading release script from {release_script}")
40
+ with open(release_script, "r") as f:
41
+ data = json.load(f)
42
+ script = ReleaseScript.from_json(data)
43
+
44
+ with CLICommandContext(local_path) as context:
45
+ command = ImportExternalCommand(context)
46
+
47
+ logger.info("Running external build command")
48
+ result, ok = command.run(script, local_path)
49
+
50
+ if not ok or result.has_errors():
51
+ logger.error("Command failed. Check the logs above!")
52
+ return 1
53
+
54
+ outfile = context.local_name(script.external.target.file)
55
+
56
+ if out is None:
57
+ out = os.path.join(local_path, script.external.target.file)
58
+
59
+ out = os.path.abspath(out)
60
+ outfile = os.path.abspath(outfile)
61
+
62
+ if out != outfile:
63
+ shutil.copy(outfile, out)
64
+
65
+ logger.info(f"External file written to {outfile}")
ose_cli/main.py ADDED
@@ -0,0 +1,10 @@
1
+ import subprocess
2
+ import sys
3
+
4
+
5
+ def main():
6
+ subprocess.run([sys.executable, "-m", "flask", "--app", "ose:create_app", "ose", *sys.argv[1:]])
7
+
8
+
9
+ if __name__ == "__main__":
10
+ main()
ose_cli/release.py ADDED
@@ -0,0 +1,9 @@
1
+ from typing import Callable, Any, Dict, Tuple
2
+
3
+ from flask.cli import AppGroup
4
+
5
+
6
+ def init_commands(cli: AppGroup, _: Callable[[Any], Callable[[Tuple[Any, ...], Dict[str, Any]], Any]]):
7
+ @cli.group("release")
8
+ def group():
9
+ pass
@@ -0,0 +1,11 @@
1
+ Metadata-Version: 2.4
2
+ Name: ose-cli
3
+ Version: 0.2.5
4
+ Summary: CLI for OntoSpreadEd - Ontology spreadsheet editor
5
+ Requires-Python: >=3.12
6
+ Requires-Dist: ose-core==0.2.5
7
+ Requires-Dist: Flask==2.3.3
8
+ Requires-Dist: Flask-Injector
9
+ Provides-Extra: dev
10
+ Requires-Dist: pytest; extra == "dev"
11
+ Requires-Dist: ruff; extra == "dev"
@@ -0,0 +1,9 @@
1
+ ose_cli/__init__.py,sha256=3PB9ZtTnDgLz0PvcE8KjGUqTecjnve0yTQ8dYPGY-SU,914
2
+ ose_cli/externals.py,sha256=Vw21KKSbc2WiicArz-g5UAVO0FjKi-I9MqaRYNFcg_4,2263
3
+ ose_cli/main.py,sha256=_cFZ51ubVuWpiYGheSUnDXhTZFbYUfEsTmqT2L5znUI,184
4
+ ose_cli/release.py,sha256=iN66qTBbnox-Is5uJZyMhLxbrUtwzJsSOAMpxTIf3qA,240
5
+ ose_cli-0.2.5.dist-info/METADATA,sha256=GYgDejcAGKjtuskJ6AFBcQiAxZ4JEXvRtqC9At15WnM,318
6
+ ose_cli-0.2.5.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
7
+ ose_cli-0.2.5.dist-info/entry_points.txt,sha256=A6dBgaCxrCersmGnYMsPuhd71d5A3bDbzN9hMpxnqEA,42
8
+ ose_cli-0.2.5.dist-info/top_level.txt,sha256=hnVK2KPjG58-mU2eg2WsMzEm_Do0g0eUlJI2-KVh-Mc,8
9
+ ose_cli-0.2.5.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.10.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ose = ose_cli.main:main
@@ -0,0 +1 @@
1
+ ose_cli