From 8cfcdb24b80de35f89a78916beadce03b469a71a Mon Sep 17 00:00:00 2001 From: RoryPTB <47696929+RoryPTB@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:23:44 +0100 Subject: [PATCH] Changed env var warning to info + using PyPI csv2bufr --- README.md | 2 +- requirements.txt | 2 +- setup.py | 4 ---- synop2bufr/__init__.py | 28 +++++++++++++++------------- tests/test_synop2bufr.py | 2 +- 5 files changed, 18 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 4cabb81..396cf3c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Dependencies are listed in [requirements.txt](https://github.com/wmo-im/synop2bu ### Setting Environment Variables -Before using synop2bufr, we highly encourage you to set the `BUFR_ORIGINATING_CENTRE` and `BUFR_ORIGINATING_SUBCENTRE` environment variables. These variables are used to specify the originating centre and subcentre of the SYNOP messages. **Without these set, they will default to missing (255).** +Before using synop2bufr, we highly encourage you to set the `BUFR_ORIGINATING_CENTRE` and `BUFR_ORIGINATING_SUBCENTRE` environment variables. These variables are used to specify the originating centre and subcentre of the SYNOP messages. **Without these set, they will default to missing (65535).** You can set these environment variables in your shell if you want to run synop2bufr on your local machine. Here's how you can do it in a Bash shell: diff --git a/requirements.txt b/requirements.txt index d19c2c5..a2c9882 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,3 @@ click pymetdecoder-wmo -csv2bufr @ git+https://github.com/wmo-im/csv2bufr.git \ No newline at end of file +csv2bufr \ No newline at end of file diff --git a/setup.py b/setup.py index 8486b23..614a0ae 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,6 @@ import os import re from setuptools import Command, find_packages, setup -import subprocess class PyTest(Command): @@ -74,9 +73,6 @@ def get_package_version(): if (os.path.exists('MANIFEST')): os.unlink('MANIFEST') -# Install dependencies not on PyPI -subprocess.check_call("pip install https://github.com/wmo-im/csv2bufr/archive/main.zip", shell=True) # noqa - setup( name='synop2bufr', version=get_package_version(), diff --git a/synop2bufr/__init__.py b/synop2bufr/__init__.py index 16a2902..5691918 100644 --- a/synop2bufr/__init__.py +++ b/synop2bufr/__init__.py @@ -1293,7 +1293,7 @@ def transform(data: str, metadata: str, year: int, # each report necessitates this approach, because # we want to ensure the warning is only appended # to the first conversion - can_var_warning_be_displayed = True + can_var_info_be_displayed = True # =================== # First parse metadata file @@ -1544,34 +1544,36 @@ def truncate_to_twenty(name: str) -> str: # and subcentre codes are present missing_env_vars = [] - if os.environ.get("BUFR_ORIGINATING_CENTRE") is None: + ORIGINATING_CENTRE = os.environ.get("BUFR_ORIGINATING_CENTRE", 65535) # noqa + ORIGINATING_SUBCENTRE = os.environ.get("BUFR_ORIGINATING_SUBCENTRE", 65535) # noqa + + if ORIGINATING_CENTRE == 65535: missing_env_vars.append("BUFR_ORIGINATING_CENTRE") else: # Add the BUFR header centre and subcentre to mappings mapping["header"].append({ "eccodes_key": "bufrHeaderCentre", - "value": f"const:{os.environ.get('BUFR_ORIGINATING_CENTRE')}" # noqa + "value": f"const:{ORIGINATING_CENTRE}" # noqa }) - if os.environ.get("BUFR_ORIGINATING_SUBCENTRE") is None: + if ORIGINATING_SUBCENTRE == 65535: missing_env_vars.append("BUFR_ORIGINATING_SUBCENTRE") else: mapping["header"].append({ "eccodes_key": "bufrHeaderSubCentre", - "value": f"const:{os.environ.get('BUFR_ORIGINATING_SUBCENTRE')}" # noqa + "value": f"const:{ORIGINATING_SUBCENTRE}" # noqa }) # If either of these environment variables are not set, - # we will default to missing and warn the user once - if missing_env_vars and can_var_warning_be_displayed: - # Display ewarning messages + # we will default to missing and inform the user once + if missing_env_vars and can_var_info_be_displayed: + # Display info messages for var in missing_env_vars: - var_warning = f"The {var} environment variable is not set, will default to missing!" # noqa - LOGGER.warning(var_warning) - warning_msgs.append(var_warning) - can_var_warning_be_displayed = False + var_info = f"The {var} environment variable is not set, will default to missing!" # noqa + LOGGER.info(var_info) + can_var_info_be_displayed = False # Stop duplicated warnings - can_var_warning_be_displayed = False + can_var_info_be_displayed = False # Define a new method which handles the updating of # the mapping file with section 3 and 4 cloud data diff --git a/tests/test_synop2bufr.py b/tests/test_synop2bufr.py index d0d633f..b6ab9bf 100644 --- a/tests/test_synop2bufr.py +++ b/tests/test_synop2bufr.py @@ -48,7 +48,7 @@ def multiple_reports_307096(): def single_report(): return """AAXX 21121 15001 05515 32931 10103 21090 39765 42250 57020 60071 72006 82110 91155 - 333 10178 21073 34101 55055 00010 20003 30002 50001 60004 + 222// 06070 20502 333 10178 21073 34101 55055 00010 20003 30002 50001 60004 60035 70500 83145 81533 91008 91111 444 18031 22053 """