def _parse_python_version()

in cli/src/klio_cli/commands/job/create.py [0:0]


    def _parse_python_version(self, python_version):
        if python_version.startswith("2"):
            msg = (
                "Klio no longer supports Python 2.7. "
                "Supported versions: {}".format(
                    ", ".join(VALID_BEAM_PY_VERSIONS)
                )
            )
            raise click.BadParameter(msg)

        if python_version.startswith("3.6") or python_version.startswith("36"):
            msg = (
                "Klio no longer supports Python 3.6. "
                "Supported versions: {}".format(
                    ", ".join(VALID_BEAM_PY_VERSIONS)
                )
            )
            raise click.BadParameter(msg)

        invalid_err_msg = (
            "Invalid Python version given: '{}'. Valid Python versions: "
            "{}".format(python_version, ", ".join(VALID_BEAM_PY_VERSIONS))
        )

        # valid examples: 37, 3.7, 3.7.7
        if len(python_version) < 2 or len(python_version) > 5:
            raise click.BadParameter(invalid_err_msg)

        # keep only the major and minor version information
        python_version = ".".join(python_version.split(".")[:2])

        if python_version not in VALID_BEAM_PY_VERSIONS:
            raise click.BadParameter(invalid_err_msg)

        return python_version