Пример #1
0
    def resolve_uri_locally(self, artifact_uri: Text, path: Text = None):
        """
        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.
        """
        if not path_utils.is_remote(artifact_uri):
            # Its already local
            return artifact_uri

        if path is None:
            path = os.path.join(
                GlobalConfig.get_config_dir(),
                self.unique_id,
                ArtifactStore.get_component_name_from_uri(artifact_uri),
                path_utils.get_parent(artifact_uri)  # unique ID from MLMD
            )

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

        return path
Пример #2
0
    def init_repo(repo_path: Text, artifact_store_path: Text = None,
                  metadata_store: Optional[ZenMLMetadataStore] = None,
                  pipelines_dir: Text = None,
                  analytics_opt_in: bool = None):
        """
        Initializes a git repo with zenml.

        Args:
            repo_path (str): path to root of a git repo
            metadata_store: metadata store definition
            artifact_store_path (str): path where to store artifacts
            pipelines_dir (str): path where to store pipeline configs.
            analytics_opt_in (str): opt-in flag for analytics code.

        Raises:
            InvalidGitRepositoryError: If repository is not a git repository.
            NoSuchPathError: If the repo_path does not exist.
        """
        # check whether its a git repo by initializing GitWrapper
        git_wrapper = GitWrapper(repo_path)
        # Do proper checks and add to .gitignore
        git_wrapper.add_gitignore([ZENML_DIR_NAME + '/'])

        # use the underlying ZenMLConfig class to create the config
        ZenMLConfig.to_config(
            repo_path, artifact_store_path, metadata_store, pipelines_dir)

        # create global config
        global_config = GlobalConfig.get_instance()
        if analytics_opt_in is not None:
            global_config.set_analytics_opt_in(analytics_opt_in)
Пример #3
0
def track_event(event, metadata=None):
    """
    Track segment event if user opted-in.

    Args:
        event: name of event to track in segment.
        metadata: dict of metadata
    """
    try:
        from zenml.core.repo.global_config import GlobalConfig
        config = GlobalConfig.get_instance()
        opt_in = config.get_analytics_opt_in()
        logger.debug(f"Analytics opt-in: {opt_in}.")

        if opt_in is False:
            return

        user_id = config.get_user_id()

        if metadata is None:
            metadata = {}

        # add basics
        metadata.update(get_system_info())
        metadata.update({'version': __version__})

        analytics.track(user_id, event, metadata)
        logger.debug(
            f'Analytics sent: User: {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}')
        return