From d146001fcd287b5d0b17f820b4caabcdec1b976d Mon Sep 17 00:00:00 2001 From: Noritada Kobayashi Date: Tue, 9 Jan 2024 20:10:31 +0900 Subject: [PATCH] Switch dynamic version handling from pkg_resources (in setuptools) to packaging This fixes following `ModuleNotFoundError` resulting from missing dependency on setuptools: % rye add pygrib --path /path/to/repo % rye sync % rye run python -c 'import pygrib' ModuleNotFoundError: No module named 'pkg_resources' In the executable code of pygrib, setuptools is only used for version comparison purposes, and since setuptools is larger than necessary, this commit replaces it with packaging, which is a more compact module containing reusable core utilities for Python packaging compliant with recent PEPs. --- Changelog | 4 ++++ pyproject.toml | 1 + src/pygrib/_pygrib.pyx | 4 ++-- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Changelog b/Changelog index 12eaaf7d..4a5fc040 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,7 @@ +since version 2.1.5 release +=========================== +* switch dynamic version handling from pkg_resources (in setuptools) to packaging + version 2.1.5 release ===================== * remove python 3.6 support, add python 3.11,3.12 diff --git a/pyproject.toml b/pyproject.toml index 5618a2d5..af194b67 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,7 @@ classifiers = [ "Topic :: Software Development :: Libraries :: Python Modules", ] dependencies = [ + "packaging", "pyproj", "numpy", ] diff --git a/src/pygrib/_pygrib.pyx b/src/pygrib/_pygrib.pyx index 949f29d4..f5896676 100644 --- a/src/pygrib/_pygrib.pyx +++ b/src/pygrib/_pygrib.pyx @@ -9,7 +9,7 @@ import os from datetime import datetime from io import BufferedReader from os import PathLike -from pkg_resources import parse_version +from packaging import version from numpy import ma import pyproj npc.import_array() @@ -1391,7 +1391,7 @@ cdef class gribmessage(object): else: scalea = 1. scaleb = 1. - if parse_version(grib_api_version) < parse_version('1.9.0'): + if version.parse(grib_api_version) < version.parse('1.9.0'): projparams['a']=self['scaledValueOfMajorAxisOfOblateSpheroidEarth']*scalea projparams['b']=self['scaledValueOfMinorAxisOfOblateSpheroidEarth']*scaleb else: