Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: log dsp-tools version #612

Merged
merged 6 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 18 additions & 2 deletions src/dsp_tools/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""
import argparse
import datetime
import subprocess
import sys
from importlib.metadata import version

Expand Down Expand Up @@ -289,6 +290,21 @@ def _parse_arguments(
return args


def _get_version() -> str:
result = subprocess.run("pip freeze | grep dsp-tools", check=False, shell=True, capture_output=True)
_detail_version = result.stdout.decode("utf-8")
# _detail_version has one of the following formats:
# - 'dsp-tools==5.0.3\n'
# - 'dsp-tools @ git+https://github.com/dasch-swiss/dsp-tools.git@1f95f8d1b79bd5170a652c0d04e7ada417d76734\n'
# - '-e git+ssh://git@github.com/dasch-swiss/dsp-tools.git@af9a35692b542676f2aa0a802ca7fc3b35f5713d#egg=dsp_tools\n'
# - ''
if version_number := regex.search(r"\d+\.\d+\.\d+", _detail_version):
return version_number.group(0)
if regex.search(r"github.com", _detail_version):
return _detail_version.replace("\n", "")
return version("dsp-tools")
BalduinLandolt marked this conversation as resolved.
Show resolved Hide resolved


def _log_cli_arguments(parsed_args: argparse.Namespace) -> None:
"""
Log the CLI arguments passed by the user from the command line.
Expand All @@ -297,8 +313,8 @@ def _log_cli_arguments(parsed_args: argparse.Namespace) -> None:
parsed_args: parsed arguments
"""
metadata_lines = []
_version = version("dsp-tools")
metadata_lines.append(f"DSP-TOOLS {_version}: Called the action '{parsed_args.action}' from the command line")
metadata_lines.append(f"DSP-TOOLS: Called the action '{parsed_args.action}' from the command line")
metadata_lines.append(f"DSP-TOOLS version: {_get_version()}")
metadata_lines.append(f"Location of this installation: {__file__}")
metadata_lines.append("CLI arguments:")
metadata_lines = [f"*** {line}" for line in metadata_lines]
Expand Down
7 changes: 3 additions & 4 deletions src/dsp_tools/fast_xmlupload/upload_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,9 @@ def _get_upload_candidates(
glob.glob(f"{dir_with_processed_files}/**/**/{internal_filename_of_processed_file.stem}*.*")
)
upload_candidates_paths = [Path(c) for c in upload_candidates]
upload_candidates_as_str = "\n - " + "\n - ".join([str(c) for c in upload_candidates])
logger.info(
f"Found the following upload candidates for {internal_filename_of_processed_file}: {upload_candidates_as_str}"
)
logger.info(f"Found the following upload candidates for {internal_filename_of_processed_file}:")
for cand in upload_candidates:
logger.info(f" - {cand}")
return upload_candidates_paths


Expand Down