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

CLI flag for getting current branch name for sanity check with venv & pip magic behind the scenes #1928

Merged
merged 5 commits into from
May 5, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions armory/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from armory.eval import Evaluator
import armory.logs
from armory.logs import log
from armory.cli.tools import log_current_branch
from armory.utils.configuration import load_config, load_config_stdin
from armory.utils.version import to_docker_tag
import docker
Expand Down Expand Up @@ -718,6 +719,23 @@ def exec(command_args, prog, description):
sys.exit(exit_code)


def utils(command_args, prog, description):
parser = argparse.ArgumentParser(prog=prog, description=description)
_debug(parser)

parser.add_argument(
"--branch",
action="store_true",
help="Print the current branch name",
)

args = parser.parse_args(command_args)
armory.logs.update_filters(args.log_level, args.debug)

if args.branch:
log_current_branch()


# command, (function, description)
PROGRAM = "armory"
COMMANDS = {
Expand All @@ -729,6 +747,7 @@ def exec(command_args, prog, description):
"configure": (configure, "set up armory and dataset paths"),
"launch": (launch, "launch a given docker container in armory"),
"exec": (exec, "run a single exec command in the container"),
"utils": (utils, "run a utility script"),
}


Expand Down
26 changes: 26 additions & 0 deletions armory/cli/tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import os

from armory.logs import log


def log_current_branch():
"""Log the current git branch of armory. Works independent of the current working directory."""
try:
from armory.__about__ import __version__

log.info(f"Armory version: {__version__}")
except ModuleNotFoundError:
log.info("Unable to extract armory version from __about__.py")
try:
import git

repo = git.Repo(
os.path.dirname(os.path.realpath(__file__)), search_parent_directories=True
)
log.info(f"Git branch: {repo.active_branch}")
except ImportError:
log.info("Unable to import gitpython, cannot determine git branch")
except git.exc.InvalidGitRepositoryError:
log.info("Unable to find .git directory, cannot determine git branch")
except git.exc.GitCommandError:
log.info("Unable to determine git branch")