Skip to content

Commit a2b6116

Browse files
Chronicle Teamcopybara-github
authored andcommitted
No public description
PiperOrigin-RevId: 900700237
1 parent 19793eb commit a2b6116

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

tools/content_manager/content_manager/__main__.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,19 @@
2121
import logging
2222
import os
2323
import pathlib
24+
import sys
2425
from typing import Literal
2526

2627
import click
27-
from content_manager.common import datetime_converter
28+
29+
# Add the directory containing this file to sys.path to fix imports when
30+
# running via Blaze
31+
current_dir = os.path.dirname(os.path.abspath(__file__))
32+
parent_dir = os.path.dirname(current_dir)
33+
if parent_dir not in sys.path:
34+
sys.path.insert(0, parent_dir)
35+
36+
from content_manager.common import datetime_converter # pylint: disable=g-import-not-at-top
2837
from content_manager.common.custom_exceptions import RuleVerificationError
2938
from content_manager.data_tables import DataTables
3039
from content_manager.reference_lists import ReferenceLists
@@ -41,7 +50,11 @@
4150

4251
LOGGER = logging.getLogger()
4352

44-
ROOT_DIR = pathlib.Path(__file__).parent.parent
53+
ROOT_DIR = pathlib.Path(
54+
os.environ.get(
55+
"CONTENT_MANAGER_ROOT", str(pathlib.Path(__file__).parent.parent)
56+
)
57+
)
4558
RULES_DIR = ROOT_DIR / "rules"
4659
RULE_CONFIG_FILE = ROOT_DIR / "rule_config.yaml"
4760
REF_LISTS_DIR = ROOT_DIR / "reference_lists"

tools/content_manager/content_manager/rules.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
import hashlib
2121
import json
2222
import logging
23+
import os
2324
import pathlib
2425
import re
2526
from typing import Any, List, Mapping, Sequence, Tuple
2627

2728
from content_manager.common.custom_exceptions import DuplicateRuleIdError
28-
from content_manager.common.custom_exceptions import DuplicateRuleNameError
2929
from content_manager.common.custom_exceptions import RuleConfigError
3030
from content_manager.common.custom_exceptions import RuleError
3131
from google.auth.transport import requests
@@ -43,7 +43,9 @@
4343

4444
LOGGER = logging.getLogger()
4545

46-
ROOT_DIR = pathlib.Path(__file__).parent.parent
46+
ROOT_DIR = pathlib.Path(
47+
os.environ.get("CONTENT_MANAGER_ROOT", pathlib.Path(__file__).parent.parent)
48+
)
4749
RULES_DIR = ROOT_DIR / "rules"
4850
RULE_CONFIG_FILE = ROOT_DIR / "rule_config.yaml"
4951

@@ -451,8 +453,9 @@ def check_for_duplicate_rule_names(cls, rules: List[Rule]):
451453
if duplicate_rule_names:
452454
for rule_name, count in duplicate_rule_names:
453455
LOGGER.info("%s rules found with the same name %s", count, rule_name)
454-
raise DuplicateRuleNameError(
455-
f"Duplicate rule names found {duplicate_rule_names}."
456+
LOGGER.warning(
457+
"Duplicate rule names found %s. Overwriting will occur.",
458+
duplicate_rule_names,
456459
)
457460

458461
@classmethod

0 commit comments

Comments
 (0)