Skip to content

Commit

Permalink
solve circular import with __version__
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfidan committed Feb 22, 2024
1 parent 624048f commit 0bc6728
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 13 deletions.
10 changes: 1 addition & 9 deletions rainforest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
import importlib.metadata as _importlib_metadata

from . import qpe
from . import common
from . import database
from . import ml
from . import performance

# Get the version
try:
__version__ = _importlib_metadata.version("rainforest_mch")
except _importlib_metadata.PackageNotFoundError:
# package is not installed
__version__ = "0.0.0"

__version__ = common.utils.get_version()
12 changes: 12 additions & 0 deletions rainforest/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# Global imports
import datetime
import io
import importlib.metadata as _importlib_metadata
import os
from collections import OrderedDict
import numpy as np
Expand All @@ -22,11 +23,22 @@
import dask.dataframe as dd
import re
import numbers

# Local imports
from .logger import logger
from .wgs84_ch1903 import GPSConverter
from . import constants

def get_version():
# Get the version
try:
version = _importlib_metadata.version("rainforest_mch")
except _importlib_metadata.PackageNotFoundError:
# package is not installed
version = "0.0.0"
return version


def hex_to_rgb(value):
value = value.lstrip('#')
lv = len(value)
Expand Down
7 changes: 3 additions & 4 deletions rainforest/qpe/qpe.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from pathlib import Path
import os


from pathlib import Path
from scipy.ndimage import gaussian_filter
from scipy.signal import convolve2d
Expand All @@ -33,7 +32,7 @@
from pyart.aux_io.odim_h5_writer import write_odim_grid_h5
from pyart.aux_io.odim_h5 import proj4_to_dict

from .. import __version__
from ..common.utils import get_version
from ..common.logger import logger
from ..common import constants
from ..common.retrieve_data import retrieve_prod, get_COSMO_T, retrieve_hzt_prod, retrieve_prod_RT, retrieve_hzt_RT
Expand Down Expand Up @@ -160,7 +159,7 @@ def _features_to_chgrid(features, features_labels, time, missing_files):

grid.metadata['source'] = b'ORG:215, CTY:644, CMT:MeteoSwiss (Switzerland)'
grid.metadata['version'] = b'H5rad 2.3'
grid.metadata['sw_version'] = __version__
grid.metadata['sw_version'] = get_version()
# Add missing radar information
quality = 'ADLPW'
if len(missing_files) != 0:
Expand Down Expand Up @@ -227,7 +226,7 @@ def _qpe_to_chgrid(qpe, time, missing_files, precision=2):
grid.fields['radar_estimated_rain_rate']['prodname'] = 'CHRFO'
grid.metadata['source'] = b'ORG:215, CTY:644, CMT:MeteoSwiss (Switzerland)'
grid.metadata['version'] = b'H5rad 2.3'
grid.metadata['sw_version'] = __version__
grid.metadata['sw_version'] = get_version()
# Add missing radar information
quality = 'ADLPW'
if len(missing_files) != 0:
Expand Down

0 comments on commit 0bc6728

Please sign in to comment.