Exemple #1
0
def download_extensions(extensions: Dict[str, str],
                        container_folder: str) -> Dict[str, str]:
    """Iterate through the extensions and download the remote urls.

    Parameters
    ----------
    extensions: Dict[str, str]
        The extensions that may contain both local or remote locations.
    container_folder: str
        The auxiliary folder where to download the remote repo

    Returns
    -------
    Dict[str, str]
        A new extensions dict with the local paths instead of remote
        urls. The local paths contain the downloaded remote resources.

    """
    ret = {}
    for key, inc in extensions.items():
        if _is_url(inc):
            loc = os.path.join(container_folder, key)
            new_inc = _download_remote_extension(inc, loc)
            ret[key] = new_inc
        else:
            expanded_inc = os.path.abspath(
                os.path.expanduser(inc))  # Could be path with ~, or rel
            if os.path.exists(expanded_inc):
                ret[key] = expanded_inc
            else:
                ret[key] = inc

    return ret
Exemple #2
0
    def parse(self) -> None:
        """Parse the experiment.

        Parse the Experiment in search of errors that won't allow the
        experiment to run successfully. If it finds any error, then it
        raises an ParsingExperimentError.

        Raises
        ------
        ParsingExperimentError
            In case a parsing error is found.

        """
        # Check if name is None:
        if self.name is None or len(self.name) == 0:
            raise error.ParsingRunnableError(
                "Experiment should declare a name and it must not be empty")

        # Check if name is valid
        else:
            if re.match('^([a-zA-Z0-9]+[_-]*)+$', self.name) is None:
                raise error.ParsingRunnableError(
                    "Experiment name should contain only alphanumeric characters "
                    + "(with optional - or _ in between)")

        # Check if resources contains only local and remote
        if self.resources:
            if len(
                    list(
                        filter(lambda x: x not in ['local', 'remote'],
                               self.resources.keys()))) > 0:
                raise error.ParsingRunnableError(
                    f"'resources' section must contain only 'local' section and/or 'remote' keys"
                )

        # Check if local resources exists:
        if self.resources and self.resources.get("local"):
            for v in self.resources["local"].values():
                if not _is_url(v) and not os.path.exists(
                        os.path.expanduser(v)):
                    raise error.ParsingRunnableError(
                        f"Local resource '{v}' does not exist.")
Exemple #3
0
def _contains_path(nested_dict) -> bool:
    """Whether the nested dict contains any value that could be a path.

    Parameters
    ----------
    nested_dict
        The nested dict to evaluate

    Returns
    -------
    bool

    """
    for v in nested_dict.values():
        if hasattr(v, "values"):
            if _contains_path(v):
                return True
        if isinstance(v, str) and os.sep in v and not _is_url(v):
            return True

    return False