From 12d54f709ca9d2325934ceb5dc7f4b77f57c999e Mon Sep 17 00:00:00 2001 From: RoryPTB <47696929+RoryPTB@users.noreply.github.com> Date: Fri, 8 Mar 2024 11:11:46 +0100 Subject: [PATCH 1/4] Update tests.yml --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2009b02..445dede 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -32,7 +32,7 @@ jobs: pip3 install https://github.com/wmo-im/csv2bufr/archive/master.zip pip3 install -r requirements.txt pip3 install -r requirements-dev.txt - pip3 install --no-cache-dir https://github.com/wmo-im/pymetdecoder/archive/refs/tags/v0.1.1.zip + pip3 install --no-cache-dir https://github.com/wmo-im/pymetdecoder/archive/refs/tags/v0.1.11.zip python3 setup.py install - name: run tests ⚙️ run: | From cd8ede611885126e88550d8acd5835b1bd1029b9 Mon Sep 17 00:00:00 2001 From: RoryPTB <47696929+RoryPTB@users.noreply.github.com> Date: Thu, 14 Mar 2024 10:51:53 +0100 Subject: [PATCH 2/4] Truncation of station name to 20 chars + updated version no --- .github/workflows/tests.yml | 3 +-- synop2bufr/__init__.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 445dede..c531e8b 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -31,8 +31,7 @@ jobs: python3 -m pip install --upgrade pip pip3 install https://github.com/wmo-im/csv2bufr/archive/master.zip pip3 install -r requirements.txt - pip3 install -r requirements-dev.txt - pip3 install --no-cache-dir https://github.com/wmo-im/pymetdecoder/archive/refs/tags/v0.1.11.zip + pip3 install -r requirements-dev.txt python3 setup.py install - name: run tests ⚙️ run: | diff --git a/synop2bufr/__init__.py b/synop2bufr/__init__.py index a68c370..19d4b69 100644 --- a/synop2bufr/__init__.py +++ b/synop2bufr/__init__.py @@ -33,7 +33,7 @@ from pymetdecoder import synop from csv2bufr import BUFRMessage -__version__ = '0.6.2' +__version__ = '0.7.0_dev' LOGGER = logging.getLogger(__name__) @@ -1484,13 +1484,28 @@ def transform(data: str, metadata: str, year: int, warning_msgs = [] error_msgs = [] continue + + def truncate_to_twenty(name: str) -> str: + """ + Ensures the string is no longer than 20 characters, + which is the maximum length allowed for the station name + in the BUFR template. + + Args: + name (str): The station or site name. + + Returns: + str: This name truncated to 20 characters. + """ + return name[:20] # parse WSI to get sections try: wsi_series, wsi_issuer, wsi_issue_number, wsi_local = wsi.split("-") # noqa # get other required metadata - station_name = metadata_dict[wsi]["station_name"] + station_name = truncate_to_twenty( + metadata_dict[wsi]["station_name"]) latitude = metadata_dict[wsi]["latitude"] longitude = metadata_dict[wsi]["longitude"] station_height = metadata_dict[wsi]["elevation"] From 8169745bffe87a588884c8434f120ed764da6181 Mon Sep 17 00:00:00 2001 From: RoryPTB <47696929+RoryPTB@users.noreply.github.com> Date: Thu, 14 Mar 2024 11:02:46 +0100 Subject: [PATCH 3/4] Removed redundant Docker image test files --- .github/workflows/dhcr.yml | 68 -------------------------------------- .github/workflows/ghcr.yml | 54 ------------------------------ synop2bufr/__init__.py | 3 +- 3 files changed, 2 insertions(+), 123 deletions(-) delete mode 100644 .github/workflows/dhcr.yml delete mode 100644 .github/workflows/ghcr.yml diff --git a/.github/workflows/dhcr.yml b/.github/workflows/dhcr.yml deleted file mode 100644 index b63375d..0000000 --- a/.github/workflows/dhcr.yml +++ /dev/null @@ -1,68 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: publish images - -on: - push: - branches: - - main - release: - types: [published] - -env: - DOCKER_ORG: wmoim - -jobs: - # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ - push: - runs-on: ubuntu-latest - permissions: - packages: write - contents: read - strategy: - matrix: - image: - - synop2bufr - - steps: - - name: Checkout branch - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Log in to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_TOKEN }} - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v1 - - - name: Docker meta - id: metadata - uses: docker/metadata-action@v4 - with: - images: | - ${{ env.DOCKER_ORG }}/${{ matrix.image }} - tags: | - type=raw,value=latest,enable={{is_default_branch}} - type=pep440,pattern={{version}} - - - name: Build and push - uses: docker/build-push-action@v2.7.0 - with: - context: . - file: Dockerfile - cache-from: type=gha - cache-to: type=gha,mode=max - platforms: linux/arm64, linux/amd64 - push: true - tags: ${{ steps.metadata.outputs.tags }} - labels: ${{ steps.metadata.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/ghcr.yml b/.github/workflows/ghcr.yml deleted file mode 100644 index 1f784a5..0000000 --- a/.github/workflows/ghcr.yml +++ /dev/null @@ -1,54 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Create and publish image to GitHub Container Registry - -on: - push: - branches: - - main - -env: - REGISTRY: ghcr.io - IMAGE_NAME: synop2bufr - -jobs: - # Push image to GitHub Packages. - # See also https://docs.docker.com/docker-hub/builds/ - push: - runs-on: ubuntu-latest - permissions: - packages: write - contents: read - - steps: - - uses: actions/checkout@v2 - - - name: Build image - run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" - - - name: Log in to registry - # This is where you will update the PAT to GHCR_BUILD_TOKEN - run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.repository_owner }} --password-stdin - - - name: Rename image for publication - run: | - IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME - - # Change all uppercase to lowercase - IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') - # Strip git ref prefix from version - VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,') - # Strip "v" prefix from tag name - [[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//') - # Use Docker `latest` tag convention - [ "$VERSION" == "main" ] && VERSION=latest - echo IMAGE_ID=$IMAGE_ID - echo VERSION=$VERSION - echo FULLCONTAINERNAME=$IMAGE_ID:$VERSION >> $GITHUB_ENV - docker tag $IMAGE_NAME $IMAGE_ID:$VERSION - - - name: Push to CR - run: docker push ${{ env.FULLCONTAINERNAME }} diff --git a/synop2bufr/__init__.py b/synop2bufr/__init__.py index 19d4b69..51f5f37 100644 --- a/synop2bufr/__init__.py +++ b/synop2bufr/__init__.py @@ -1484,7 +1484,7 @@ def transform(data: str, metadata: str, year: int, warning_msgs = [] error_msgs = [] continue - + def truncate_to_twenty(name: str) -> str: """ Ensures the string is no longer than 20 characters, @@ -1497,6 +1497,7 @@ def truncate_to_twenty(name: str) -> str: Returns: str: This name truncated to 20 characters. """ + LOGGER.info(f"Truncating station name {name} to 20 characters") return name[:20] # parse WSI to get sections From 85e9572d9d325732a513a8d2a46c7cb4f2ddcac4 Mon Sep 17 00:00:00 2001 From: RoryPTB <47696929+RoryPTB@users.noreply.github.com> Date: Thu, 14 Mar 2024 11:17:41 +0100 Subject: [PATCH 4/4] Added name length check --- synop2bufr/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/synop2bufr/__init__.py b/synop2bufr/__init__.py index 51f5f37..16a2902 100644 --- a/synop2bufr/__init__.py +++ b/synop2bufr/__init__.py @@ -1497,6 +1497,8 @@ def truncate_to_twenty(name: str) -> str: Returns: str: This name truncated to 20 characters. """ + if len(name) <= 20: + return name LOGGER.info(f"Truncating station name {name} to 20 characters") return name[:20]