Repository: meltano/meltano

Issue:
bug: meltano-cloud --version
### Meltano Version

2023-04-05 pipx install 'git+https://github.com/meltano/meltano.git@cloud#subdirectory=src/cloud-cli'

### Python Version

3.8

### Bug scope

CLI (options, error messages, logging, etc.)

### Operating System

Ubuntu LTS 20.04.5

### Description

While putting in https://github.com/meltano/meltano/issues/7494 I tried to answer which meltano version I was running with. So I ran `meltano-cloud --version`  Stack trace is below

### Code

```python
visch@DESKTOP-9BDPA9T:~/git/prodder$ meltano-cloud --version
2023-04-05 09:09:40 [error    ] An unexpected error occurred.
Traceback (most recent call last):
  File "/home/visch/.local/pipx/venvs/meltano-cloud-cli/lib/python3.8/site-packages/meltano/cloud/cli/__init__.py", line 31, in main
    cloud()
  File "/home/visch/.local/pipx/venvs/meltano-cloud-cli/lib/python3.8/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
  File "/home/visch/.local/pipx/venvs/meltano-cloud-cli/lib/python3.8/site-packages/click/core.py", line 1054, in main
    with self.make_context(prog_name, args, **extra) as ctx:
  File "/home/visch/.local/pipx/venvs/meltano-cloud-cli/lib/python3.8/site-packages/click/core.py", line 920, in make_context
    self.parse_args(ctx, args)
  File "/home/visch/.local/pipx/venvs/meltano-cloud-cli/lib/python3.8/site-packages/click/core.py", line 1613, in parse_args
    rest = super().parse_args(ctx, args)
  File "/home/visch/.local/pipx/venvs/meltano-cloud-cli/lib/python3.8/site-packages/click/core.py", line 1378, in parse_args
    value, args = param.handle_parse_result(ctx, opts, args)
  File "/home/visch/.local/pipx/venvs/meltano-cloud-cli/lib/python3.8/site-packages/click/core.py", line 2360, in handle_parse_result
    value = self.process_value(ctx, value)
  File "/home/visch/.local/pipx/venvs/meltano-cloud-cli/lib/python3.8/site-packages/click/core.py", line 2322, in process_value
    value = self.callback(ctx, self, value)
  File "/home/visch/.local/pipx/venvs/meltano-cloud-cli/lib/python3.8/site-packages/click/decorators.py", line 441, in callback
    raise RuntimeError(
RuntimeError: 'meltano' is not installed. Try passing 'package_name' instead.
```


Discussion:

Resolving patch:
diff --git a/src/cloud-cli/meltano/cloud/__init__.py b/src/cloud-cli/meltano/cloud/__init__.py
--- a/src/cloud-cli/meltano/cloud/__init__.py
+++ b/src/cloud-cli/meltano/cloud/__init__.py
@@ -1,3 +1,15 @@
 """Meltano Cloud."""
 
 from __future__ import annotations
+
+import sys
+
+if sys.version_info >= (3, 8):
+    from importlib import metadata as importlib_metadata
+else:
+    import importlib_metadata
+
+try:
+    __version__ = importlib_metadata.version("meltano-cloud-cli")
+except importlib_metadata.PackageNotFoundError:
+    __version__ = importlib_metadata.version("meltano")
diff --git a/src/cloud-cli/meltano/cloud/api/client.py b/src/cloud-cli/meltano/cloud/api/client.py
--- a/src/cloud-cli/meltano/cloud/api/client.py
+++ b/src/cloud-cli/meltano/cloud/api/client.py
@@ -12,14 +12,10 @@
 from aiohttp import ClientResponse, ClientResponseError, ClientSession
 from structlog import get_logger
 
+from meltano.cloud import __version__ as version
 from meltano.cloud.api.auth import MeltanoCloudAuth
 from meltano.cloud.api.config import MeltanoCloudConfig
 
-if sys.version_info >= (3, 8):
-    from importlib.metadata import version
-else:
-    from importlib_metadata import version
-
 if t.TYPE_CHECKING:
     import types
 
@@ -63,10 +59,7 @@ def __init__(self, config: MeltanoCloudConfig | None = None) -> None:
         self.config = config or MeltanoCloudConfig()
         self.auth = MeltanoCloudAuth(self.config)
         self.api_url = self.config.base_url
-        try:
-            self.version = version("meltano-cloud-cli")
-        except Exception:
-            self.version = version("meltano")
+        self.version = version
 
     async def __aenter__(self) -> Self:
         """Enter the client context.
diff --git a/src/cloud-cli/meltano/cloud/cli/base.py b/src/cloud-cli/meltano/cloud/cli/base.py
--- a/src/cloud-cli/meltano/cloud/cli/base.py
+++ b/src/cloud-cli/meltano/cloud/cli/base.py
@@ -11,6 +11,7 @@
 
 import click
 
+from meltano.cloud import __version__ as version
 from meltano.cloud.api.auth import MeltanoCloudAuth
 from meltano.cloud.api.config import MeltanoCloudConfig
 from meltano.cloud.api.types import CloudProject
@@ -73,7 +74,7 @@ def _set_shared_option(ctx: click.Context, opt: click.Option, value: t.Any) -> N
 
 
 @click.group(invoke_without_command=True, no_args_is_help=True)
-@click.version_option()
+@click.version_option(version=version)
 @click.option(
     "--config-path",
     required=False,


Test patch: