Skip to content

Commit

Permalink
Merge pull request #1063 from metno/remove-entry-points
Browse files Browse the repository at this point in the history
move readers on plugins to io and remove extension entry points
  • Loading branch information
heikoklein authored Mar 19, 2024
2 parents 98de116 + 48abf73 commit 783dae1
Show file tree
Hide file tree
Showing 44 changed files with 44 additions and 56 deletions.
7 changes: 2 additions & 5 deletions pyaerocom/colocation_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import os
import traceback
from datetime import datetime
from importlib import metadata
from pathlib import Path
from typing import Optional

Expand All @@ -33,6 +32,7 @@
)
from pyaerocom.io import ReadGridded, ReadUngridded
from pyaerocom.io.helpers import get_all_supported_ids_ungridded
from pyaerocom.io.mscw_ctm.reader import ReadMscwCtm
from pyaerocom.io.pyaro.pyaro_config import PyaroConfig

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -548,10 +548,7 @@ class Colocator(ColocationSetup):
as such. For setup attributes, please see base class.
"""

SUPPORTED_GRIDDED_READERS = {"ReadGridded": ReadGridded}
SUPPORTED_GRIDDED_READERS.update(
{ep.name: ep.load() for ep in metadata.entry_points(group="pyaerocom.gridded")}
)
SUPPORTED_GRIDDED_READERS = {"ReadGridded": ReadGridded, "ReadMscwCtm": ReadMscwCtm}

STATUS_CODES = {
1: "SUCCESS",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import xarray as xr

from pyaerocom import const
from pyaerocom.plugins.mep.reader import ReadMEP
from pyaerocom.io.mep.reader import ReadMEP
from pyaerocom.stationdata import StationData
from pyaerocom.ungriddeddata import UngriddedData

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

from pyaerocom import const
from pyaerocom._lowlevel_helpers import BrowseDict
from pyaerocom.io.icpforests.metadata import MetadataReader, Station, SurveyYear
from pyaerocom.io.readungriddedbase import ReadUngriddedBase
from pyaerocom.plugins.icpforests.metadata import MetadataReader, Station, SurveyYear
from pyaerocom.stationdata import StationData
from pyaerocom.ungriddeddata import UngriddedData

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
38 changes: 25 additions & 13 deletions pyaerocom/io/readungridded.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import warnings
from copy import deepcopy
from importlib import metadata
from pathlib import Path
from typing import Optional, Union

Expand All @@ -12,6 +11,11 @@
from pyaerocom.helpers import varlist_aerocom
from pyaerocom.io import ReadUngriddedBase
from pyaerocom.io.cachehandler_ungridded import CacheHandlerUngridded
from pyaerocom.io.gaw.reader import ReadGAW
from pyaerocom.io.ghost.reader import ReadGhost
from pyaerocom.io.icos.reader import ReadICOS
from pyaerocom.io.icpforests.reader import ReadICPForest
from pyaerocom.io.mep.reader import ReadMEP
from pyaerocom.io.pyaro.pyaro_config import PyaroConfig
from pyaerocom.io.pyaro.read_pyaro import ReadPyaro
from pyaerocom.io.read_aasetal import ReadAasEtal
Expand All @@ -26,7 +30,6 @@
from pyaerocom.io.read_ebas import ReadEbas
from pyaerocom.io.read_eea_aqerep import ReadEEAAQEREP
from pyaerocom.io.read_eea_aqerep_v2 import ReadEEAAQEREP_V2
from pyaerocom.plugins.icpforests.reader import ReadICPForest
from pyaerocom.ungriddeddata import UngriddedData
from pyaerocom.variable import get_aliases

Expand Down Expand Up @@ -61,11 +64,12 @@ class ReadUngridded:
ReadAirNow,
ReadEEAAQEREP,
ReadEEAAQEREP_V2,
ReadGAW,
ReadGhost,
ReadMEP,
ReadICOS,
ReadICPForest,
]
SUPPORTED_READERS.extend(
ep.load() for ep in metadata.entry_points(group="pyaerocom.ungridded")
)

# Creates list of all readers excluding ReadPyaro
INCLUDED_READERS = deepcopy(SUPPORTED_READERS)
Expand Down Expand Up @@ -266,7 +270,7 @@ def get_reader(self, data_id):
)
return self.get_lowlevel_reader(data_id)

def get_lowlevel_reader(self, data_id=None):
def get_lowlevel_reader(self, data_id: str | None = None) -> ReadUngriddedBase:
"""Helper method that returns initiated reader class for input ID
Parameters
Expand All @@ -284,16 +288,16 @@ class :class:`ReadUngriddedBase`).
if data_id is None:
if len(self.data_ids) != 1:
raise ValueError("Please specify dataset")
if not data_id in self.supported_datasets:
if data_id not in self.supported_datasets:
if data_id not in self.config_map:
raise NetworkNotSupported(
f"Could not fetch reader class: Input "
f"network {data_id} is not supported by "
f"ReadUngridded"
)
elif not data_id in self.data_ids:
elif data_id not in self.data_ids:
self.data_ids.append(data_id)
if not data_id in self._readers:
if data_id not in self._readers:
_cls = self._find_read_class(data_id)
reader = self._init_lowlevel_reader(_cls, data_id)
self._readers[data_id] = reader
Expand Down Expand Up @@ -880,7 +884,15 @@ def get_vars_supported(self, obs_id, vars_desired): # , config: Optional[PyaroC
return obs_vars

def __str__(self):
s = ""
for ds in self.data_ids:
s += f"\n{self.get_lowlevel_reader(ds)}"
return s
return "\n".join(str(self.get_lowlevel_reader(ds)) for ds in self.data_ids)

def __str__(self):
return "\n".join(str(self.get_lowlevel_reader(ds)) for ds in self.data_ids)
return "\n".join(str(self.get_lowlevel_reader(ds)) for ds in self.data_ids)

def __str__(self):
return "\n".join(str(self.get_lowlevel_reader(ds)) for ds in self.data_ids)
return "\n".join(str(self.get_lowlevel_reader(ds)) for ds in self.data_ids)

def __str__(self):
return "\n".join(str(self.get_lowlevel_reader(ds)) for ds in self.data_ids)
9 changes: 0 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ dev = ["pytest-sugar", "pytest-xdist", "pre-commit"]
[project.scripts]
pya = "pyaerocom.scripts.cli:main"

[project.entry-points."pyaerocom.gridded"]
ReadMscwCtm = "pyaerocom.plugins.mscw_ctm.reader:ReadMscwCtm"

[project.entry-points."pyaerocom.ungridded"]
ReadGAW = "pyaerocom.plugins.gaw.reader:ReadGAW"
ReadGhost = "pyaerocom.plugins.ghost.reader:ReadGhost"
ReadMEP = "pyaerocom.plugins.mep.reader:ReadMEP"
ReadICOS = "pyaerocom.plugins.icos.reader:ReadICOS"
ReadICPForest = "pyaerocom.plugins.icpforests.reader:ReadICPForest"

[tool.flit.sdist]
include = ["LICENSE", "README.*", "pyaerocom_env.yml", "tests"]
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/data_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import pooch

from pyaerocom import const, io
from pyaerocom.io.ghost.reader import ReadGhost
from pyaerocom.io.icpforests.reader import ReadICPForest
from pyaerocom.io.readungriddedbase import ReadUngriddedBase
from pyaerocom.plugins.ghost.reader import ReadGhost
from pyaerocom.plugins.icpforests.reader import ReadICPForest

logger = logging.getLogger(__name__)

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/plugins/gaw/test_dms.py → tests/io/gaw/test_dms.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from numpy.testing import assert_allclose, assert_array_equal

from pyaerocom import const
from pyaerocom.plugins.gaw.reader import ReadGAW
from pyaerocom.io.gaw.reader import ReadGAW
from tests.conftest import TEST_RTOL


Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
THESE SHOULD BE ALWAYS THE SAME ACCORDING TO INFORMATION INFORMATION
PROVIDED BY BSC
"""
from pyaerocom.plugins.ghost.meta_keys import ghost_meta_keys

from pyaerocom.io.ghost.meta_keys import ghost_meta_keys

desired_keys = [
"EDGAR_v4.3.2_annual_average_BC_emissions",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import numpy as np
import pytest

from pyaerocom.plugins.ghost.reader import ReadGhost
from pyaerocom.io.ghost.reader import ReadGhost


@pytest.fixture(scope="module")
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from pyaerocom import const
from pyaerocom.plugins.icos.reader import ReadICOS
from pyaerocom.io.icos.reader import ReadICOS

if not const.has_access_lustre:
pytestmark = pytest.skip(
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import pytest

from pyaerocom import const
from pyaerocom.plugins.icpforests.metadata import MetadataReader as ReadICPForestMeta
from pyaerocom.plugins.icpforests.reader import ReadICPForest
from pyaerocom.io.icpforests.metadata import MetadataReader as ReadICPForestMeta
from pyaerocom.io.icpforests.reader import ReadICPForest
from tests.fixtures.data_access import TEST_DATA, DataForTests

# station names are not consistent between variables!
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest

from pyaerocom import const
from pyaerocom.plugins.mep.reader import ReadMEP
from pyaerocom.io.mep.reader import ReadMEP

STATION_NAMES = ("1478A", "2706A", "3377A")
VARS_DEFAULT = {"concco", "concno2", "conco3", "concpm10", "concpm25", "concso2"}
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyaerocom.plugins.mscw_ctm.additional_variables import (
from pyaerocom.io.mscw_ctm.additional_variables import (
calc_concNhno3,
calc_concNnh3,
calc_concNnh4,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyaerocom.plugins.mscw_ctm.model_variables import emep_variables
from pyaerocom.io.mscw_ctm.model_variables import emep_variables


def test_emep_variables():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pyaerocom.exceptions as exc
from pyaerocom import get_variable
from pyaerocom.griddeddata import GriddedData
from pyaerocom.plugins.mscw_ctm.reader import ReadEMEP, ReadMscwCtm
from pyaerocom.io.mscw_ctm.reader import ReadEMEP, ReadMscwCtm
from tests.conftest import TEST_RTOL
from tests.fixtures.mscw_ctm import create_fake_MSCWCtm_data

Expand Down
Empty file removed tests/plugins/mep/__init__.py
Empty file.
Empty file removed tests/plugins/mscw_ctm/__init__.py
Empty file.
13 changes: 0 additions & 13 deletions tests/plugins/test_entry_points.py

This file was deleted.

2 changes: 1 addition & 1 deletion tests/test_colocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from pyaerocom.config import ALL_REGION_NAME
from pyaerocom.exceptions import UnresolvableTimeDefinitionError
from pyaerocom.plugins.mscw_ctm.reader import ReadMscwCtm
from pyaerocom.io.mscw_ctm.reader import ReadMscwCtm
from tests.conftest import TEST_RTOL, need_iris_32
from tests.fixtures.stations import create_fake_station_data

Expand Down
2 changes: 1 addition & 1 deletion tests/test_colocation_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from pyaerocom.config import ALL_REGION_NAME
from pyaerocom.exceptions import ColocationError, ColocationSetupError
from pyaerocom.io.aux_read_cubes import add_cubes
from pyaerocom.plugins.mscw_ctm.reader import ReadMscwCtm
from pyaerocom.io.mscw_ctm.reader import ReadMscwCtm
from tests.fixtures.data_access import TEST_DATA

COL_OUT_DEFAULT = Path(const.OUTPUTDIR) / "colocated_data"
Expand Down

0 comments on commit 783dae1

Please sign in to comment.