Exemple #1
0
def main():  # pragma: no cover
    """Main entry point. Look for a ``cli.py``, and, if found, add its
    commands to `kedro`'s before invoking the CLI.
    """
    _init_plugins()

    global_groups = [cli]
    global_groups.extend(load_entry_points("global"))
    project_groups = []
    cli_context = dict()

    path = Path.cwd()
    if _is_project(path):
        # load project commands from cli.py
        metadata = _get_project_metadata(path)
        cli_context = dict(obj=metadata)
        _add_src_to_path(metadata.source_dir, path)

        project_groups.extend(load_entry_points("project"))
        package_name = metadata.package_name

        try:
            project_cli = importlib.import_module(f"{package_name}.cli")
            project_groups.append(project_cli.cli)
        except Exception as exc:
            raise KedroCliError(
                f"Cannot load commands from {package_name}.cli"
            ) from exc

    cli_collection = CommandCollection(
        ("Global commands", global_groups),
        ("Project specific commands", project_groups),
    )
    cli_collection(**cli_context)
Exemple #2
0
    def reset_commands(self):
        self.commands = {}

        # add commands on the fly based on conditions
        if _is_project(Path.cwd()):
            self.add_command(init)
            self.add_command(ui)
            self.add_command(modelify)
Exemple #3
0
 def _load_project(project_path):  # pragma: no cover
     # TODO: This one can potentially become project bootstrap and will be
     #  tested there
     if not _is_project(project_path):
         return None
     metadata = _get_project_metadata(project_path)
     _add_src_to_path(metadata.source_dir, project_path)
     configure_project(metadata.package_name)
     return metadata
Exemple #4
0
def _find_kedro_project(current_dir):  # pragma: no cover
    from kedro.framework.startup import _is_project

    while current_dir != current_dir.parent:
        if _is_project(current_dir):
            return current_dir
        current_dir = current_dir.parent

    return None
Exemple #5
0
    def __init__(self, project_path: Path):
        self._metadata = None  # running in package mode
        if _is_project(project_path):
            self._metadata = bootstrap_project(project_path)
        self._cli_hook_manager = CLIHooksManager()

        super().__init__(
            ("Global commands", self.global_groups),
            ("Project specific commands", self.project_groups),
        )
Exemple #6
0
    def reset_commands(self):
        self.commands = {}

        # add commands on the fly based on conditions
        if _is_project(Path.cwd()):
            self.add_command(init)
            self.add_command(ui)
            # self.add_command(run) # TODO : IMPLEMENT THIS FUNCTION
        else:
            self.add_command(new)
Exemple #7
0
    def __init__(
        self,
        project_path: Union[str, Path],
        mlflow_tracking_uri: str = "mlruns",
        credentials: Optional[Dict[str, str]] = None,
        disable_tracking_opts: Optional[Dict[str, str]] = None,
        experiment_opts: Union[Dict[str, Any], None] = None,
        run_opts: Union[Dict[str, Any], None] = None,
        ui_opts: Union[Dict[str, Any], None] = None,
        node_hook_opts: Union[Dict[str, Any], None] = None,
    ):

        # declare attributes in __init__.py to avoid pylint complaining
        if not _is_project(project_path):
            raise KedroMlflowConfigError((
                f"'project_path' = '{project_path}' is not a valid path to a kedro project"
            ))
        self.project_path = Path(project_path)
        # TODO we may add mlflow_registry_uri future release
        self.mlflow_tracking_uri = "mlruns"
        self.credentials = (
            credentials or {}
        )  # replace None by {} but o not default to empty dict which is mutable
        self.disable_tracking_opts = None
        self.experiment_opts = None
        self.run_opts = None
        self.ui_opts = None
        self.node_hook_opts = None
        self.mlflow_client = None  # the client to interact with the mlflow database
        self.experiment = (
            None  # the mlflow experiment object to interact directly with it
        )

        # load attributes with the from_dict method
        # which is the method which will almost always be used
        # for loading the configuration
        configuration = dict(
            mlflow_tracking_uri=mlflow_tracking_uri,
            credentials=credentials,
            disable_tracking=disable_tracking_opts,
            experiment=experiment_opts,
            run=run_opts,
            ui=ui_opts,
            hooks=dict(node=node_hook_opts),
        )
        self.from_dict(configuration)
Exemple #8
0
    def test_valid_toml_file(self, mocker):
        mocker.patch.object(Path, "is_file", return_value=True)
        pyproject_toml_payload = {"tool": {"kedro": {}}}
        mocker.patch("anyconfig.load", return_value=pyproject_toml_payload)

        assert _is_project(self.project_path)
Exemple #9
0
    def test_toml_invalid_format(self, tmp_path):
        """Test for loading context from an invalid path. """
        toml_path = tmp_path / "pyproject.toml"
        toml_path.write_text("!!")  # Invalid TOML

        assert not _is_project(tmp_path)
Exemple #10
0
    def test_no_metadata_file(self, mocker):
        mocker.patch.object(Path, "is_file", return_value=False)

        assert not _is_project(self.project_path)
Exemple #11
0
    def test_toml_bad_encoding(self, mocker):
        mocker.patch.object(Path, "is_file", return_value=True)
        mocker.patch.object(Path, "read_text", side_effect=UnicodeDecodeError)

        assert not _is_project(self.project_path)
Exemple #12
0
    def test_valid_toml_file(self, mocker):
        mocker.patch.object(Path, "is_file", return_value=True)
        pyproject_toml_payload = "[tool.kedro]"  # \nproject_name = 'proj'"
        mocker.patch.object(Path, "read_text", return_value=pyproject_toml_payload)

        assert _is_project(self.project_path)