diff --git a/melusine/_config.py b/melusine/_config.py index 58eee93..3b94944 100644 --- a/melusine/_config.py +++ b/melusine/_config.py @@ -1,6 +1,7 @@ """ Module which handles the package configuration. """ + import copy import logging import os diff --git a/melusine/backend/base_backend.py b/melusine/backend/base_backend.py index 16e88f7..cd5f46a 100644 --- a/melusine/backend/base_backend.py +++ b/melusine/backend/base_backend.py @@ -7,6 +7,7 @@ BaseTransformerBackend, ] """ + from abc import ABC, abstractmethod from typing import Any, Callable, List, Optional diff --git a/melusine/backend/pandas_backend.py b/melusine/backend/pandas_backend.py index 9228d5e..951dc8a 100644 --- a/melusine/backend/pandas_backend.py +++ b/melusine/backend/pandas_backend.py @@ -5,6 +5,7 @@ PandasBackend, ] """ + from typing import Any, Callable, List, Optional, Tuple, Union import numpy as np diff --git a/melusine/base.py b/melusine/base.py index f586db5..a0f72c1 100644 --- a/melusine/base.py +++ b/melusine/base.py @@ -11,6 +11,7 @@ MelusineFeatureEncoder ] """ + from __future__ import annotations import copy diff --git a/melusine/connectors/gmail.py b/melusine/connectors/gmail.py index 8b31c92..682d445 100644 --- a/melusine/connectors/gmail.py +++ b/melusine/connectors/gmail.py @@ -11,6 +11,7 @@ from google.oauth2.credentials import Credentials from google_auth_oauthlib.flow import InstalledAppFlow from googleapiclient.discovery import build +from googleapiclient.errors import HttpError from tqdm import tqdm logger = logging.getLogger(__name__) @@ -158,8 +159,15 @@ def create_label(self, label_name: str) -> Dict[str, str]: Returns: Dict[str, str]: return from the api with label and its informations """ - label = self.service.users().labels().create(userId="me", body=dict(name=label_name)).execute() - logger.info(f"Label {label_name} has been created.") + try: + label = self.service.users().labels().create(userId="me", body=dict(name=label_name)).execute() + logger.info(f"Label {label_name} has been created.") + except HttpError as error: + if error.resp.status == 409: # Conflict error if label already exists + logger.error(f"Label '{label_name}' already exists.") + return {} + else: + raise return label @staticmethod diff --git a/melusine/detectors.py b/melusine/detectors.py index e6a10c7..96bf51a 100644 --- a/melusine/detectors.py +++ b/melusine/detectors.py @@ -5,6 +5,7 @@ ReplyDetector, TransferDetector, RecipientsDetector] """ + from typing import Any, Dict, List, Tuple from melusine.base import MelusineDetector, MelusineItem, MelusineRegex diff --git a/melusine/io/_classes.py b/melusine/io/_classes.py index 02c6c6e..e7c6c24 100644 --- a/melusine/io/_classes.py +++ b/melusine/io/_classes.py @@ -3,6 +3,7 @@ Contained classes: [IoMixin] """ + from __future__ import annotations import logging diff --git a/melusine/message.py b/melusine/message.py index 97d5c01..e58e09f 100644 --- a/melusine/message.py +++ b/melusine/message.py @@ -5,6 +5,7 @@ Implemented classes: [Message] """ + import re from datetime import datetime from typing import Iterable, List, Optional, Tuple diff --git a/melusine/pipeline.py b/melusine/pipeline.py index 6888ae2..7c37dfb 100644 --- a/melusine/pipeline.py +++ b/melusine/pipeline.py @@ -3,6 +3,7 @@ Implemented classes: [PipelineConfigurationError, MelusinePipeline] """ + from __future__ import annotations import copy diff --git a/melusine/processors.py b/melusine/processors.py index 7239bd3..c40e49b 100644 --- a/melusine/processors.py +++ b/melusine/processors.py @@ -18,6 +18,7 @@ Cleaner, ] """ + from __future__ import annotations import logging @@ -1901,7 +1902,6 @@ def clean(self, text: str) -> str: class DateProcessor(MelusineTransformer): - """ Parse string date to iso format string date """ diff --git a/melusine/regex/__init__.py b/melusine/regex/__init__.py index b987cd3..f27b8a8 100644 --- a/melusine/regex/__init__.py +++ b/melusine/regex/__init__.py @@ -1,6 +1,7 @@ """ The melusine.regex module includes tools for handling regexes. """ + from melusine.regex.emergency_regex import EmergencyRegex from melusine.regex.reply_regex import ReplyRegex from melusine.regex.thanks_regex import ThanksRegex diff --git a/melusine/testing/pipeline_testing.py b/melusine/testing/pipeline_testing.py index bed25f7..28aa90c 100644 --- a/melusine/testing/pipeline_testing.py +++ b/melusine/testing/pipeline_testing.py @@ -1,6 +1,7 @@ """ Module that contains utility functions for tests (in /tests). """ + from typing import Any, Dict from melusine.base import MelusineTransformer diff --git a/melusine/utils/__init__.py b/melusine/utils/__init__.py index 612fb05..13c2efe 100644 --- a/melusine/utils/__init__.py +++ b/melusine/utils/__init__.py @@ -1,6 +1,7 @@ """ The melusine.utils module includes utils functionalitites. """ + from melusine.utils.show_versions import show_versions __all__ = ["show_versions"] diff --git a/tests/detectors/test_reply_detector.py b/tests/detectors/test_reply_detector.py index b939fef..56555a2 100644 --- a/tests/detectors/test_reply_detector.py +++ b/tests/detectors/test_reply_detector.py @@ -1,6 +1,7 @@ """ Unit tests of the ReplyDetector. """ + import pandas as pd import pytest from pandas import DataFrame diff --git a/tests/detectors/test_thanks_detector.py b/tests/detectors/test_thanks_detector.py index b84510a..7f6e41c 100644 --- a/tests/detectors/test_thanks_detector.py +++ b/tests/detectors/test_thanks_detector.py @@ -2,6 +2,7 @@ Unit test of the ThanksDetector. """ + from tempfile import TemporaryDirectory import pandas as pd diff --git a/tests/detectors/test_transfer_detector.py b/tests/detectors/test_transfer_detector.py index e9ae89f..96ab166 100644 --- a/tests/detectors/test_transfer_detector.py +++ b/tests/detectors/test_transfer_detector.py @@ -2,7 +2,6 @@ Unit tests of the TransferDetector. """ - import pandas as pd import pytest from pandas import DataFrame diff --git a/tests/detectors/test_vacation_reply_detector.py b/tests/detectors/test_vacation_reply_detector.py index d733779..40a625f 100644 --- a/tests/detectors/test_vacation_reply_detector.py +++ b/tests/detectors/test_vacation_reply_detector.py @@ -1,6 +1,7 @@ """ Unit tests of the VacationReplyDetector """ + import pandas as pd import pytest from pandas import DataFrame diff --git a/tests/functional/test_emails_fixtures.py b/tests/functional/test_emails_fixtures.py index 30586ab..58f719b 100644 --- a/tests/functional/test_emails_fixtures.py +++ b/tests/functional/test_emails_fixtures.py @@ -41,6 +41,7 @@ } ======================================================================================== """ + import pytest testcase_initial_cleaning_1 = dict( diff --git a/tests/pipeline/test_pipeline.py b/tests/pipeline/test_pipeline.py index 507530e..cecb5cd 100644 --- a/tests/pipeline/test_pipeline.py +++ b/tests/pipeline/test_pipeline.py @@ -1,6 +1,7 @@ """ Unit test for pipeline.py """ + import pandas as pd import pytest diff --git a/tests/pipeline/test_pipeline_basic.py b/tests/pipeline/test_pipeline_basic.py index 5eb94ae..d2b2f25 100644 --- a/tests/pipeline/test_pipeline_basic.py +++ b/tests/pipeline/test_pipeline_basic.py @@ -1,6 +1,7 @@ """ Example script to fit a minimal preprocessing pipeline """ + import pandas as pd import pytest diff --git a/tests/processors/test_processors.py b/tests/processors/test_processors.py index ba4257a..c6aaae5 100644 --- a/tests/processors/test_processors.py +++ b/tests/processors/test_processors.py @@ -1,6 +1,7 @@ """ Unit test for processors.py """ + import pytest from melusine.processors import (