def testConfig(self): conf = record.Record() self.assertEqual([], dir(conf)) logging.info('Step 1') self.assertFalse('x' in conf) self.assertEqual(UNDEFINED, conf.x) self.assertEqual(UNDEFINED, conf.get('x')) logging.info('Step 2') conf.x = 1 self.assertTrue('x' in conf) self.assertEqual(1, conf.x) self.assertEqual(1, conf['x']) self.assertEqual(['x'], dir(conf)) logging.info('Step 3') conf.x = 2 self.assertTrue('x' in conf) self.assertEqual(2, conf.x) self.assertEqual(2, conf['x']) self.assertEqual(['x'], dir(conf)) logging.info('Step 4') del conf['x'] self.assertFalse('x' in conf) self.assertEqual(UNDEFINED, conf.x) self.assertEqual(UNDEFINED, conf.get('x')) self.assertEqual([], dir(conf)) conf.x = 1 del conf.x self.assertFalse('x' in conf)
def declare(self, name, kind, deps=tuple(), target=None, **kwargs): """Declares a new target. Args: name: Target task name (unique task ID). kind: Target kind, eg. "java_library" or "python_test". deps: Dependencies on other targets. target: Target this task contributes to. Different tasks make contribute to the same target. **kwargs: Target-specific parameters. Returns: Target specification record. """ if target is None: target = name kwargs["name"] = name kwargs["kind"] = kind kwargs["deps"] = deps kwargs["target"] = target spec = record.Record(kwargs) if name in self._definitions: raise Error( "Duplicate definition for {name}:\n{existing}\n{duplicate}". format(name=name, existing=self._definitions[name], duplicate=spec)) self._definitions[name] = spec return spec
def test_write_load(self): conf = record.Record() conf.x = 1 with tempfile.NamedTemporaryFile() as f: conf.write_to_file(f.name) logging.info('Writing record: %r', conf) new = record.load_from_file(f.name) logging.info('Loaded record: %r', new) self.assertEqual(1, new.x)
def run(self): """Wires tasks outputs and inputs. Sub-classes should NOT override this method, but should instead implement IOTask.run_with_io(output, **inputs). Returns: The task run completion state. """ # Load task inputs: self._input = record.Record() input_map = dict() for input_name, dep_id in self._input_map.items(): dep = self.workflow.tasks[dep_id] self._input[input_name] = dep.output input_map[input_name] = dep.output # Run task, if necessary: task_run_id = self.get_task_run_id() logging.info('Processing task run ID: %r', task_run_id) output = self._read_task_run_trace(task_run_id) if ((output is not None) and self.should_task_run(task_run_id=task_run_id, output=output, **input_map)): # Force re-running the task: output = None if output is None: output = record.Record() task_state = self.run_with_io(output=output, **input_map) # Store task output: if task_state == TaskState.SUCCESS: self._write_task_run_trace(task_run_id, output) else: logging.info('Trace found for task run ID: %r', task_run_id) task_state = TaskState.SUCCESS self._output = output return task_state
def test_iter(self): """The names of parameters set on the record should be in iter(record).""" conf = record.Record() conf.x = 1 conf.y = 2 self.assertSetEqual({"x", "y"}, set(iter(conf)))
def __init__( self, path, maven_repository=None, ): """Initializes a new workspace object. Args: path: Root path of the workspace. maven_repository: Optional explicit Maven repository where to search for artifacts. """ self._path = os.path.abspath(path) assert os.path.exists(self.path), \ "Workspace root directory does not exist: {!r}".format(self.path) assert os.path.isdir(self.config_dir), \ "Workspace configuration directory missing: {!r}".format(self.config_dir) self._build_defs = build_defs.BuildDefs() # Process workspace configuration file: conf_file = os.path.join(self.config_dir, "conf.py") if os.path.exists(conf_file): logging.info("Loading configuration %r", conf_file) with open(conf_file, mode="rt", encoding="UTF-8") as f: conf_py = f.read() self._build_defs.eval(conf_py) # Process master BUILD file: build_file = os.path.join(self.path, "BUILD") if os.path.exists(build_file): logging.info("Loading build file %r", build_file) with open(build_file, mode="rt", encoding="UTF-8") as f: build_py = f.read() self._build_defs.eval(build_py) else: logging.info("BUILD file missing: %r", build_file) self._config = record.Record(self._build_defs.exec_locals) self.config.definitions = self._build_defs.definitions logging.debug("Using configuration: %r", self._config) # ------------------------------------------------------------------------------------------ base.make_dir(self.output_dir) base.make_dir(self.temp_dir) base.make_dir(self.maven_local_repo) base.make_dir(os.path.join(self.temp_dir, "workflow")) logging.debug("Generating artifacts in: %s", self.maven_local_repo) # ------------------------------------------------------------------------------------------ self._git = git_wrapper.Git(self.path) if maven_repository is None: remotes = self.config.get("maven_repositories", tuple()) maven_repository = maven_repo.MavenRepository( local=self.maven_local_repo, remotes=remotes, ) logging.debug("Using Maven repositories:\n%s", base.add_margin("\n".join(remotes), "\t- ")) self._maven_repo = maven_repository # Build toolkit: self._tools = build_tools.BuildTools(workspace=self) self.tools.validate() # Workflow generated after the build graph: self._workflow = None