Skip to content

Commit eb6bc48

Browse files
committed
Added --version option to CLI
1 parent 4618003 commit eb6bc48

File tree

7 files changed

+37
-8
lines changed

7 files changed

+37
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
testdata/
2+
site/
23

34
# Byte-compiled / optimized / DLL files
45
__pycache__/

CHANGES.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
## Version 0.2.1 (in development)
1+
## Version 0.3.0 (in development)
22

33
### Enhancements
44

5-
* It is now possible to configure runtime profiling of the `zappend`
6-
processing using the new configuration setting `profiling`. [#39]
7-
85
* Allow for passing custom slice sources via the configuration.
96
The new configuration setting `slice_source` is the name of a class
107
derived from `zappend.api.SliceSource` or a function that creates an instance
@@ -13,6 +10,11 @@
1310
passed to the constructor of the specified class or the factory function.
1411
[#27]
1512

13+
* It is now possible to configure runtime profiling of the `zappend`
14+
processing using the new configuration setting `profiling`. [#39]
15+
16+
* Added `--version` option to CLI. [#42]
17+
1618
* Using `sizes` instead of `dims` attribute of `xarray.Dataset` in
1719
implementation code. [#25]
1820

docs/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Options:
2222
'target_dir' configuration field.
2323
--dry-run Run the tool without creating, changing, or deleting
2424
any files.
25-
--profiling TEXT Path for profiling output. Switches on profiling.
25+
--version Show version and exit.
2626
--help-config json|md Show configuration help and exit.
2727
--help Show this message and exit.
2828
```

setup.cfg

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = zappend
33
version = attr: zappend.__version__
44
author = Norman Fomferra
5-
description = Tool for creating and updating a Zarr datacubes from smaller slices
5+
description = Tool for robustly creating and updating Zarr datacubes from smaller slices
66
long_description = file: README.md
77
long_description_content_type = text/markdown
88
keywords = analysis ready data, data science, datacube, xarray, zarr
@@ -14,6 +14,7 @@ project_urls =
1414
Changelog = https://github.com/bcdev/zappend/blob/main/CHANGES.md
1515

1616
[options]
17+
packages = find:
1718
python_requires = >=3.10
1819
install_requires = file: requirements.txt
1920

@@ -25,6 +26,13 @@ doc = file: requirements-doc.txt
2526
console_scripts =
2627
zappend = zappend.cli:zappend
2728

29+
[options.packages.find]
30+
exclude =
31+
test*
32+
doc*
33+
site*
34+
htmlcov*
35+
2836
[flake8]
2937
max-line-length = 88
3038
extend-ignore = E203

tests/test_cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import unittest
66
from click.testing import CliRunner
77

8+
from zappend import __version__
89
from zappend.cli import zappend
910
from zappend.fsutil.fileobj import FileObj
1011
from .helpers import clear_memory_fs
@@ -15,6 +16,13 @@ class CliTest(unittest.TestCase):
1516
def setUp(self):
1617
clear_memory_fs()
1718

19+
def test_version(self):
20+
runner = CliRunner()
21+
# noinspection PyTypeChecker
22+
result = runner.invoke(zappend, ["--version"])
23+
self.assertEqual(0, result.exit_code)
24+
self.assertEqual(f"{__version__}\n", result.output)
25+
1826
def test_help(self):
1927
runner = CliRunner()
2028
# noinspection PyTypeChecker

zappend/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# Permissions are hereby granted under the terms of the MIT License:
33
# https://opensource.org/licenses/MIT.
44

5-
__version__ = "0.2.1.dev0"
5+
__version__ = "0.3.0.dev0"

zappend/cli.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
is_flag=True,
2929
help="Run the tool without creating, changing," " or deleting any files.",
3030
)
31+
@click.option(
32+
"--version",
33+
is_flag=True,
34+
help="Show version and exit.",
35+
)
3136
@click.option(
3237
"--help-config",
3338
metavar="json|md",
@@ -39,6 +44,7 @@ def zappend(
3944
config: tuple[str, ...],
4045
target: str | None,
4146
dry_run: bool,
47+
version: bool,
4248
help_config: str | None,
4349
):
4450
"""Create or update a Zarr datacube TARGET from slice datasets SLICES.
@@ -49,6 +55,10 @@ def zappend(
4955
be rolled back, in case the append operation fails. This ensures integrity of the
5056
target data cube given by TARGET or in CONFIG.
5157
"""
58+
if version:
59+
from zappend import __version__
60+
61+
return click.echo(f"{__version__}")
5262

5363
if help_config:
5464
return _show_config_help(help_config)
@@ -70,7 +80,7 @@ def _show_config_help(config_help_format):
7080
from zappend.config import get_config_schema
7181

7282
text = get_config_schema(format=config_help_format)
73-
print(text + "\n")
83+
click.echo(text + "\n")
7484

7585

7686
if __name__ == "__main__":

0 commit comments

Comments
 (0)