diff --git a/cloud-build.py b/cloud-build.py index c4f7c53..8eb4692 100755 --- a/cloud-build.py +++ b/cloud-build.py @@ -87,11 +87,15 @@ def main(): args = parse_args() stages = set(args.stages) - set(args.skip_stages) + config_override = {} + if args.force_rebuild: + config_override['rebuild_after'] = {'days': 0} + cb = cloud_build.CB( config=args.config, tasks=args.tasks, built_images_dir=args.built_images_dir, - force_rebuild=args.force_rebuild, + config_override=config_override, ) if 'build' in stages: diff --git a/cloud_build/cloud_build.py b/cloud_build/cloud_build.py index 99e3cad..0c62dab 100755 --- a/cloud_build/cloud_build.py +++ b/cloud_build/cloud_build.py @@ -58,13 +58,11 @@ class CB: data_dir: Optional[PathLike] = None, tasks: Optional[dict[str, List[str]]] = None, built_images_dir: Optional[PathLike] = None, - force_rebuild: bool = False, + config_override: Optional[Dict] = None, ) -> None: self.initialized = False self._save_cwd = os.getcwd() - self.parse_config(config) - if force_rebuild: - self.rebuild_after = datetime.timedelta(0) + self.parse_config(config, config_override) if tasks is None: self.tasks = {} else: @@ -203,7 +201,14 @@ class CB: self.debug(f'Popd from {new_dir}') os.chdir(previous_dir) - def parse_config(self, config: str) -> None: + def parse_config( + self, + config: str, + override: Optional[Dict] = None + ) -> None: + if override is None: + override = {} + try: with open(config) as f: cfg = yaml.safe_load(f) @@ -230,7 +235,10 @@ class CB: if self.external_files: self.external_files = self.expand_path(Path(self.external_files)) - rebuild_after = cfg.get('rebuild_after', {'days': 1}) + rebuild_after = override.get( + 'rebuild_after', + cfg.get('rebuild_after', {'days': 1}), + ) try: self.rebuild_after = datetime.timedelta(**rebuild_after) except TypeError as e: diff --git a/tests/test_rebuild.py b/tests/test_rebuild.py index 7bc96eb..343048e 100644 --- a/tests/test_rebuild.py +++ b/tests/test_rebuild.py @@ -45,7 +45,7 @@ class TestRebuild(TestCase): cb = CB( config='tests/test_rebuild.yaml', data_dir=self.data_dir, - force_rebuild=True, + config_override={'rebuild_after': {'days': 0}}, ) msg = 'Do not try to rebuild when force_rebuild' with self.assertRaises(BuildError, msg=msg):