cwms-cli 0.3.0__tar.gz → 0.3.2__tar.gz
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.
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/PKG-INFO +1 -1
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/__main__.py +15 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/utils/__init__.py +3 -3
- cwms_cli-0.3.2/cwmscli/utils/click_help.py +64 -0
- cwms_cli-0.3.2/cwmscli/utils/version.py +35 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/pyproject.toml +1 -1
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/LICENSE +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/README.md +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/__init__.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/callbacks/__init__.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/blob.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/commands_cwms.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/.gitignore +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/README.md +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/__init__.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/__main__.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/examples/complete_config.json +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/examples/hourly.json +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/examples/minutes.json +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/tests/__init__.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/tests/data/.gitignore +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/tests/data/expected_brok_output.json +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/tests/data/sample_brok.csv +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/tests/data/sample_config.json +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/tests/skip_test_integration_pipeline.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/tests/test_dateutils.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/tests/test_expressions.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/tests/test_fileio.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/utils/__init__.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/utils/dateutils.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/utils/expression.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/utils/fileio.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/utils/logging.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/utils/terminal.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/shef_critfile_import.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/load/README.md +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/load/__init__.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/load/__main__.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/load/location/location.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/load/location/location_ids.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/load/location/location_ids_bygroup.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/load/root.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/load/timeseries/timeseries.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/load/timeseries/timeseries_ids.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/requirements.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/usgs/__init__.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/usgs/__main__.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/usgs/getUSGS_ratings_cda.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/usgs/getusgs_cda.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/usgs/getusgs_measurements_cda.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/usgs/rating_ini_file_import.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/utils/colors.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/utils/deps.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/utils/io.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/utils/logging/__init__.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/utils/logging/formatters.py +0 -0
- {cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/utils/ssl_errors.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cwms-cli
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.2
|
|
4
4
|
Summary: Command line utilities for Corps Water Management Systems (CWMS) python scripts. This is a collection of shared scripts across the enterprise Water Management Enterprise System (WMES) teams.
|
|
5
5
|
License: LICENSE
|
|
6
6
|
License-File: LICENSE
|
|
@@ -8,11 +8,19 @@ import click
|
|
|
8
8
|
from cwmscli.commands import commands_cwms
|
|
9
9
|
from cwmscli.load import __main__ as load
|
|
10
10
|
from cwmscli.usgs import usgs_group
|
|
11
|
+
from cwmscli.utils.click_help import add_version_to_help_tree
|
|
11
12
|
from cwmscli.utils.logging import LoggingConfig, setup_logging
|
|
12
13
|
from cwmscli.utils.ssl_errors import is_cert_verify_error, ssl_help_text
|
|
14
|
+
from cwmscli.utils.version import get_cwms_cli_version
|
|
13
15
|
|
|
14
16
|
|
|
15
17
|
@click.group(context_settings=dict(help_option_names=["-h", "--help"]))
|
|
18
|
+
@click.version_option(
|
|
19
|
+
get_cwms_cli_version(),
|
|
20
|
+
"--version",
|
|
21
|
+
"-V",
|
|
22
|
+
message="cwms-cli version %(version)s",
|
|
23
|
+
)
|
|
16
24
|
@click.option(
|
|
17
25
|
"--log-file",
|
|
18
26
|
type=click.Path(dir_okay=False, writable=True, resolve_path=True),
|
|
@@ -46,6 +54,7 @@ cli.add_command(commands_cwms.shefcritimport)
|
|
|
46
54
|
cli.add_command(commands_cwms.csv2cwms_cmd)
|
|
47
55
|
cli.add_command(commands_cwms.blob_group)
|
|
48
56
|
cli.add_command(load.load_group)
|
|
57
|
+
add_version_to_help_tree(cli)
|
|
49
58
|
|
|
50
59
|
|
|
51
60
|
def main() -> None:
|
|
@@ -60,9 +69,15 @@ def main() -> None:
|
|
|
60
69
|
"on",
|
|
61
70
|
}
|
|
62
71
|
try:
|
|
72
|
+
if len(sys.argv) == 1:
|
|
73
|
+
cli.main(args=["--help"], prog_name="cwms-cli", standalone_mode=False)
|
|
74
|
+
raise SystemExit(0)
|
|
63
75
|
cli(standalone_mode=False)
|
|
64
76
|
except SystemExit:
|
|
65
77
|
raise
|
|
78
|
+
except click.ClickException as e:
|
|
79
|
+
e.show()
|
|
80
|
+
raise SystemExit(e.exit_code)
|
|
66
81
|
except Exception as e:
|
|
67
82
|
if is_cert_verify_error(e) and not debug:
|
|
68
83
|
# Keep this short, no stack trace.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import logging
|
|
1
|
+
import logging as py_logging
|
|
2
2
|
|
|
3
3
|
import click
|
|
4
4
|
|
|
@@ -12,10 +12,10 @@ def to_uppercase(ctx, param, value):
|
|
|
12
12
|
def _set_log_level(ctx, param, value):
|
|
13
13
|
if value is None:
|
|
14
14
|
return
|
|
15
|
-
level = getattr(
|
|
15
|
+
level = getattr(py_logging, value.upper(), None)
|
|
16
16
|
if level is None:
|
|
17
17
|
raise click.BadParameter(f"Invalid log level: {value}")
|
|
18
|
-
|
|
18
|
+
py_logging.getLogger().setLevel(level)
|
|
19
19
|
return value
|
|
20
20
|
|
|
21
21
|
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
import click
|
|
6
|
+
|
|
7
|
+
from cwmscli.utils import colors
|
|
8
|
+
from cwmscli.utils.version import get_cwms_cli_version
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _render_version_line(ctx: click.Context) -> str:
|
|
12
|
+
# Match existing CLI color behavior: disable color for non-TTY, --no-color, or --log-file.
|
|
13
|
+
argv = sys.argv[1:]
|
|
14
|
+
no_color = "--no-color" in argv
|
|
15
|
+
has_log_file = ("--log-file" in argv) or any(
|
|
16
|
+
arg.startswith("--log-file=") for arg in argv
|
|
17
|
+
)
|
|
18
|
+
allow_color = sys.stdout.isatty() and (not no_color) and (not has_log_file)
|
|
19
|
+
colors.set_enabled(allow_color)
|
|
20
|
+
return f"Version: {colors.c(get_cwms_cli_version(), 'cyan', bright=True)}"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def _inject_version_line(help_text: str, ctx: click.Context) -> str:
|
|
24
|
+
lines = help_text.splitlines()
|
|
25
|
+
if not lines:
|
|
26
|
+
return help_text
|
|
27
|
+
|
|
28
|
+
plain_version_line = f"Version: {get_cwms_cli_version()}"
|
|
29
|
+
if any(line.strip() == plain_version_line for line in lines):
|
|
30
|
+
return help_text
|
|
31
|
+
|
|
32
|
+
version_line = _render_version_line(ctx)
|
|
33
|
+
if lines[0].startswith("Usage:"):
|
|
34
|
+
lines.insert(1, version_line)
|
|
35
|
+
else:
|
|
36
|
+
lines.insert(0, version_line)
|
|
37
|
+
return "\n".join(lines)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def _wrap_get_help(command: click.Command) -> None:
|
|
41
|
+
original_get_help = command.get_help
|
|
42
|
+
|
|
43
|
+
def get_help_with_version(ctx: click.Context) -> str:
|
|
44
|
+
return _inject_version_line(original_get_help(ctx), ctx)
|
|
45
|
+
|
|
46
|
+
command.get_help = get_help_with_version # type: ignore[method-assign]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def add_version_to_help_tree(command: click.Command) -> None:
|
|
50
|
+
"""Patch a command tree so every help output shows the CLI version."""
|
|
51
|
+
stack = [command]
|
|
52
|
+
seen: set[int] = set()
|
|
53
|
+
|
|
54
|
+
while stack:
|
|
55
|
+
cmd = stack.pop()
|
|
56
|
+
obj_id = id(cmd)
|
|
57
|
+
if obj_id in seen:
|
|
58
|
+
continue
|
|
59
|
+
seen.add(obj_id)
|
|
60
|
+
|
|
61
|
+
_wrap_get_help(cmd)
|
|
62
|
+
|
|
63
|
+
if isinstance(cmd, click.Group):
|
|
64
|
+
stack.extend(cmd.commands.values())
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from functools import lru_cache
|
|
5
|
+
from importlib import metadata
|
|
6
|
+
from pathlib import Path
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@lru_cache(maxsize=1)
|
|
10
|
+
def get_cwms_cli_version() -> str:
|
|
11
|
+
"""Return installed cwms-cli version, with pyproject fallback for source runs."""
|
|
12
|
+
try:
|
|
13
|
+
return metadata.version("cwms-cli")
|
|
14
|
+
except metadata.PackageNotFoundError:
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
pyproject = Path(__file__).resolve().parents[2] / "pyproject.toml"
|
|
18
|
+
if not pyproject.exists():
|
|
19
|
+
return "unknown"
|
|
20
|
+
|
|
21
|
+
text = pyproject.read_text(encoding="utf-8")
|
|
22
|
+
|
|
23
|
+
# Prefer the [tool.poetry] version declaration.
|
|
24
|
+
in_poetry_section = False
|
|
25
|
+
for line in text.splitlines():
|
|
26
|
+
stripped = line.strip()
|
|
27
|
+
if stripped.startswith("[") and stripped.endswith("]"):
|
|
28
|
+
in_poetry_section = stripped == "[tool.poetry]"
|
|
29
|
+
continue
|
|
30
|
+
if in_poetry_section:
|
|
31
|
+
m = re.match(r'^version\s*=\s*"([^"]+)"\s*$', stripped)
|
|
32
|
+
if m:
|
|
33
|
+
return m.group(1)
|
|
34
|
+
|
|
35
|
+
return "unknown"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/tests/data/expected_brok_output.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{cwms_cli-0.3.0 → cwms_cli-0.3.2}/cwmscli/commands/csv2cwms/tests/skip_test_integration_pipeline.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|