Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New get latest path #107

Merged
merged 20 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*.xlsx
*.zip

# Notebooks shall be stored in .py or .R-format.
# See https://adr.ssb.no/0020-lagringsformat-for-jupyter-notebooks/
*.ipynb


# The section below is from the GitHub .gitignore template for Python:
# https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore

Expand Down Expand Up @@ -208,6 +213,3 @@ rsconnect/
# Blaise specific ignores
*.bdix
*.bdbx

# PyCharm
.idea/
75 changes: 75 additions & 0 deletions demos/versions_dapla.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# ---
# jupyter:
# jupytext:
# text_representation:
# extension: .py
# format_name: percent
# format_version: '1.3'
# jupytext_version: 1.16.4
# kernelspec:
# display_name: ssb-fagfunksjoner
# language: python
# name: ssb-fagfunksjoner
# ---

# %%
import dapla as dp


fs = dp.FileClient().get_gcs_file_system()

# %%
base_path = "ssb-dapla-felles-data-produkt-prod"
folder_name = "versions_paths_fagfunksjoner"

# %% [markdown]
# # Make testfiles

# %%
testfile_paths = [
"file_v1.parquet",
"file_v2.parquet",
"file_v11.parquet",
"otherfile_v3.parquet",
"otherfile_v20.parquet",
]

# %%
for file in testfile_paths:
fs.touch("/".join([base_path, folder_name, file]))

# %% [markdown]
# # Test functions

# %%
from fagfunksjoner.paths import versions


# %%
files = fs.glob(f"{base_path}/{folder_name}/*.parquet")
files # noqa: B018

# %%
versions.get_latest_fileversions(files)

# %%
versions.next_version_path(
"/buckets/produkt/versions_paths_fagfunksjoner/file_v1.parquet"
)

# %%
versions.next_version_path(
"gs://ssb-dapla-felles-data-produkt-prod/versions_paths_fagfunksjoner/file_v1.parquet"
)

# %%
versions.latest_version_number(
"ssb-dapla-felles-data-produkt-prod/versions_paths_fagfunksjoner/file_v1.parquet"
)

# %%
versions.next_version_path(
"ssb-dapla-felles-data-produkt-prod/versions_paths_fagfunksjoner/dont_exist_v1.parquet"
)

# %%
11 changes: 11 additions & 0 deletions src/fagfunksjoner/fagfunksjoner_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,22 @@

import logging
import sys
from collections.abc import Callable
from typing import Any

from colorama import Back, Fore, Style


def silence_logger(func: Callable[..., Any], *args: Any, **kwargs: Any) -> Any:
"""Silences INFO and WARNING logs for the duration of the function call."""
original_level = logger.level
logger.setLevel(logging.ERROR) # Suppress INFO and WARNING messages
try:
return func(*args, **kwargs)
finally:
logger.setLevel(original_level) # Restore original logging level


class ColoredFormatter(logging.Formatter):
"""Colored log formatter."""

Expand Down
Loading