def file_contents(self, project): initialize_file = bundle.find("initialize.yml") file_contents = { Path(relative_path): content for relative_path, content in yaml.safe_load( initialize_file.open()).items() } if self._discovery: file_contents["discovery.yml"] = bundle.find( "discovery.yml").read_text() return file_contents
def settings(self): if self._settings is None: with bundle.find("settings.yml").open() as settings_yaml: settings = yaml.safe_load(settings_yaml) self._settings = list( map(SettingDefinition.parse, settings["settings"])) return self._settings
def upgrade_files(self): """ Update the files managed by Meltano inside the current project. """ files_map = { bundle.find("dags/meltano.py"): self.project.root_dir( "orchestrate/dags/meltano.py" ), bundle.find("transform/profile/profiles.yml"): self.project.root_dir( "transform/profile/profiles.yml" ), } for src, dst in files_map.items(): try: shutil.copy(src, dst) logging.info(f"{dst} has been updated.") except Exception as err: logging.error(f"Meltano could not update {dst}: {err}")
def cached_discovery(self): try: with self.cached_discovery_file.open() as discovery_cache: return yaml.load(discovery_cache) except (yaml.YAMLError, FileNotFoundError): logging.debug( f"Discovery cache corrupted or missing, falling back on the bundled discovery." ) shutil.copy(bundle.find("discovery.yml"), self.cached_discovery_file) # load it back with self.cached_discovery_file.open() as discovery_cache: return yaml.load(discovery_cache)
def _(node: str, target_path: Path): """ Create the file using either the raw content or a bundled file. """ logging.debug(f"{target_path}") if node.startswith("bundle://"): # copy from the bundle _, path = node.split("bundle://") path = bundle.find(path) logging.debug(f"{path} → {target_path}") if path.is_dir(): shutil.copytree(path, target_path) else: shutil.copy(path, target_path) else: # write the content with target_path.open("w") as target: target.write(node) return [target_path]
def load_bundled_discovery(self): with bundle.find("discovery.yml").open() as bundled_discovery: discovery = self.load_discovery(bundled_discovery, cache=True) return discovery
def bundled_discovery(self): with bundle.find("discovery.yml").open() as bundled_discovery: return yaml.safe_load(bundled_discovery)
def test_bundled_discovery(self, subject): # load the bundled discovery file with bundle.find("discovery.yml").open() as bundled: bundled_discovery = DiscoveryFile.parse(yaml.safe_load(bundled)) assert subject.cached_discovery.version == bundled_discovery.version
def __init__(self, project_name): self.initialize_file = bundle.find("initialize.yml") self.project_name = project_name.lower()