From 20e61533a8a140c7f8c9a3bab297a34a326f1246 Mon Sep 17 00:00:00 2001 From: Kent Pitman Date: Fri, 29 Sep 2023 12:57:10 -0400 Subject: [PATCH] Small tweak to allow lookup_checker to use a specified policy dir when called from code. --- dcicutils/license_utils.py | 7 ++++--- dcicutils/scripts/run_license_checker.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/dcicutils/license_utils.py b/dcicutils/license_utils.py index 8d6553b0a..ce01a5c80 100644 --- a/dcicutils/license_utils.py +++ b/dcicutils/license_utils.py @@ -745,11 +745,12 @@ def find_checker(cls, checker_name: str) -> Optional[Type[LicenseChecker]]: return cls.REGISTRY.get(checker_name, None) @classmethod - def lookup_checker(cls, checker_name: str, autoload: bool = False) -> Type[LicenseChecker]: + def lookup_checker(cls, checker_name: str, autoload: bool = False, + policy_dir: Optional[str] = None) -> Type[LicenseChecker]: result: Optional[Type[LicenseChecker]] = cls.find_checker(checker_name) if result is None: - if autoload: - policy_dir = LicenseOptions.POLICY_DIR or POLICY_DIR + if autoload or policy_dir: + policy_dir = policy_dir or LicenseOptions.POLICY_DIR or POLICY_DIR PRINT(f"Looking for custom policy {checker_name} in {policy_dir} ...") result = find_or_create_license_class(policy_name=checker_name, policy_dir=policy_dir) diff --git a/dcicutils/scripts/run_license_checker.py b/dcicutils/scripts/run_license_checker.py index c07c06529..7cafdae37 100644 --- a/dcicutils/scripts/run_license_checker.py +++ b/dcicutils/scripts/run_license_checker.py @@ -31,9 +31,9 @@ def main(): parser.add_argument("--debug", '-q', default=False, action="store_true", help="Requests additional debugging output.") parser.add_argument("--conda-prefix", "--conda_prefix", "--cp", default=LicenseOptions.CONDA_PREFIX, - help=(f"Overrides the CONDA_PREFIX (default {LicenseOptions.CONDA_PREFIX!r}).")) + help=f"Overrides the CONDA_PREFIX (default {LicenseOptions.CONDA_PREFIX!r}).") parser.add_argument("--policy-dir", "--policy_dir", "--pd", default=LicenseOptions.POLICY_DIR, - help=(f"Specifies a custom policy directory (default {LicenseOptions.POLICY_DIR!r}).")) + help=f"Specifies a custom policy directory (default {LicenseOptions.POLICY_DIR!r}).") args = parser.parse_args()