Skip to content

Commit

Permalink
Merge pull request #5 from ecmwf/feature/move_to_pyproject
Browse files Browse the repository at this point in the history
Move to pyproject toml
  • Loading branch information
dsarmany authored Oct 8, 2024
2 parents c0629cc + de461ca commit 59e363d
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 89 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/


_version.py
2 changes: 1 addition & 1 deletion example/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Optional
import numpy as np

from multiopython import Multio
from multio import Multio

dir = os.path.dirname(__file__)

Expand Down
11 changes: 11 additions & 0 deletions multio/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from .lib import MultioException # noqa: F401
from .metadata import Metadata # noqa: F401
from .multio import Multio # noqa: F401

try:
# NOTE: the `version.py` file must not be present in the git repository
# as it is generated by setuptools at install time
from ._version import __version__
except ImportError: # pragma: no cover
# Local copy or not installed with setuptools
__version__ = "999"
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 0 additions & 5 deletions multiopython/__init__.py

This file was deleted.

63 changes: 63 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,66 @@
# (C) Copyright 2024 ECMWF.
#
# 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" ]

[project]
name = "multio-python"

description = "A Python interface to multio."
keywords = [ "multio", "multiopython", "tools" ]

license = { file = "LICENSE" }
authors = [
{ name = "European Centre for Medium-Range Weather Forecasts (ECMWF)", email = "software.support@ecmwf.int" },
]

requires-python = ">=3.9"

classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Operating System :: OS Independent",
]

dynamic = [ "version" ]
dependencies = [
"cffi",
]

optional-dependencies.all = [ "multio-python" ]

optional-dependencies.tests = [ "pytest", "pytest-cov", "pytest-flakes" ]

urls.Homepage = "https://github.com/ecmwf/multio-python/"
urls.Issues = "https://github.com/ecmwf/multio-python/issues"
urls.Repository = "https://github.com/ecmwf/multio-python/"


[tool.setuptools]
include-package-data = true
zip-safe = true

[tool.setuptools_scm]
version_file = "multio/_version.py"

[tool.setuptools.package-data]
multio = ["*.h"]

[tool.black]
line-length = 120

Expand Down
61 changes: 2 additions & 59 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,60 +1,3 @@
import io
import os
import re
from setuptools import setup

import setuptools


def read(path):
file_path = os.path.join(os.path.dirname(__file__), *path.split("/"))
return io.open(file_path, encoding="utf-8").read()


# single-sourcing the package version using method 1 of:
# https://packaging.python.org/guides/single-sourcing-package-version/
def parse_version_from(path):
version_file = read(path)
version_match = re.search(r'^__version__ = "(.*)"', version_file, re.M)
if version_match is None or len(version_match.groups()) > 1:
raise ValueError("couldn't parse version")
return version_match.group(1)


setuptools.setup(
name="multiopython",
version=parse_version_from("multiopython/__init__.py"),
description="A Python interface to multio.",
long_description=read("README.md"),
long_description_content_type="text/markdown",
author="European Centre for Medium-Range Weather Forecasts (ECMWF)",
author_email="software.support@ecmwf.int",
license="Apache License Version 2.0",
url="https://github.com/ecmwf/multio",
packages=["multiopython"],
package_data={"": ["*.h"]},
include_package_data=True,
install_requires=[
"cffi",
],
extras_require={},
tests_require=[
"pytest",
"pytest-cov",
"pytest-flakes",
],
test_suite="tests",
zip_safe=True,
keywords="multio multiopython",
classifiers=[
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: Apache Software License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.5",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
"Operating System :: OS Independent",
],
)
setup()
48 changes: 24 additions & 24 deletions tests/test_multio_pythonapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import pytest

import multiopython
import multio

default_dict = {"allow_world": True, "parent_comm": 1, "client_comm": [2, 3], "server_comm": [4, 5]}

Expand Down Expand Up @@ -41,43 +41,43 @@


def test_initialisation():
multiopython.Multio(**default_dict)
multio.Multio(**default_dict)


def test_multio_version():
assert multiopython.Multio(**default_dict).__version__() == "2.2.0"
assert multio.Multio(**default_dict).__version__() == "2.2.0"


def test_initialisation_no_config():
multiopython.Multio()
multio.Multio()


def test_multio_wrong_config_path():
incorrect_path = "I_AM_NOT_HERE/multio/config/multio-server.yaml"
with pytest.raises(multiopython.MultioException):
multiopython.Multio(config_path=incorrect_path, **default_dict)
with pytest.raises(multio.MultioException):
multio.Multio(config_path=incorrect_path, **default_dict)


def test_multio_config_path():
config_path = "../../tests/multio/config/testPlan.yaml"
with pytest.raises(multiopython.MultioException):
multiopython.Multio(config_path=config_path, **default_dict)
with pytest.raises(multio.MultioException):
multio.Multio(config_path=config_path, **default_dict)


def test_multio_open_close_connections():
with multiopython.Multio(**default_dict):
with multio.Multio(**default_dict):
pass


def test_create_metadata():
multio = multiopython.Multio(**default_dict)
multioclient = multio.Multio(**default_dict)
metadata = {"category": "path", "new": 1, "new_float": 1.0, "trigger": "step", "step": 1}
metadata = multiopython.Metadata(multio, metadata)
metadata = multio.Metadata(multioclient, metadata)


def test_metadata_set_item_syntax():
multio = multiopython.Multio(**default_dict)
metadata = multiopython.Metadata(multio, None)
multioclient = multio.Multio(**default_dict)
metadata = multio.Metadata(multioclient, None)
metadata["category"] = "path"
metadata["new"] = 1
metadata["new_float"] = 1.0
Expand All @@ -86,25 +86,25 @@ def test_metadata_set_item_syntax():


def test_create_wrong_metadata_object():
multio = multiopython.Multio(**default_dict)
multioclient = multio.Multio(**default_dict)
metadata = {"category": "path", "new": 1, "new_float": 1.0, "trigger": "step", "step": 1, "pair": (1, 2)}
with pytest.raises(TypeError):
multiopython.Metadata(multio, metadata)
multio.Metadata(multioclient, metadata)


def test_create_wrong_metadata_dict():
multio = multiopython.Multio(**default_dict)
multioclient = multio.Multio(**default_dict)
metadata = {"category": "path", "new": 1, "new_float": 1.0, "trigger": "step", "step": 1, "pair": (1, 2)}
with pytest.raises(TypeError):
multio.write_field(metadata, np.array([1.0, 2.0, 3.0, 4.0]))
multioclient.write_field(metadata, np.array([1.0, 2.0, 3.0, 4.0]))


def test_write_field():
os.environ["MULTIO_PLANS"] = WRITE_FILE_PLAN
if os.path.isfile(TEST_WRITE_FILE):
os.remove(TEST_WRITE_FILE)
metadata = {"category": "path", "new": 1, "new_float": 1.0, "trigger": "step", "step": 1}
with multiopython.Multio(**default_dict) as multio_object:
with multio.Multio(**default_dict) as multio_object:
multio_object.write_field(metadata, np.array([1.0, 2.0, 3.0, 4.0]))
multio_object.flush(metadata)
multio_object.notify(metadata)
Expand All @@ -117,8 +117,8 @@ def test_write_field_use_metadata_object():

if os.path.isfile(TEST_WRITE_FILE):
os.remove(TEST_WRITE_FILE)
with multiopython.Multio(**default_dict) as multio_object:
metadata = multiopython.Metadata(multio_object, None)
with multio.Multio(**default_dict) as multio_object:
metadata = multio.Metadata(multio_object, None)
metadata["category"] = "path"
metadata["new"] = 1
metadata["new_float"] = 1.0
Expand All @@ -137,7 +137,7 @@ def test_write_no_metadata():

if os.path.isfile(TEST_WRITE_FILE):
os.remove(TEST_WRITE_FILE)
with multiopython.Multio(**default_dict) as multio_object:
with multio.Multio(**default_dict) as multio_object:
multio_object.write_field(None, np.array([1.0, 2.0, 3.0, 4.0]))
assert os.path.isfile(TEST_WRITE_FILE) is True
os.remove(TEST_WRITE_FILE)
Expand All @@ -149,7 +149,7 @@ def test_field_accepted():
if os.path.isfile(TEST_WRITE_FILE):
os.remove(TEST_WRITE_FILE)
metadata = {"category": "path", "new": 1, "new_float": 1.0, "trigger": "step", "step": 1}
with multiopython.Multio(**default_dict) as multio_object:
with multio.Multio(**default_dict) as multio_object:
multio_object.write_field(metadata, np.array([1.0, 2.0, 3.0, 4.0]))
multio_object.flush(metadata)
multio_object.notify(metadata)
Expand All @@ -166,7 +166,7 @@ def test_enter_exit_connections():
if os.path.isfile(TEST_WRITE_FILE):
os.remove(TEST_WRITE_FILE)
metadata = {"category": "path", "new": 1, "new_float": 1.0, "trigger": "step", "step": 1}
with multiopython.Multio(**default_dict) as multio_object:
with multio.Multio(**default_dict) as multio_object:
multio_object.write_field(metadata, np.array([1.0, 2.0, 3.0, 4.0]))
multio_object.flush(metadata)
multio_object.notify(metadata)
Expand All @@ -178,7 +178,7 @@ def test_combined():
os.environ["MULTIO_PLANS"] = NO_OP_PLAN

metadata = {"category": "custom", "new": 1, "new_float": 1.0, "trigger": "step", "step": 1}
with multiopython.Multio(**default_dict) as multio_object:
with multio.Multio(**default_dict) as multio_object:
multio_object.write_domain({"category": "domain"}, [1, 2, 3, 4])
multio_object.write_mask({"category": "mask"}, [1.0, 0.0, 1.0, 0.0])
multio_object.write_mask({"category": "mask"}, np.array([1.0, 0.0, 1.0, 0.0], dtype=np.float32))
Expand Down

0 comments on commit 59e363d

Please sign in to comment.