Commit 120a8342 authored by Ross Beyer's avatar Ross Beyer Committed by Jesse Mapel
Browse files

feat(isisVarInit.py): Removed the default "cat" in the written activation

scripts (but still available as an option), and provided a quiet option
for this program itself.
parent 8a6c8fd0
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -35,6 +35,9 @@ release.

## [Unreleased]

### Changed
- isisVarInit.py no longer writes a "cat" statement by default to the activate scripts which cause the ISIS version information to be written on conda activate.  This can be included in those scripts via a command line option to isisVarInit.py.  Also, a quiet option is provided to isisVarInit.py to suppress its own writing to standard out, if needed.

### Fixed
- Fixed logging in FindFeatures where we were trying to get a non-existent Pvl group from the Pvl log. [#4375](https://github.com/USGS-Astrogeology/ISIS3/issues/4375)
- Fixed an arccos evaluating a double close to either 1, -1 when calculating the ground azimuth in camera.cpp. [#4393](https://github.com/USGS-Astrogeology/ISIS3/issues/4393)
+31 −13
Original line number Diff line number Diff line
@@ -5,10 +5,11 @@ variables that are sourced during conda environment activation and
removed at deactivation.

If the directories don't exist, they are created.  If their path is
not specified, they are placed in $ISISROOT.
not specified, they are placed in $CONDA_PREFIX (which is $ISISROOT).
"""

import argparse
import logging
import os
from pathlib import Path

@@ -51,7 +52,7 @@ def mkdir(p: Path) -> str:
        return f"Created {p}"


def activate_text(shell: dict, env_vars: dict) -> str:
def activate_text(shell: dict, env_vars: dict, cat=False) -> str:
    """Returns the formatted text to write to the activation script
    based on the passed dictionaries."""

@@ -62,6 +63,7 @@ def activate_text(shell: dict, env_vars: dict) -> str:
    if shell["activate_extra"] != "":
        lines.append(shell["activate_extra"])

    if cat:
        lines.append("cat $ISISROOT/version")

    return "\n".join(lines)
@@ -106,21 +108,37 @@ parser.add_argument(
    action=ResolveAction,
    help="ISIS Ale Data Directory, default: %(default)s",
)
parser.add_argument(
    "-c", "--cat",
    action="store_true",
    help="If given, the activation script will include a 'cat' action that "
         "will print the ISIS version information to STDOUT every time the "
         "ISIS environment is activated."
)
parser.add_argument(
    "-q", "--quiet",
    action="store_true",
    help="If given, will suppress all regular text output."
)
args = parser.parse_args()

print("-- ISIS Data Directories --")
log_lvl = {False: "INFO", True: "ERROR"}

logging.basicConfig(format="%(message)s", level=log_lvl[args.quiet])

logging.info("-- ISIS Data Directories --")
# Create the data directories:
print(mkdir(args.data_dir))
print(mkdir(args.test_dir))
print(mkdir(args.ale_dir))
logging.info(mkdir(args.data_dir))
logging.info(mkdir(args.test_dir))
logging.info(mkdir(args.ale_dir))

print("-- Conda activation and deactivation scripts --")
logging.info("-- Conda activation and deactivation scripts --")
# Create the conda activation and deactivation directories:
activate_dir = Path(os.environ["CONDA_PREFIX"]) / "etc/conda/activate.d"
deactivate_dir = Path(os.environ["CONDA_PREFIX"]) / "etc/conda/deactivate.d"

print(mkdir(activate_dir))
print(mkdir(deactivate_dir))
logging.info(mkdir(activate_dir))
logging.info(mkdir(deactivate_dir))

# Set the environment variables to manage
env_vars = dict(
@@ -161,9 +179,9 @@ fish = dict(
# each:
for shell in (sh, csh, fish):
    a_path = activate_dir / ("isis-activate" + shell["extension"])
    a_path.write_text(activate_text(shell, env_vars))
    print(f"Wrote {a_path}")
    a_path.write_text(activate_text(shell, env_vars, cat=args.cat))
    logging.info(f"Wrote {a_path}")

    d_path = deactivate_dir / ("isis-deactivate" + shell["extension"])
    d_path.write_text(deactivate_text(shell, env_vars))
    print(f"Wrote {d_path}")
    logging.info(f"Wrote {d_path}")