Beispiel #1
0
    def on_make_generate(self, event):
        event.makefile["YARN"] = which("yarn")
        event.makefile["NODE"] = which("node")

        event.makefile.get_target("install").install += ["$(YARN) install --production"]

        event.makefile.get_target("install-dev").install += ["$(YARN) install"]
Beispiel #2
0
    def on_make_generate(self, event):
        event.makefile["YARN"] = which("yarn")
        event.makefile["NODE"] = which("node")

        event.makefile.get_target("install").install += [
            "$(YARN) install --production"
        ]

        event.makefile.get_target("install-dev").install += ["$(YARN) install"]
Beispiel #3
0
    def on_make_generate(self, event):
        kube_config = event.config["kube"]

        event.makefile["KUBECTL"] = which("kubectl")
        event.makefile["KUBECTL_OPTIONS"] = ""
        event.makefile["KUBECONFIG"] = ""
        event.makefile["KUBE_NAMESPACE"] = "default"

        if kube_config.use_helm:
            event.makefile["HELM"] = which("helm")
            event.makefile["HELM_RELEASE"] = event.config.get_name()

        for variant in kube_config.get_variants():
            targets = list(kube_config.get_targets(variant=variant))
            if len(targets):
                rollout_target = "-".join(
                    filter(None, ("kube-rollout", variant)))
                rollback_target = "-".join(
                    filter(None, ("kube-rollback", variant)))

                rollout_commands, rollback_commands = [], []
                for target, (patch_path, patch) in targets:
                    while patch_path:
                        try:
                            patch_path, _bit = patch_path.rsplit(".", 1)
                        except ValueError:
                            patch_path, _bit = None, patch_path
                        patch = {_bit: patch}

                    rollout_commands.append(
                        "$(KUBECTL) $(KUBECTL_OPTIONS) --namespace=$(KUBE_NAMESPACE) patch {target} -p{patch}"
                        .format(target=target, patch=repr(json.dumps(patch))))

                    rollback_commands.append(
                        "$(KUBECTL) rollout undo {target}".format(
                            target=target))

                event.makefile.add_target(
                    rollout_target,
                    "\n".join(rollout_commands),
                    phony=True,
                    doc="Rollout docker image onto kubernetes cluster.",
                )

                event.makefile.add_target(
                    rollback_target,
                    "\n".join(rollback_commands),
                    phony=True,
                    doc="Rollbacks last kubernetes patch operation.",
                )
Beispiel #4
0
    def on_make_generate(self, event):
        kube_config = event.config["kube"]

        event.makefile["KUBECTL"] = which("kubectl")
        event.makefile["KUBECTL_OPTIONS"] = ""
        event.makefile["KUBECONFIG"] = ""
        event.makefile["KUBE_NAMESPACE"] = "default"

        if kube_config.use_helm:
            event.makefile["HELM"] = which("helm")
            event.makefile["HELM_RELEASE"] = event.config.get_name()

        for variant in kube_config.get_variants():
            targets = list(kube_config.get_targets(variant=variant))
            if len(targets):
                rollout_target = "-".join(filter(None, ("kube-rollout", variant)))
                rollback_target = "-".join(filter(None, ("kube-rollback", variant)))

                rollout_commands, rollback_commands = [], []
                for target, (patch_path, patch) in targets:
                    while patch_path:
                        try:
                            patch_path, _bit = patch_path.rsplit(".", 1)
                        except ValueError:
                            patch_path, _bit = None, patch_path
                        patch = {_bit: patch}

                    rollout_commands.append(
                        "$(KUBECTL) $(KUBECTL_OPTIONS) --namespace=$(KUBE_NAMESPACE) patch {target} -p{patch}".format(
                            target=target, patch=repr(json.dumps(patch))
                        )
                    )

                    rollback_commands.append("$(KUBECTL) rollout undo {target}".format(target=target))

                event.makefile.add_target(
                    rollout_target,
                    "\n".join(rollout_commands),
                    phony=True,
                    doc="Rollout docker image onto kubernetes cluster.",
                )

                event.makefile.add_target(
                    rollback_target,
                    "\n".join(rollback_commands),
                    phony=True,
                    doc="Rollbacks last kubernetes patch operation.",
                )
Beispiel #5
0
    def on_make_generate(self, event):
        config = self.get_config(event)  # type: FormatConfig
        makefile = event.makefile

        if "yapf" in config.active_tools and "black" in config.active_tools:
            raise RuntimeError(
                'Using both "black" and "yapf" does not make sense, choose one.'
            )

        format_script = []

        if "black" in config.active_tools:
            makefile["BLACK"] = which("black")
            makefile["BLACK_OPTIONS"] = "--line-length " + str(
                LINE_LENGTH)  # TODO line length global option
            format_script += ["$(BLACK) $(BLACK_OPTIONS) . Projectfile"]

        if "yapf" in config.active_tools:
            makefile["YAPF"] = "$(PYTHON) -m yapf"
            makefile["YAPF_OPTIONS"] = "-rip"
            format_script += ["$(YAPF) $(YAPF_OPTIONS) . Projectfile"]

        if "isort" in config.active_tools:
            makefile["ISORT"] = "$(PYTHON) -m isort"
            makefile["ISORT_OPTIONS"] = ""
            format_script += ["$(ISORT) $(ISORT_OPTIONS) . Projectfile"]

        if "prettier" in config.active_tools:
            makefile["PRETTIER"] = which("prettier")
            makefile["PRETTIER_OPTIONS"] = "--write"
            makefile[
                "PRETTIER_PATTERNS"] = "**/*.\{j,t\}s **/*.\{j,t\}sx \!docs/**"
            format_script += [
                "$(PRETTIER) $(PRETTIER_OPTIONS) $(PRETTIER_PATTERNS)"
            ]

        makefile.add_target(
            "format",
            Script("\n".join(format_script)),
            deps=("install-dev", ),
            phony=True,
            doc="Reformats the codebase (with " +
            ", ".join(sorted(config.active_tools)) + ").",
        )
Beispiel #6
0
 def _get_default_variables(self):
     return dict(
         DOCKER=which("docker"),
         DOCKER_BUILD="$(DOCKER) image build",
         DOCKER_BUILD_OPTIONS="--build-arg IMAGE=$(DOCKER_IMAGE) --build-arg TAG=$(DOCKER_TAG)",
         DOCKER_PUSH="$(DOCKER) image push",
         DOCKER_PUSH_OPTIONS="",
         DOCKER_RUN="$(DOCKER) run",
         DOCKER_RUN_COMMAND="",
         DOCKER_RUN_NAME="$(PACKAGE)_run",
         DOCKER_RUN_OPTIONS="",
         DOCKER_RUN_PORTS="",
     )
Beispiel #7
0
 def _get_default_variables(self):
     return dict(
         DOCKER=which("docker"),
         DOCKER_BUILD="$(DOCKER) image build",
         DOCKER_BUILD_OPTIONS=
         "--build-arg IMAGE=$(DOCKER_IMAGE) --build-arg TAG=$(DOCKER_TAG)",
         DOCKER_PUSH="$(DOCKER) image push",
         DOCKER_PUSH_OPTIONS="",
         DOCKER_RUN="$(DOCKER) run",
         DOCKER_RUN_COMMAND="",
         DOCKER_RUN_NAME="$(PACKAGE)_run",
         DOCKER_RUN_OPTIONS="",
         DOCKER_RUN_PORTS="",
     )
Beispiel #8
0
    def use_rocker_builder(self):
        self.use_default_builder()

        self.builder = ROCKER

        self._variables = [
            self._get_default_variables(),
            self._get_default_image_variables(),
            dict(
                ROCKER=which("rocker"),
                ROCKER_BUILD="$(ROCKER) build",
                ROCKER_BUILD_OPTIONS="",
                ROCKER_BUILD_VARIABLES="--var DOCKER_IMAGE=$(DOCKER_IMAGE) --var DOCKER_TAG=$(DOCKER_TAG) --var PYTHON_REQUIREMENTS_FILE=requirements-prod.txt",
            ),
        ]

        self.scripts.build.set("$(ROCKER_BUILD) $(ROCKER_BUILD_OPTIONS) $(ROCKER_BUILD_VARIABLES) .")
        self.scripts.push.set('ROCKER_BUILD_OPTIONS="$(ROCKER_BUILD_OPTIONS) --push" $(MAKE) docker-build')
Beispiel #9
0
    def use_rocker_builder(self):
        self.use_default_builder()

        self.builder = ROCKER

        self._variables = [
            self._get_default_variables(),
            self._get_default_image_variables(),
            dict(
                ROCKER=which("rocker"),
                ROCKER_BUILD="$(ROCKER) build",
                ROCKER_BUILD_OPTIONS="",
                ROCKER_BUILD_VARIABLES=
                "--var DOCKER_IMAGE=$(DOCKER_IMAGE) --var DOCKER_TAG=$(DOCKER_TAG) --var PYTHON_REQUIREMENTS_FILE=requirements-prod.txt",
            ),
        ]

        self.scripts.build.set(
            "$(ROCKER_BUILD) $(ROCKER_BUILD_OPTIONS) $(ROCKER_BUILD_VARIABLES) ."
        )
        self.scripts.push.set(
            'ROCKER_BUILD_OPTIONS="$(ROCKER_BUILD_OPTIONS) --push" $(MAKE) docker-build'
        )
Beispiel #10
0
    def on_make_generate(self, event):
        """
        **Environment variables**

        - ``PACKAGE``
        - ``PYTHON``
        - ``PYTHON_BASENAME``
        - ``PYTHON_DIR``
        - ``PYTHON_REQUIREMENTS_FILE``
        - ``PYTHON_REQUIREMENTS_DEV_FILE``
        
        **Shortcuts**
        - ``PIP``
        - ``PIP_INSTALL_OPTIONS``

        **Make targets**

        - ``install``
        - ``install-dev``

        :param MakefileEvent event:

        """

        python_config = event.config["python"]  # type: PythonConfig

        def _get_reqs_file_varname(extra=None):
            if extra:
                return "PYTHON_REQUIREMENTS_" + extra.upper().replace(
                    "-", "_") + "_FILE"
            return "PYTHON_REQUIREMENTS_FILE"

        def _get_reqs_inline_varname(extra=None):
            if extra:
                return "PYTHON_REQUIREMENTS_" + extra.upper().replace(
                    "-", "_") + "_INLINE"
            return "PYTHON_REQUIREMENTS_INLINE"

        extra_variables = []
        for extra in event.config["python"].get_extras():
            extra_variables += [
                (_get_reqs_file_varname(extra=extra),
                 "requirements-" + extra + ".txt"),
                (_get_reqs_inline_varname(extra=extra),
                 " ".join(python_config.get_inline_requirements(extra=extra))),
            ]

        # Python related environment
        event.makefile.updateleft(
            ("PACKAGE", event.config.package_name),
            ("PYTHON", which("python")),
            ("PYTHON_BASENAME", "$(shell basename $(PYTHON))"),
            ("PYTHON_DIRNAME", "$(shell dirname $(PYTHON))"),
            (_get_reqs_file_varname(), "requirements.txt"),
            (_get_reqs_inline_varname(), " ".join(
                python_config.get_inline_requirements())), *extra_variables)

        event.makefile["PIP"] = "$(PYTHON) -m pip"
        event.makefile["PIP_INSTALL_OPTIONS"] = ""

        if python_config.use_wheelhouse:

            def _get_wheelhouse(extra=None):
                if extra:
                    return ".wheelhouse-" + extra
                return ".wheelhouse"

            def _get_wheelhouse_options(extra=None):
                return "--no-index --find-links=" + _get_wheelhouse(
                    extra=extra)

            def _get_install_commands(extra=None):
                return [
                    "$(PIP) install $(PIP_INSTALL_OPTIONS) " +
                    _get_wheelhouse_options(extra=extra) + ' -U "pip ' +
                    PIP_VERSION + '" wheel',
                    "$(PIP) install $(PIP_INSTALL_OPTIONS) " +
                    _get_wheelhouse_options(extra=extra) + " -U $(" +
                    _get_reqs_inline_varname(extra=extra) + ") -r $(" +
                    _get_reqs_file_varname(extra=extra) + ")",
                ]

            def _get_install_deps(extra=None):
                # TODO add inline requirements without -e/-r ?
                return [
                    ".medikit/" + _get_wheelhouse(extra=extra),
                    "$(" + _get_reqs_file_varname(extra=extra) + ")",
                    "setup.py",
                ]

            for extra in (None, *python_config.get_extras()):
                target = _get_wheelhouse(extra=extra)

                if not event.makefile.has_target(target):
                    event.makefile.add_target(target,
                                              InstallScript(),
                                              phony=True)

                clean_target = event.makefile.get_clean_target()
                marker = ".medikit/" + target
                if not marker in clean_target.remove:
                    clean_target.remove.append(marker)

                event.makefile.get_target(target).install += [
                    "$(PIP) wheel -w " + _get_wheelhouse(extra=extra) + " $(" +
                    _get_reqs_inline_varname(extra=extra) + ") -r $(" +
                    _get_reqs_file_varname(extra=extra) + ")"
                ]

        else:

            def _get_install_commands(extra=None):
                return [
                    '$(PIP) install $(PIP_INSTALL_OPTIONS) -U "pip ' +
                    PIP_VERSION + '" wheel',
                    "$(PIP) install $(PIP_INSTALL_OPTIONS) -U $(" +
                    _get_reqs_inline_varname(extra=extra) + ") -r $(" +
                    _get_reqs_file_varname(extra=extra) + ")",
                ]

            def _get_install_deps(extra=None):
                # TODO add inline requirements without -e/-r ?
                return [
                    "$(" + _get_reqs_file_varname(extra=extra) + ")",
                    "setup.py"
                ]

        for extra in (None, *python_config.get_extras()):
            target = event.makefile.add_install_target(extra)
            target.install += _get_install_commands(extra=extra)
            target.deps += _get_install_deps(extra=extra)
Beispiel #11
0
    def on_make_generate(self, event):
        """
        **Environment variables**

        - ``PACKAGE``
        - ``PYTHON``
        - ``PYTHON_BASENAME``
        - ``PYTHON_DIR``
        - ``PYTHON_REQUIREMENTS_FILE``
        - ``PYTHON_REQUIREMENTS_DEV_FILE``
        
        **Shortcuts**
        - ``PIP``
        - ``PIP_INSTALL_OPTIONS``

        **Make targets**

        - ``install``
        - ``install-dev``

        :param MakefileEvent event:

        """

        python_config = event.config["python"]  # type: PythonConfig

        def _get_reqs_file_varname(extra=None):
            if extra:
                return "PYTHON_REQUIREMENTS_" + extra.upper().replace("-", "_") + "_FILE"
            return "PYTHON_REQUIREMENTS_FILE"

        def _get_reqs_inline_varname(extra=None):
            if extra:
                return "PYTHON_REQUIREMENTS_" + extra.upper().replace("-", "_") + "_INLINE"
            return "PYTHON_REQUIREMENTS_INLINE"

        extra_variables = []
        for extra in event.config["python"].get_extras():
            extra_variables += [
                (_get_reqs_file_varname(extra=extra), "requirements-" + extra + ".txt"),
                (_get_reqs_inline_varname(extra=extra), " ".join(python_config.get_inline_requirements(extra=extra))),
            ]

        # Python related environment
        event.makefile.updateleft(
            ("PACKAGE", event.config.package_name),
            ("PYTHON", which("python")),
            ("PYTHON_BASENAME", "$(shell basename $(PYTHON))"),
            ("PYTHON_DIRNAME", "$(shell dirname $(PYTHON))"),
            (_get_reqs_file_varname(), "requirements.txt"),
            (_get_reqs_inline_varname(), " ".join(python_config.get_inline_requirements())),
            *extra_variables
        )

        event.makefile["PIP"] = "$(PYTHON) -m pip"
        event.makefile["PIP_INSTALL_OPTIONS"] = ""

        if python_config.use_wheelhouse:

            def _get_wheelhouse(extra=None):
                if extra:
                    return ".wheelhouse-" + extra
                return ".wheelhouse"

            def _get_wheelhouse_options(extra=None):
                return "--no-index --find-links=" + _get_wheelhouse(extra=extra)

            def _get_install_commands(extra=None):
                return [
                    "$(PIP) install $(PIP_INSTALL_OPTIONS) "
                    + _get_wheelhouse_options(extra=extra)
                    + ' -U "pip ~=18.0" wheel',
                    "$(PIP) install $(PIP_INSTALL_OPTIONS) "
                    + _get_wheelhouse_options(extra=extra)
                    + " -U $("
                    + _get_reqs_inline_varname(extra=extra)
                    + ") -r $("
                    + _get_reqs_file_varname(extra=extra)
                    + ")",
                ]

            def _get_install_deps(extra=None):
                # TODO add inline requirements without -e/-r ?
                return [
                    ".medikit/" + _get_wheelhouse(extra=extra),
                    "$(" + _get_reqs_file_varname(extra=extra) + ")",
                    "setup.py",
                ]

            for extra in (None, *python_config.get_extras()):
                target = _get_wheelhouse(extra=extra)

                if not event.makefile.has_target(target):
                    event.makefile.add_target(target, InstallScript(), phony=True)

                clean_target = event.makefile.get_clean_target()
                marker = ".medikit/" + target
                if not marker in clean_target.remove:
                    clean_target.remove.append(marker)

                event.makefile.get_target(target).install += [
                    "$(PIP) wheel -w "
                    + _get_wheelhouse(extra=extra)
                    + " $("
                    + _get_reqs_inline_varname(extra=extra)
                    + ") -r $("
                    + _get_reqs_file_varname(extra=extra)
                    + ")"
                ]

        else:

            def _get_install_commands(extra=None):
                return [
                    '$(PIP) install $(PIP_INSTALL_OPTIONS) -U "pip ~=18.0" wheel',
                    "$(PIP) install $(PIP_INSTALL_OPTIONS) -U $("
                    + _get_reqs_inline_varname(extra=extra)
                    + ") -r $("
                    + _get_reqs_file_varname(extra=extra)
                    + ")",
                ]

            def _get_install_deps(extra=None):
                # TODO add inline requirements without -e/-r ?
                return ["$(" + _get_reqs_file_varname(extra=extra) + ")", "setup.py"]

        for extra in (None, *python_config.get_extras()):
            target = event.makefile.add_install_target(extra)
            target.install += _get_install_commands(extra=extra)
            target.deps += _get_install_deps(extra=extra)