Skip to content

Replace use of deprecated pkg_resources (#1881) #1882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions benchmarks/benchmarks/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pandas as pd
import pvlib
from pkg_resources import parse_version
from packaging.version import Version


def set_solar_position(obj):
Expand Down Expand Up @@ -37,7 +37,7 @@ def time_location_get_clearsky(self):
class Location_0_6_1:

def setup(self):
if parse_version(pvlib.__version__) < parse_version('0.6.1'):
if Version(pvlib.__version__) < Version('0.6.1'):
raise NotImplementedError

set_solar_position(self)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/benchmarks/solarposition.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import pvlib
from pvlib import solarposition

from pkg_resources import parse_version
from packaging.version import Version


if parse_version(pvlib.__version__) >= parse_version('0.6.1'):
if Version(pvlib.__version__) >= Version('0.6.1'):
sun_rise_set_transit_spa = solarposition.sun_rise_set_transit_spa
else:
sun_rise_set_transit_spa = solarposition.get_sun_rise_set_transit
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/benchmarks/solarposition_numba.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Try to keep relevant sections in sync with benchmarks/solarposition.py
"""

from pkg_resources import parse_version
from packaging.version import Version
import pandas as pd

import os
Expand All @@ -18,7 +18,7 @@
from pvlib import solarposition # NOQA: E402


if parse_version(pvlib.__version__) >= parse_version('0.6.1'):
if Version(pvlib.__version__) >= Version('0.6.1'):
sun_rise_set_transit_spa = solarposition.sun_rise_set_transit_spa
else:
sun_rise_set_transit_spa = solarposition.get_sun_rise_set_transit
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/benchmarks/temperature.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import pandas as pd
import pvlib
from pkg_resources import parse_version
from packaging.version import Version
from functools import partial


Expand All @@ -20,7 +20,7 @@ class SAPM:

def setup(self):
set_weather_data(self)
if parse_version(pvlib.__version__) >= parse_version('0.7.0'):
if Version(pvlib.__version__) >= Version('0.7.0'):
kwargs = pvlib.temperature.TEMPERATURE_MODEL_PARAMETERS['sapm']
kwargs = kwargs['open_rack_glass_glass']
self.sapm_cell_wrapper = partial(pvlib.temperature.sapm_cell,
Expand All @@ -41,7 +41,7 @@ def time_sapm_cell(self):
class Fuentes:

def setup(self):
if parse_version(pvlib.__version__) < parse_version('0.8.0'):
if Version(pvlib.__version__) < Version('0.8.0'):
raise NotImplementedError

set_weather_data(self)
Expand Down
2 changes: 2 additions & 0 deletions docs/sphinx/source/whatsnew/v0.10.3.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Bug fixes

Testing
~~~~~~~
* Replace use of deprecated ``pkg_resources``. (:issue:`1881`, :pull:`1882`)


Documentation
Expand All @@ -24,3 +25,4 @@ Documentation
Contributors
~~~~~~~~~~~~
* Arjan Keeman (:ghuser:`akeeman`)
* Miguel Sánchez de León Peque (:ghuser:`Peque`)
9 changes: 4 additions & 5 deletions pvlib/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@

import pandas as pd
import os
from pkg_resources import parse_version
from packaging.version import Version
import pytest
from functools import wraps

import pvlib
from pvlib.location import Location

pvlib_base_version = \
parse_version(parse_version(pvlib.__version__).base_version)
pvlib_base_version = Version(Version(pvlib.__version__).base_version)


# decorator takes one argument: the base version for which it should fail
Expand All @@ -27,7 +26,7 @@ def wrapper(func):
@wraps(func)
def inner(*args, **kwargs):
# fail if the version is too high
if pvlib_base_version >= parse_version(version):
if pvlib_base_version >= Version(version):
pytest.fail('the tested function is scheduled to be '
'removed in %s' % version)
# otherwise return the function to be executed
Expand All @@ -40,7 +39,7 @@ def inner(*args, **kwargs):
def _check_pandas_assert_kwargs(kwargs):
# handles the change in API related to default
# tolerances in pandas 1.1.0. See pvlib GH #1018
if parse_version(pd.__version__) >= parse_version('1.1.0'):
if Version(pd.__version__) >= Version('1.1.0'):
if kwargs.pop('check_less_precise', False):
kwargs['atol'] = 1e-3
kwargs['rtol'] = 1e-3
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@

TESTS_REQUIRE = ['pytest', 'pytest-cov', 'pytest-mock',
'requests-mock', 'pytest-timeout', 'pytest-rerunfailures',
'pytest-remotedata']
'pytest-remotedata', 'packaging']
EXTRAS_REQUIRE = {
'optional': ['cython', 'ephem', 'nrel-pysam', 'numba',
'solarfactors', 'statsmodels'],
Expand Down