Пример #1
0
    def resolve_uri_locally(self,
                            artifact_uri: str,
                            path: Optional[str] = None) -> str:
        """Takes a URI that points within the artifact store, downloads the
        URI locally, then returns local URI.

        Args:
          artifact_uri: uri to artifact.
          path: optional path to download to. If None, is inferred.

        Returns:
            Locally resolved uri.
        """
        if not fileio.is_remote(artifact_uri):
            # It's already local
            return artifact_uri

        if path is None:
            # Create a unique path in local machine
            path = os.path.join(
                GlobalConfig().get_serialization_dir(),
                str(self.uuid),
                BaseArtifactStore.get_component_name_from_uri(artifact_uri),
                fileio.get_parent(artifact_uri),  # unique ID from MLMD
            )

        # Create if not exists and download
        fileio.create_dir_recursive_if_not_exists(path)
        fileio.copy_dir(artifact_uri, path, overwrite=True)

        return path
Пример #2
0
def track_event(event: str, metadata: Optional[Dict[str, Any]] = None) -> None:
    """
    Track segment event if user opted-in.

    Args:
        event: Name of event to track in segment.
        metadata: Dict of metadata to track.
    """
    try:
        import analytics

        if analytics.write_key is None:
            analytics.write_key = get_segment_key()

        assert (analytics.write_key is not None
                ), "Analytics key not set but trying to make telemetry call."

        from zenml.config.global_config import GlobalConfig

        gc = GlobalConfig()

        if not gc.analytics_opt_in and event != INITIALIZE_REPO:
            return

        if metadata is None:
            metadata = {}

        # add basics
        metadata.update(get_system_info())
        metadata.update({
            "in_docker": in_docker(),
            "in_google_colab": in_google_colab(),
            "in_paperspace_gradient": in_paperspace_gradient(),
            "version": __version__,
        })

        analytics.track(str(gc.user_id), event, metadata)
        logger.debug(
            f"Analytics sent: User: {gc.user_id}, Event: {event}, Metadata: "
            f"{metadata}")
    except Exception as e:
        # We should never fail main thread
        logger.debug(f"Analytics failed due to: {e}")
Пример #3
0
def opt_out() -> None:
    """Opt-out to analytics"""
    gc = GlobalConfig()
    gc.analytics_opt_in = False
    gc.update()
    cli_utils.declare("Opted out of analytics.")
Пример #4
0
def opt_in() -> None:
    """Opt-in to analytics"""
    gc = GlobalConfig()
    gc.analytics_opt_in = True
    gc.update()
    cli_utils.declare("Opted in to analytics.")
Пример #5
0
def is_analytics_opted_in() -> None:
    """Check whether user is opt-in or opt-out of analytics."""
    gc = GlobalConfig()
    cli_utils.declare(f"Analytics opt-in: {gc.analytics_opt_in}")
Пример #6
0
def set_analytics_opt_in_status(status: bool):
    """Set the analytics opt-in status"""
    gc = GlobalConfig()
    gc.analytics_opt_in = status
    gc.update()
Пример #7
0
def get_analytics_opt_in_status():
    """Get the analytics opt-in status"""
    gc = GlobalConfig()
    return gc.analytics_opt_in
Пример #8
0
def test_global_config_file_creation():
    """A simple test to check whether the global config is created."""
    GlobalConfig()

    # Raw config should now exist
    assert fileio.file_exists(os.path.join(APP_DIR, GLOBAL_CONFIG_NAME))