Skip to content

Commit f724cfb

Browse files
Fix the --version flag (#106)
1 parent 5b147b1 commit f724cfb

File tree

5 files changed

+39
-16
lines changed

5 files changed

+39
-16
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ python3 -m pip install python-cmethods
149149
```
150150

151151
The package is also available via conda-forge. See
152-
[conda-forge/python_cmethods-feedstock](https://github.com/conda-forge/python_cmethods-feedstock/tree/main) for more
153-
information.
152+
[conda-forge/python_cmethods](https://anaconda.org/conda-forge/python_cmethods)
153+
for more information.
154154

155155
<a name="examples"></a>
156156

cmethods/__init__.py

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,36 @@
2929

3030
import logging
3131
import sys
32+
from typing import TYPE_CHECKING, Any
33+
34+
if TYPE_CHECKING:
35+
from cloup import Context
3236

3337
import cloup
3438
import xarray as xr
35-
from cloup import (
36-
HelpFormatter,
37-
HelpTheme,
38-
Path,
39-
Style,
40-
command,
41-
option,
42-
option_group,
43-
version_option,
44-
)
39+
from click import echo
40+
from cloup import HelpFormatter, HelpTheme, Path, Style, command, option, option_group
4541
from cloup.constraints import Equal, If, require_all
4642

4743
from cmethods.core import adjust
4844

4945
__all__ = ["adjust"]
5046

5147

48+
def print_version(
49+
ctx: Context,
50+
param: Any, # noqa: ARG001
51+
value: Any,
52+
) -> None:
53+
"""Prints the version of the package"""
54+
if not value or ctx.resilient_parsing:
55+
return
56+
from importlib.metadata import version
57+
58+
echo(version("python-cmethods"))
59+
ctx.exit()
60+
61+
5262
@command(
5363
context_settings={
5464
"auto_envvar_prefix": "CMETHODS",
@@ -63,7 +73,13 @@
6373
),
6474
),
6575
)
66-
@version_option(message="%version%")
76+
@option(
77+
"--version",
78+
is_flag=True,
79+
callback=print_version,
80+
expose_value=False,
81+
is_eager=True,
82+
)
6783
@option(
6884
"--obs",
6985
"--observations",

doc/getting_started.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ The `python-cmethods`_ module can be installed using the package manager pip:
1919
python3 -m pip install python-cmethods
2020
2121
The package is also available via conda-forge. See
22-
`python_cmethods-feedstock`_ for more information.
22+
`python_cmethods-conda`_ for more information.
2323

2424
Command-Line Interface Usage
2525
----------------------------

doc/links.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
88
.. _python-cmethods: https://github.com/btschwertfeger/python-cmethods
99

10-
.. _python_cmethods-feedstock: https://github.com/conda-forge/python_cmethods-feedstock/tree/main
10+
.. _python_cmethods-conda: https://anaconda.org/conda-forge/python_cmethods
1111

1212
.. _python-cmethods/issues: https://github.com/btschwertfeger/python-cmethods/issues
1313

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ description = "A collection of bias correction techniques written in Python - fo
1515
readme = "README.md"
1616
license = { file = "LICENSE" }
1717
requires-python = ">=3.8"
18-
dependencies = ["xarray>=2022.11.0", "netCDF4>=1.6.1", "numpy", "cloup"]
18+
dependencies = [
19+
"xarray>=2022.11.0",
20+
"netCDF4>=1.6.1",
21+
"numpy",
22+
"click",
23+
"cloup",
24+
]
1925
keywords = [
2026
"climate-science",
2127
"bias",
@@ -68,6 +74,7 @@ testpaths = ["tests"]
6874
[tool.pytest.ini_options]
6975
cache_dir = ".cache/pytest"
7076
markers = ["wip: Used to run a specific test by hand."]
77+
addopts = "--maxfail=1"
7178

7279
[tool.coverage.run]
7380
source = ["cmethods"]

0 commit comments

Comments
 (0)