Пример #1
0
 def __init__(self):
     self._googleapis = None
     self._googleapis_private = None
     self._artman = artman.Artman()
Пример #2
0
    def _generate_code(self,
                       service,
                       version,
                       language,
                       config_path=None,
                       artman_output_name=None):
        # map the language to the artman argument and subdir of genfiles
        GENERATE_FLAG_LANGUAGE = {
            "python": ("python_gapic", "python"),
            "nodejs": ("nodejs_gapic", "js"),
            "ruby": ("ruby_gapic", "ruby"),
            "php": ("php_gapic", "php"),
            "java": ("java_discogapic", "java"),
        }

        if language not in GENERATE_FLAG_LANGUAGE:
            raise ValueError("provided language unsupported")

        gapic_language_arg, gen_language = GENERATE_FLAG_LANGUAGE[language]

        if self.discovery_artifact_manager is None:
            raise RuntimeError(
                f"Unable to generate {config_path}, the googleapis repository"
                "is unavailable.")

        # Run the code generator.
        # $ artman --config path/to/artman_api.yaml generate python_gapic
        if config_path is None:
            config_path = (Path("gapic/google") / service /
                           f"artman_{service}_{version}.yaml")
        elif Path(config_path).is_absolute():
            config_path = Path(config_path).relative_to("/")
        else:
            config_path = Path("gapic/google") / service / Path(config_path)

        if not (self.discovery_artifact_manager / config_path).exists():
            raise FileNotFoundError(
                f"Unable to find configuration yaml file: {config_path}.")

        logger.debug(f"Running generator for {config_path}.")
        output_root = artman.Artman().run(
            f"googleapis/artman:{artman.ARTMAN_VERSION}",
            self.discovery_artifact_manager,
            config_path,
            gapic_language_arg,
        )

        # Expect the output to be in the artman-genfiles directory.
        # example: /artman-genfiles/python/speech-v1
        if artman_output_name is None:
            artman_output_name = f"{service}-{version}"
        genfiles = output_root / gen_language / artman_output_name

        if not genfiles.exists():
            raise FileNotFoundError(
                f"Unable to find generated output of artman: {genfiles}.")

        logger.success(f"Generated code into {genfiles}.")

        _tracked_paths.add(genfiles)
        return genfiles