Skip to content

Commit

Permalink
Add many deprecation warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
dostuffthatmatters committed Mar 24, 2024
1 parent 4c6ad49 commit 756a1f7
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 35 deletions.
51 changes: 45 additions & 6 deletions docs/pages/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,16 @@ Context managers for common tasks.

Implements: `ensure_section_duration`, `set_alarm`, `clear_alarm`.

All functions in this module are deprecated and will be removed in the
next breaking release. Use the functions from the `timing` module instead.


##### `ensure_section_duration`

```python
@deprecated(
"Will be removed in the next breaking release. Use `timing.ensure_section_duration` instead."
)
@contextlib.contextmanager
def ensure_section_duration(duration: float) -> Generator[None, None, None]
```
Expand All @@ -36,6 +42,9 @@ with ensure_section_duration(6):
##### `set_alarm`

```python
@deprecated(
"Will be removed in the next breaking release. Use `timing.set_alarm` instead."
)
def set_alarm(timeout: int, label: str) -> None
```

Expand All @@ -47,6 +56,9 @@ Set an alarm that will raise a `TimeoutError` after
##### `clear_alarm`

```python
@deprecated(
"Will be removed in the next breaking release. Use `timing.clear_alarm` instead."
)
def clear_alarm() -> None
```

Expand Down Expand Up @@ -159,7 +171,11 @@ should not interfere. A file "*.lock" will be created and the
content of this file will make the wrapped function possibly
wait until other programs are done using it.

See https://en.wikipedia.org/wiki/Semaphore_(programming)
See https://en.wikipedia.org/wiki/Semaphore_(programming).


Credits for the typing of higher level decorators goes to
https://github.com/python/mypy/issues/1551#issuecomment-253978622.


##### `__init__`
Expand All @@ -177,7 +193,10 @@ File-related utility functions.

Implements: `load_file`, `dump_file`, `load_json_file`,
`dump_json_file`, `get_parent_dir_path`, `get_dir_checksum`,
`get_file_checksum`, `load_raw_proffast_output`, `rel_to_abs_path`
`get_file_checksum`, `load_raw_proffast_output`, `rel_to_abs_path`.

`load_raw_proffast_output` is deprecated and will be removed in the
next breaking release.


##### `get_parent_dir_path`
Expand Down Expand Up @@ -216,6 +235,9 @@ not spawn a new process.
##### `load_raw_proffast_output`

```python
@deprecated(
"Will be removed in the next breaking release. We will move this functionality into a separate library. The reason for this is that this function is the reason why the utils package requires `polars` which is still at release `0.X`. This results in frequent version conflicts."
)
def load_raw_proffast_output(
path: str,
selected_columns: list[str] = [
Expand Down Expand Up @@ -310,6 +332,18 @@ Sends a request and returns the content of the response,
as a string. Raises an HTTPError if the response status code
is not 200.

**Arguments**:

- `github_repository` - In the format "owner/repo".
- `filepath` - The path to the file in the repository.
- `access_token` - The GitHub access token. Only required if
the repo is private.


**Returns**:

The content of the file as a string.


## `tum_esm_utils.interferograms`

Expand Down Expand Up @@ -670,6 +704,7 @@ Returns `True` if string is in a valid `YYYYMMDD` format
##### `date_range`

```python
@deprecated("Use `timing.date_range` instead")
def date_range(from_date_string: str, to_date_string: str) -> list[str]
```

Expand All @@ -686,6 +721,7 @@ date_range("20210101", "20210103") == ["20210101", "20210102", "20210103"]
##### `is_datetime_string`

```python
@deprecated("Will be removed in the next breaking release")
def is_datetime_string(datetime_string: str) -> bool
```

Expand All @@ -705,6 +741,7 @@ format. Caution: The appendix of `+00:00` is required for UTC!
##### `date_is_too_recent`

```python
@deprecated("Will be removed in the next breaking release")
def date_is_too_recent(date_string: str, min_days_delay: int = 1) -> bool
```

Expand Down Expand Up @@ -805,17 +842,19 @@ parse_timezone_string("UTC+2.0") # returns 2
parse_timezone_string("UTC-02:00") # returns -2
```

You are required to pass a datetime object in can the utc offset for the
You are required to pass a datetime object in case the utc offset for the
passed timezone is not constant - e.g. for "Europe/Berlin".


## `tum_esm_utils.validators`

Implements validator functions for use with pydantic models.

Implements: `validate_bool`, `validate_float`, `validate_int`,
`validate_str`, `validate_list`, `StrictFilePath`,
`StrictDirectoryPath`.
Implements: `StrictFilePath`, `StrictDirectoryPath`.

Also implements `validate_bool`, `validate_float`, `validate_int`,
`validate_str`, `validate_list` but these are deprecated and will
be removed in the next breaking release.


## `StrictFilePath` Objects
Expand Down
31 changes: 14 additions & 17 deletions tum_esm_utils/context.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
"""Context managers for common tasks.
Implements: `ensure_section_duration`, `set_alarm`, `clear_alarm`."""
Implements: `ensure_section_duration`, `set_alarm`, `clear_alarm`.
All functions in this module are deprecated and will be removed in the
next breaking release. Use the functions from the `timing` module instead."""

from typing import Generator
from typing_extensions import deprecated
import contextlib
import warnings
from . import timing


@deprecated(
"Will be removed in the next breaking release. Use `timing.ensure_section_duration` instead."
)
@contextlib.contextmanager
def ensure_section_duration(duration: float) -> Generator[None, None, None]:
"""Make sure that the duration of the section is at least the given duration.
Expand All @@ -20,34 +26,25 @@ def ensure_section_duration(duration: float) -> Generator[None, None, None]:
```
"""

warnings.warn(
"`context.ensure_section_duration` is deprecated, " +
"use `timing.ensure_section_duration` instead",
DeprecationWarning,
)
with timing.ensure_section_duration(duration):
yield


@deprecated(
"Will be removed in the next breaking release. Use `timing.set_alarm` instead."
)
def set_alarm(timeout: int, label: str) -> None:
"""Set an alarm that will raise a `TimeoutError` after
`timeout` seconds. The message will be formatted as
`{label} took too long (timed out after {timeout} seconds)`."""

warnings.warn(
"`context.set_alarm` is deprecated, " +
"use `timing.set_alarm` instead",
DeprecationWarning,
)
timing.set_alarm(timeout, label)


@deprecated(
"Will be removed in the next breaking release. Use `timing.clear_alarm` instead."
)
def clear_alarm() -> None:
"""Clear the alarm set by `set_alarm`."""

warnings.warn(
"`context.clear_alarm` is deprecated, " +
"use `timing.clear_alarm` instead",
DeprecationWarning,
)
timing.clear_alarm()
11 changes: 6 additions & 5 deletions tum_esm_utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
import filelock
import functools

# typing of higher level decorators:
# https://github.com/python/mypy/issues/1551#issuecomment-253978622
F = TypeVar("F", bound=Callable[..., Any])


class with_filelock:
"""
FileLock = Mark, that a file is being used and other programs
"""FileLock = Mark, that a file is being used and other programs
should not interfere. A file "*.lock" will be created and the
content of this file will make the wrapped function possibly
wait until other programs are done using it.
See https://en.wikipedia.org/wiki/Semaphore_(programming)
See https://en.wikipedia.org/wiki/Semaphore_(programming).
Credits for the typing of higher level decorators goes to
https://github.com/python/mypy/issues/1551#issuecomment-253978622.
"""
def __init__(self, lockfile_path: str, timeout: float = -1) -> None:
"""A timeout of -1 means that the code waits forever."""
Expand Down
11 changes: 9 additions & 2 deletions tum_esm_utils/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
Implements: `load_file`, `dump_file`, `load_json_file`,
`dump_json_file`, `get_parent_dir_path`, `get_dir_checksum`,
`get_file_checksum`, `load_raw_proffast_output`, `rel_to_abs_path`"""
`get_file_checksum`, `load_raw_proffast_output`, `rel_to_abs_path`.
`load_raw_proffast_output` is deprecated and will be removed in the
next breaking release."""

from __future__ import annotations
import traceback
from typing import Any, List, Optional
from typing_extensions import deprecated
import traceback
import hashlib
import json
import os
Expand Down Expand Up @@ -66,6 +70,9 @@ def get_file_checksum(path: str) -> str:
return hashlib.md5(f.read()).hexdigest()


@deprecated(
"Will be removed in the next breaking release. We will move this functionality into a separate library. The reason for this is that this function is the reason why the utils package requires `polars` which is still at release `0.X`. This results in frequent version conflicts."
)
def load_raw_proffast_output(
path: str,
selected_columns: list[str] = [
Expand Down
15 changes: 14 additions & 1 deletion tum_esm_utils/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ def request_github_file(
) -> str:
"""Sends a request and returns the content of the response,
as a string. Raises an HTTPError if the response status code
is not 200."""
is not 200.
Args:
github_repository: In the format "owner/repo".
filepath: The path to the file in the repository.
access_token: The GitHub access token. Only required if
the repo is private.
Returns:
The content of the file as a string.
"""

response = requests.get(
f"https://raw.githubusercontent.com/{github_repository}/main/{filepath}",
Expand All @@ -25,3 +35,6 @@ def request_github_file(
)
response.raise_for_status()
return response.text


# TODO: add "request gitlab file"
4 changes: 4 additions & 0 deletions tum_esm_utils/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import sys
import traceback
import datetime
from typing_extensions import deprecated
import filelock


Expand Down Expand Up @@ -204,6 +205,9 @@ def _write_log_line(
if (now - Logger.last_archive_time).total_seconds() > 600:
self._archive()

@deprecated(
"Will be removed in the next breaking release. The logger will write into the archive by default and optionally keep a separate log file containing the latest x minutes. This makes the archive parsing logic redundant."
)
def _archive(self) -> None:
"""moves old log lines in "logs/current-logs.log" into an
archive file "logs/archive/YYYYMMDD.log". log lines from
Expand Down
4 changes: 4 additions & 0 deletions tum_esm_utils/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import datetime
import random
import string
from typing_extensions import deprecated
import warnings
from . import timing

Expand Down Expand Up @@ -47,6 +48,7 @@ def is_date_string(date_string: str) -> bool:
return False


@deprecated("Use `timing.date_range` instead")
def date_range(from_date_string: str, to_date_string: str) -> list[str]:
"""Returns a list of dates between `from_date_string` and `to_date_string`.
Expand All @@ -71,6 +73,7 @@ def date_range(from_date_string: str, to_date_string: str) -> list[str]:
return [d.strftime("%Y%m%d") for d in timing.date_range(from_date, to_date)]


@deprecated("Will be removed in the next breaking release")
def is_datetime_string(datetime_string: str) -> bool:
"""Returns `True` if string is in a valid `YYYYMMDD HH:mm:ss` format"""

Expand Down Expand Up @@ -98,6 +101,7 @@ def is_rfc3339_datetime_string(rfc3339_datetime_string: str) -> bool:
return False


@deprecated("Will be removed in the next breaking release")
def date_is_too_recent(
date_string: str,
min_days_delay: int = 1,
Expand Down
2 changes: 1 addition & 1 deletion tum_esm_utils/timing.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def parse_timezone_string(
parse_timezone_string("UTC-02:00") # returns -2
```
You are required to pass a datetime object in can the utc offset for the
You are required to pass a datetime object in case the utc offset for the
passed timezone is not constant - e.g. for "Europe/Berlin"."""

offset: float = 0
Expand Down
Loading

0 comments on commit 756a1f7

Please sign in to comment.