Integrate version hardcoding into CLI

The get_distribution load was very heavy, so follow the other parts and
just hardcode the version in. Also update bump-version to work with this
and with the new pyproject.toml configuration, and add a custom
user-agent to the API requests leveraging this version.
This commit is contained in:
2025-03-17 18:05:44 -04:00
parent 5831c3a425
commit e5c8318b8e
3 changed files with 9 additions and 5 deletions

View File

@ -51,6 +51,8 @@ import click
###############################################################################
VERSION = "0.9.107"
CONTEXT_SETTINGS = dict(
help_option_names=["-h", "--help"], max_content_width=MAX_CONTENT_WIDTH
)
@ -97,10 +99,7 @@ def version(ctx, param, value):
if not value or ctx.resilient_parsing:
return
from pkg_resources import get_distribution
version = get_distribution("pvc").version
echo(CLI_CONFIG, f"Parallel Virtual Cluster CLI client version {version}")
echo(CLI_CONFIG, f"Parallel Virtual Cluster CLI client version {VERSION}")
ctx.exit()

View File

@ -27,6 +27,7 @@ from requests import get, post, put, patch, delete, Response
from requests.exceptions import ConnectionError
from time import time
from urllib3 import disable_warnings
from pvc.cli.cli import VERSION
def format_bytes(size_bytes):
@ -166,6 +167,9 @@ def call_api(
config["api_scheme"], config["api_host"], config["api_prefix"], request_uri
)
# Add custom User-Agent header
headers["User-Agent"] = f"pvc-client-cli/{VERSION}"
# Craft the authentication header if required
if config["api_key"]:
headers["X-Api-Key"] = config["api_key"]