Skip to content
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

remove requirement for setuptools.pkg_resources #5845

Merged
merged 30 commits into from
Nov 1, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
a73a78a
remove requirement for setuptools.pkg_resources
marscher Oct 7, 2021
9d14a01
doh
marscher Oct 7, 2021
6104a05
doh2
marscher Oct 7, 2021
d500090
doh3, no reraise for fallback version number
marscher Oct 7, 2021
7537b33
black formatting
marscher Oct 7, 2021
4dcc371
ordering
marscher Oct 7, 2021
2fc6537
all this lifetime wasted by fucking linting tools
marscher Oct 7, 2021
b482d68
precommit
marscher Oct 7, 2021
b2f1ad2
unconditionally depend on importlib-metadata [ci skip]
marscher Oct 27, 2021
25cb017
follow up
marscher Oct 27, 2021
9666401
import import_libmeta (unconditionally); rename pkg_entrypoints
marscher Oct 27, 2021
becf45e
Revert "unconditionally depend on importlib-metadata [ci skip]"
marscher Oct 27, 2021
a21485b
first try importlib.metadata (stdlib), then fallback to importlib_met…
marscher Oct 27, 2021
2310041
linting
marscher Oct 27, 2021
7ab694f
minor [ci skip]
marscher Oct 27, 2021
60b4237
broad exception clause?
marscher Oct 28, 2021
6a377ac
use importlib.resources read_binary to read html formatting files
marscher Oct 28, 2021
a9e695f
update changelog [ci skip]
marscher Oct 28, 2021
0ea3d65
Merge branch 'main' into remove_pkgresources
marscher Oct 28, 2021
e69e073
Update doc/whats-new.rst
marscher Oct 28, 2021
efc0bdb
Update doc/whats-new.rst
keewis Oct 28, 2021
5883ff8
remove setuptools from the minimum dependencies
keewis Oct 28, 2021
833b1cd
remove setuptools from the min deps CI and the installing docs
keewis Oct 28, 2021
d602190
ignore setuptools
keewis Oct 28, 2021
aeeb89f
decode the loaded resources
keewis Oct 28, 2021
5348287
add importlib_metadata to the list of dependencies
keewis Oct 28, 2021
4d2cc88
__init__: no no-redef
marscher Oct 29, 2021
dbd8108
Merge branch 'main' into remove_pkgresources
dcherian Oct 29, 2021
5ca4a94
Revert "__init__: no no-redef"
dcherian Oct 29, 2021
28c8485
[skip-ci] Update doc/getting-started-guide/installing.rst
dcherian Oct 29, 2021
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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ python_requires = >=3.7
install_requires =
numpy >= 1.17
pandas >= 1.0
setuptools >= 40.4 # For pkg_resources
importlib-metadata
marscher marked this conversation as resolved.
Show resolved Hide resolved

[options.extras_require]
io =
Expand Down
19 changes: 16 additions & 3 deletions xarray/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import pkg_resources

from . import testing, tutorial, ufuncs
from .backends.api import (
load_dataarray,
Expand Down Expand Up @@ -30,7 +28,22 @@
from .util.print_versions import show_versions

try:
__version__ = pkg_resources.get_distribution("xarray").version
try:
from importlib.metadata import PackageNotFoundError, version
except ImportError:
try:
from importlib_metadata import ( # type: ignore[no-redef]
PackageNotFoundError,
version,
)
except ImportError:
raise
marscher marked this conversation as resolved.
Show resolved Hide resolved

try:
__version__ = version("xarray")
except PackageNotFoundError:
raise
del version, PackageNotFoundError
except Exception:
# Local copy or not installed with setuptools.
# Disable minimum version checks on downstream libraries.
Expand Down
14 changes: 10 additions & 4 deletions xarray/backends/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import itertools
import warnings

import pkg_resources

from .common import BACKEND_ENTRYPOINTS, BackendEntrypoint

STANDARD_BACKENDS_ORDER = ["netcdf4", "h5netcdf", "scipy"]
Expand Down Expand Up @@ -95,8 +93,16 @@ def build_engines(pkg_entrypoints):

@functools.lru_cache(maxsize=1)
def list_engines():
pkg_entrypoints = pkg_resources.iter_entry_points("xarray.backends")
return build_engines(pkg_entrypoints)
try:
from importlib.metadata import Distribution
except ImportError:
from importlib_metadata import Distribution
marscher marked this conversation as resolved.
Show resolved Hide resolved
importlib_entrypoints = (
entry_point
for entry_point in Distribution.from_name("xarray").entry_points
if entry_point.module == "xarray.backends"
)
return build_engines(importlib_entrypoints)
marscher marked this conversation as resolved.
Show resolved Hide resolved


def guess_engine(store_spec):
Expand Down
15 changes: 9 additions & 6 deletions xarray/core/formatting_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from functools import lru_cache, partial
from html import escape

import pkg_resources

from .formatting import inline_variable_array_repr, short_data_repr
from .options import _get_boolean_with_default

Expand All @@ -14,10 +12,15 @@
@lru_cache(None)
def _load_static_files():
"""Lazily load the resource files into memory the first time they are needed"""
return [
pkg_resources.resource_string("xarray", fname).decode("utf8")
for fname in STATIC_FILES
]
import pathlib

parent = pathlib.Path(__file__).parent / "../"
result = []
for fname in STATIC_FILES:
with open(parent / fname) as fh:
keewis marked this conversation as resolved.
Show resolved Hide resolved
result.append(fh.read().encode("utf8"))

return result


def short_data_repr_html(array):
Expand Down