diff --git a/tools/content_manager/content_manager/__main__.py b/tools/content_manager/content_manager/__main__.py index 5c8c7c3..e911a24 100644 --- a/tools/content_manager/content_manager/__main__.py +++ b/tools/content_manager/content_manager/__main__.py @@ -21,10 +21,19 @@ import logging import os import pathlib +import sys from typing import Literal import click -from content_manager.common import datetime_converter + +# Add the directory containing this file to sys.path to fix imports when +# running via Blaze +current_dir = os.path.dirname(os.path.abspath(__file__)) +parent_dir = os.path.dirname(current_dir) +if parent_dir not in sys.path: + sys.path.insert(0, parent_dir) + +from content_manager.common import datetime_converter # pylint: disable=g-import-not-at-top from content_manager.common.custom_exceptions import RuleVerificationError from content_manager.data_tables import DataTables from content_manager.reference_lists import ReferenceLists @@ -41,7 +50,11 @@ LOGGER = logging.getLogger() -ROOT_DIR = pathlib.Path(__file__).parent.parent +ROOT_DIR = pathlib.Path( + os.environ.get( + "CONTENT_MANAGER_ROOT", str(pathlib.Path(__file__).parent.parent) + ) +) RULES_DIR = ROOT_DIR / "rules" RULE_CONFIG_FILE = ROOT_DIR / "rule_config.yaml" REF_LISTS_DIR = ROOT_DIR / "reference_lists" diff --git a/tools/content_manager/content_manager/rules.py b/tools/content_manager/content_manager/rules.py index a5afb60..51ec6f9 100644 --- a/tools/content_manager/content_manager/rules.py +++ b/tools/content_manager/content_manager/rules.py @@ -20,12 +20,12 @@ import hashlib import json import logging +import os import pathlib import re from typing import Any, List, Mapping, Sequence, Tuple from content_manager.common.custom_exceptions import DuplicateRuleIdError -from content_manager.common.custom_exceptions import DuplicateRuleNameError from content_manager.common.custom_exceptions import RuleConfigError from content_manager.common.custom_exceptions import RuleError from google.auth.transport import requests @@ -43,7 +43,9 @@ LOGGER = logging.getLogger() -ROOT_DIR = pathlib.Path(__file__).parent.parent +ROOT_DIR = pathlib.Path( + os.environ.get("CONTENT_MANAGER_ROOT", pathlib.Path(__file__).parent.parent) +) RULES_DIR = ROOT_DIR / "rules" RULE_CONFIG_FILE = ROOT_DIR / "rule_config.yaml" @@ -451,8 +453,9 @@ def check_for_duplicate_rule_names(cls, rules: List[Rule]): if duplicate_rule_names: for rule_name, count in duplicate_rule_names: LOGGER.info("%s rules found with the same name %s", count, rule_name) - raise DuplicateRuleNameError( - f"Duplicate rule names found {duplicate_rule_names}." + LOGGER.warning( + "Duplicate rule names found %s. Overwriting will occur.", + duplicate_rule_names, ) @classmethod