flex.common package

Submodules

flex.common.utils module

Copyright (C) 2024 Instituto Andaluz Interuniversitario en Ciencia de Datos e Inteligencia Computacional (DaSCI).

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.

flex.common.utils.check_dir_exists(filename: str) bool[source]

Function that checks if a given directory exits or not.

Args:

filename (str): Directory to check.

Returns:

bool: True/False if the directory exits or not.

flex.common.utils.check_file_exists(filename: str) bool[source]

Function that checks if a given file exits or not.

Args:

filename (str): Filename to check.

Returns:

bool: True/False if the file exits or not.

flex.common.utils.check_integrity(filename: str, md5_hash: str) bool[source]
Function that computes the md5 hash of a file and compares it

with a given one, ensuring that the file corresponds to the given md5 hash.

Args:

filename (str): path to file which will be used to compute a md5 hash md5_hash (str): md5 hash to compare with the one compute using filename

Returns:

bool: whether the given file has the same hash as the one provided

flex.common.utils.check_min_arguments(func: Callable, min_args: int = 1)[source]

Function that inspect the minumum number of arguments of a given function.

Args:

func (Callable): Function to inspect min_args (int, optional): Minimum number of arguments that the function func must have. Defaults to 1.

Raises:

AssertionError: Raise an assertion error if the number of arguments of the given function is lower than the min_args value.

flex.common.utils.download_dataset(url: str, filename: str, md5_hash: str, out_dir: str = '.', extract: bool = False, max_trials: int = 3, output: bool = True)[source]

Function that download a dataset given an URL.

Args:

url (str): url to download the file filename (str): name used to store the downloaded file md5_hash (str): hash used to ensure the integrity of the downloaded file out_dir (str, optional): directory where the downloaded file will be stored. Defaults to “.”. extract (bool, optional): Select to whether to extract the data or not. Defaults to False. max_trials (int, optional): Max number of trials to download the dataset. Defaults to 3. output (bool, optional): whether to return a list with the paths of the downloaded/extractred files. Defaults to True.

Raises:

ValueError: Raise an error if it fails downloading the dataset or the given md5 hash is not correct.

flex.common.utils.download_file(url: str, filename: str, out_dir: str = '.')[source]
Function that downloads a file from a url and stores it in out_dir

with name filename.

Args:

url (str): url to download the file filename (str): name used to store the downloaded file out_dir (str, optional): directory where the downloaded file will be stored. Defaults to “.”.

flex.common.utils.extract_zip(filename: str, output: bool = True)[source]

Function that extract a zip file. If files are already extracted, it skips extracting them.

Args:

filename (str): Directory to check. output (bool): Whether to output the paths of the extracted files

Returns:

bool: True/False if the directory exits or not.

Module contents

Copyright (C) 2024 Instituto Andaluz Interuniversitario en Ciencia de Datos e Inteligencia Computacional (DaSCI)

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.

You should have received a copy of the GNU Affero General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.