Repository: kedro-org/kedro

Issue:
Add logging when computing micropackage version
## Description

My team and I had a hard time debugging our micropackages versioning. It is not easy to find out why the package version that is picked is not the one that we expect. 

If Kedro was a bit more verbose at startup, it would help to find out what is wrong in our project structure or setup (in our case, it was because some dependencies were not installed in the python environment. But the module loading was failing silently so we could not see that pandas was missing and that this was the cause for the wrong versioning of the micropackage)

## Context

I need to micropackage different modular pipelines with different version numbers. Each version number is written in `src/<project_name>/pipelines/<pipeline_name>/__init__.py`

## Possible Implementation

Add some logging in `kedro/framework/cli/micropkg.py`:

```

def _get_default_version(metadata: ProjectMetadata, micropkg_module_path: str) -> str:
    # default to micropkg package version
    try:
        micropkg_module = import_module(
            f"{metadata.package_name}.{micropkg_module_path}"
        )
        return micropkg_module.__version__  # type: ignore
    except (AttributeError, ModuleNotFoundError):
        logger.warning(f"Micropackage version not found in '{metadata.package_name}.{micropkg_module_path}', will take the top-level one in '{metadata.package_name}')
        # if micropkg version doesn't exist, take the project one
        project_module = import_module(f"{metadata.package_name}")
        return project_module.__version__  # type: ignore
```

## Possible Alternative

Additionnally to adding somme logging in `kedro/framework/cli/micropkg.py`, we could stop catching the exception if micropackage module cannot be loaded, so that the error is not silenced:

```
def _get_default_version(metadata: ProjectMetadata, micropkg_module_path: str) -> str:
    # default to micropkg package version
    micropkg_module = import_module(
        f"{metadata.package_name}.{micropkg_module_path}"
    )
    try:
        return micropkg_module.__version__  # type: ignore
    except AttributeError:
        logger.warning(f"Micropackage version not found in '{metadata.package_name}.{micropkg_module_path}', will take the top-level one in '{metadata.package_name}')
        # if micropkg version doesn't exist, take the project one
        project_module = import_module(f"{metadata.package_name}")
        return project_module.__version__  # type: ignore
```




Discussion:
That's a very reasonable request. Thanks for flagging it @clotildeguinard . I'll add it to the backlog, but we would also be very happy to accept a PR for this. It might be faster to get the change in that way 🙂 

Resolving patch:
diff --git a/kedro/framework/cli/micropkg.py b/kedro/framework/cli/micropkg.py
--- a/kedro/framework/cli/micropkg.py
+++ b/kedro/framework/cli/micropkg.py
@@ -2,6 +2,7 @@
 # ruff: noqa: I001 # https://github.com/kedro-org/kedro/pull/2634
 from __future__ import annotations
 
+import logging
 import re
 import shutil
 import sys
@@ -52,6 +53,8 @@
 find = {{}}
 """
 
+logger = logging.getLogger(__name__)
+
 
 class _EquivalentRequirement(Requirement):
     """Parse a requirement according to PEP 508.
@@ -592,6 +595,12 @@ def _get_default_version(metadata: ProjectMetadata, micropkg_module_path: str) -
         )
         return micropkg_module.__version__  # type: ignore
     except (AttributeError, ModuleNotFoundError):
+        logger.warning(
+            "Micropackage version not found in '%s.%s', will take the top-level one in '%s'",
+            metadata.package_name,
+            micropkg_module_path,
+            metadata.package_name,
+        )
         # if micropkg version doesn't exist, take the project one
         project_module = import_module(f"{metadata.package_name}")
         return project_module.__version__  # type: ignore


Test patch: