Skip to content

Commit

Permalink
Merge pull request #43 from ecmwf/develop
Browse files Browse the repository at this point in the history
release 0.4.5
  • Loading branch information
floriankrb authored Nov 6, 2024
2 parents 83d521e + 6de64e7 commit c113eb0
Show file tree
Hide file tree
Showing 23 changed files with 1,251 additions and 584 deletions.
36 changes: 18 additions & 18 deletions .github/workflows/changelog-pr-update.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name: Check Changelog Update on PR
on:
pull_request:
types: [assigned, opened, synchronize, reopened, labeled, unlabeled]
branches:
- main
- develop
paths-ignore:
- .pre-commit-config.yaml
- .readthedocs.yaml
jobs:
Check-Changelog:
name: Check Changelog Action
runs-on: ubuntu-20.04
steps:
- uses: tarides/changelog-check-action@v2
with:
changelog: CHANGELOG.md
# name: Check Changelog Update on PR
# on:
# pull_request:
# types: [assigned, opened, synchronize, reopened, labeled, unlabeled]
# branches:
# - main
# - develop
# paths-ignore:
# - .pre-commit-config.yaml
# - .readthedocs.yaml
# jobs:
# Check-Changelog:
# name: Check Changelog Action
# runs-on: ubuntu-20.04
# steps:
# - uses: tarides/changelog-check-action@v2
# with:
# changelog: CHANGELOG.md
1 change: 1 addition & 0 deletions .github/workflows/changelog-release-update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ jobs:
with:
latest-version: ${{ github.event.release.tag_name }}
heading-text: ${{ github.event.release.name }}
release-notes: ${{ github.event.release.body }}

- name: Create Pull Request
uses: peter-evans/create-pull-request@v6
Expand Down
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ repos:
- id: python-check-blanket-noqa # Check for # noqa: all
- id: python-no-log-warn # Check for log.warn
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.8.0
rev: 24.10.0
hooks:
- id: black
args: [--line-length=120]
Expand All @@ -40,7 +40,7 @@ repos:
- --force-single-line-imports
- --profile black
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.6.9
rev: v0.7.2
hooks:
- id: ruff
args:
Expand All @@ -65,7 +65,7 @@ repos:
- id: docconvert
args: ["numpy"]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "2.2.4"
rev: "v2.5.0"
hooks:
- id: pyproject-fmt
- repo: https://github.com/jshwi/docsig # Check docstrings against function sig
Expand Down
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
Please add your functional changes to the appropriate section in the PR.
Keep it human-readable, your future self will thank you!

## [Unreleased](https://github.com/ecmwf/anemoi-utils/compare/0.4.4...HEAD)

## [0.4.4](https://github.com/ecmwf/anemoi-utils/compare/0.4.3...0.4.4) - 2024-11-01

## [0.4.3](https://github.com/ecmwf/anemoi-utils/compare/0.4.1...0.4.3) - 2024-10-26

## [0.4.2](https://github.com/ecmwf/anemoi-utils/compare/0.4.1...0.4.2) - 2024-10-25

### Added

- Add supporting_arrays to checkpoints
- Add factories registry
- Optional renaming of subcommands via `command` attribute [#34](https://github.com/ecmwf/anemoi-utils/pull/34)
Expand Down Expand Up @@ -53,7 +50,9 @@ Keep it human-readable, your future self will thank you!
- Changelog merge strategy- Codeowners file
- Create dependency on wcwidth. MIT licence.
- Add distribution name dictionary to provenance [#15](https://github.com/ecmwf/anemoi-utils/pull/15) & [#19](https://github.com/ecmwf/anemoi-utils/pull/19)
- Add anonimize() function.
- Add anonymize() function.
- Add transfer to ssh:// target (experimental)
- Deprecated 'anemoi.utils.s3'

### Changed

Expand Down
7 changes: 3 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
#!/usr/bin/env python
# (C) Copyright 2024 ECMWF.
# (C) Copyright 2024 Anemoi contributors.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

# https://packaging.python.org/en/latest/guides/writing-pyproject-toml/

[build-system]
requires = [ "setuptools>=60", "setuptools-scm>=8" ]

Expand All @@ -35,6 +33,7 @@ classifiers = [
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
Expand Down
5 changes: 2 additions & 3 deletions src/anemoi/utils/__main__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python
# (C) Copyright 2024 ECMWF.
# (C) Copyright 2024 Anemoi contributors.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#

from anemoi.utils.cli import cli_main
from anemoi.utils.cli import make_parser
Expand Down
4 changes: 2 additions & 2 deletions src/anemoi/utils/checkpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ def load_metadata(path: str, *, supporting_arrays=False, name: str = DEFAULT_NAM
with zipfile.ZipFile(path, "r") as f:
metadata = json.load(f.open(metadata, "r"))
if supporting_arrays:
metadata["supporting_arrays"] = load_supporting_arrays(f, metadata.get("supporting_arrays", {}))
return metadata, supporting_arrays
arrays = load_supporting_arrays(f, metadata.get("supporting_arrays_paths", {}))
return metadata, arrays

return metadata
else:
Expand Down
5 changes: 2 additions & 3 deletions src/anemoi/utils/commands/__init__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#!/usr/bin/env python
# (C) Copyright 2024 ECMWF.
# (C) Copyright 2024 Anemoi contributors.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
#

import os

Expand Down
1 change: 0 additions & 1 deletion src/anemoi/utils/commands/config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#!/usr/bin/env python3
# (C) Copyright 2024 Anemoi contributors.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
Expand Down
76 changes: 76 additions & 0 deletions src/anemoi/utils/compatibility.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# (C) Copyright 2024 Anemoi contributors.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.

from __future__ import annotations

import functools
from typing import Any
from typing import Callable


def aliases(
aliases: dict[str, str | list[str]] | None = None, **kwargs: str | list[str]
) -> Callable[[Callable], Callable]:
"""Alias keyword arguments in a function call.
Allows for dynamically renaming keyword arguments in a function call.
Parameters
----------
aliases : dict[str, str | list[str]] | None, optional
Key, value pair of aliases, with keys being the true name, and value being a str or list of aliases,
by default None
**kwargs : str | list[str]
Kwargs form of aliases
Returns
-------
Callable
Decorator function that renames keyword arguments in a function call.
Raises
------
ValueError
If the aliasing would result in duplicate keys.
Examples
--------
```python
@aliases(a="b", c=["d", "e"])
def func(a, c):
return a, c
func(a=1, c=2) # (1, 2)
func(b=1, d=2) # (1, 2)
```
"""

if aliases is None:
aliases = {}
aliases.update(kwargs)

aliases = {v: k for k, vs in aliases.items() for v in (vs if isinstance(vs, list) else [vs])}

def decorator(func: Callable) -> Callable:
@functools.wraps(func)
def wrapper(*args, **kwargs) -> Any:
keys = kwargs.keys()
for k in set(keys).intersection(set(aliases.keys())):
if aliases[k] in keys:
raise ValueError(
f"When aliasing {k} with {aliases[k]} duplicate keys were present. Cannot include both."
)
kwargs[aliases[k]] = kwargs.pop(k)

return func(*args, **kwargs)

return wrapper

return decorator
4 changes: 3 additions & 1 deletion src/anemoi/utils/mars/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# (C) Copyright 2024 European Centre for Medium-Range Weather Forecasts.
# (C) Copyright 2024 Anemoi contributors.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation
# nor does it submit to any jurisdiction.
Expand Down
33 changes: 32 additions & 1 deletion src/anemoi/utils/registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ def __call__(self, factory):
class Registry:
"""A registry of factories"""

def __init__(self, package):
def __init__(self, package, key="_type"):

self.package = package
self.registered = {}
self.kind = package.split(".")[-1]
self.key = key

def register(self, name: str, factory: callable = None):

Expand Down Expand Up @@ -86,6 +87,8 @@ def lookup(self, name: str) -> callable:
self.registered[name] = entry_point.load()

if name not in self.registered:
for e in self.registered:
LOG.info(f"Registered: {e}")
raise ValueError(f"Cannot load '{name}' from {self.package}")

return self.registered[name]
Expand All @@ -96,3 +99,31 @@ def create(self, name: str, *args, **kwargs):

def __call__(self, name: str, *args, **kwargs):
return self.create(name, *args, **kwargs)

def from_config(self, config, *args, **kwargs):
if isinstance(config, str):
config = {config: {}}

if not isinstance(config, dict):
raise ValueError(f"Invalid config: {config}")

if self.key in config:
config = config.copy()
key = config.pop(self.key)
return self.create(key, *args, **config, **kwargs)

if len(config) == 1:
key = list(config.keys())[0]
value = config[key]

if isinstance(value, dict):
return self.create(key, *args, **value, **kwargs)

if isinstance(value, list):
return self.create(key, *args, *value, **kwargs)

return self.create(key, *args, value, **kwargs)

raise ValueError(
f"Entry '{config}' must either be a string, a dictionray with a single entry, or a dictionary with a '{self.key}' key"
)
Loading

0 comments on commit c113eb0

Please sign in to comment.