Skip to content

Commit

Permalink
Merge branch 'develop' into feature/metrics-overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisspyB committed Nov 4, 2024
2 parents f8cc4af + 65d9010 commit f819698
Show file tree
Hide file tree
Showing 17 changed files with 385 additions and 218 deletions.
1 change: 0 additions & 1 deletion MANIFEST.in

This file was deleted.

5 changes: 0 additions & 5 deletions pygribjump/requirements.txt

This file was deleted.

1 change: 1 addition & 0 deletions pygribjump/src/pygribjump/VERSION
1 change: 1 addition & 0 deletions pygribjump/src/pygribjump/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from .pygribjump import *
from ._version import __version__
5 changes: 5 additions & 0 deletions pygribjump/src/pygribjump/_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from pathlib import Path
from .pygribjump import *

with open(Path(__file__).parent / "VERSION") as f:
__version__ = f.read().strip()
2 changes: 2 additions & 0 deletions pygribjump/src/pygribjump/gribjump_c.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,7 @@ int gribjump_axes_values(gj_axes_t* axes, const char* key, const char*** values_
int gribjump_delete_axes(gj_axes_t* axes);

int gribjump_initialise();
int gribjump_version_c(const char** version);
int gribjump_git_sha1_c(const char** sha1);

const char* gribjump_error_string(int err);
20 changes: 18 additions & 2 deletions pygribjump/src/pygribjump/pygribjump.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import cffi
import os
import findlibs
import warnings
from ._version import __version__

ffi = cffi.FFI()

Expand Down Expand Up @@ -44,8 +46,7 @@ def __init__(self):
self.__lib = ffi.dlopen(libName)

# All of the executable members of the CFFI-loaded library are functions in the GribJump
# C API. These should be wrapped with the correct error handling. Otherwise forward
# these on directly.
# C API. These should be wrapped with the correct error handling.

for f in dir(self.__lib):
try:
Expand All @@ -59,6 +60,14 @@ def __init__(self):
# Initialise the library, and set it up for python-appropriate behaviour
self.gribjump_initialise()

# Check versions
tmp_str = ffi.new('char**')
self.gribjump_version_c(tmp_str)
versionstr = ffi.string(tmp_str[0]).decode('utf-8')

if versionstr != __version__:
warnings.warn(f"GribJump library version {versionstr} does not match pygribjump version {__version__}")

def __read_header(self, hdr_path):
with open(hdr_path, 'r') as f:
return f.read()
Expand Down Expand Up @@ -349,3 +358,10 @@ def dic_to_request(dic):
# e.g. {"class":"od", "expver":"0001", "levtype":"pl"} -> "class=od,expver=0001,levtype=pl"
return ','.join(['='.join([k, v]) for k, v in dic.items()])

def version():
return __version__

def library_version():
tmp_str = ffi.new('char**')
lib.gribjump_version_c(tmp_str)
return ffi.string(tmp_str[0]).decode('utf-8')
5 changes: 5 additions & 0 deletions pygribjump/tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from importlib.metadata import version
import pygribjump

def test_version():
assert pygribjump.__version__ == version("pygribjump")
42 changes: 42 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,45 @@ addopts = "-vv -s"
testpaths = [
"pygribjump/tests"
]

# pyproject.toml

[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"

[project]
name = "pygribjump"
description = "Python interface to GribJump"
readme = "README.md"
requires-python = ">=3.8"
dynamic = ["version"]
authors = [
{ name = "ECMWF", email = "[email protected]" }
]
urls = { "Home" = "https://github.com/ecmwf/gribjump" }
dependencies = [
"cffi~=1.17",
"numpy~=2.1",
"pytest~=8.3",
"setuptools~=75.1",
"findlibs~=0.0.5",
]

[project.optional-dependencies]
dev = [
"pyyaml",
"pyfdb",
]

[tool.setuptools.dynamic]
version = { file = ["VERSION"] }

[tool.setuptools]
packages = ["pygribjump"]
package-dir = { "pygribjump" = "./pygribjump/src/pygribjump" }
include-package-data = true
zip-safe = false

[tool.setuptools.package-data]
"pygribjump" = ["VERSION", "pygribjump/src/pygribjump/gribjump_c.h"]
23 changes: 0 additions & 23 deletions setup.py

This file was deleted.

3 changes: 2 additions & 1 deletion src/gribjump/Config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ Config::Config() {

Config::Config(const eckit::PathName path) :
eckit::LocalConfiguration(eckit::YAMLConfiguration(path)),
serverMap_{loadServerMap()} {
serverMap_{loadServerMap()},
path_{path} {
}

std::map<std::string, std::string> Config::loadServerMap() const {
Expand Down
4 changes: 4 additions & 0 deletions src/gribjump/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ class Config : public eckit::LocalConfiguration {
Config(const eckit::PathName);

const std::map<std::string, std::string>& serverMap() const { return serverMap_; }

///@note : Will be empty if default config is used
const std::string& path() const { return path_; }

private:
std::map<std::string, std::string> loadServerMap() const;

private:
std::map<std::string, std::string> serverMap_;
std::string path_;
};

} // namespace gribjump
3 changes: 1 addition & 2 deletions src/gribjump/LibGribJump.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ class LibGribJump : public eckit::system::Plugin {

const Config& config();

protected:
virtual std::string version() const override;

virtual std::string gitsha1(unsigned int count) const override;
virtual std::string gitsha1(unsigned int count=40u) const override;

private:
Config loadConfig();
Expand Down
Loading

0 comments on commit f819698

Please sign in to comment.