diff --git a/CHANGELOG.md b/CHANGELOG.md
index 35d4da6..10dc706 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,12 @@ The format is (loosely) based on [Keep a Changelog](http://keepachangelog.com/)
## Unreleased
+### Changed
+
+- No longer use the deprecated pkg-resources package.
+ It has been replaced with importlib from the Python standard library
+ ([#112](https://github.com/stac-utils/stac-check/pull/112))
+
## [v1.4.0] - 2024-10-09
### Added
diff --git a/docs/api.rst b/docs/api.rst
index 40a7680..9d8d42e 100644
--- a/docs/api.rst
+++ b/docs/api.rst
@@ -30,7 +30,7 @@ API Reference
import pkg_resources
+
from stac_validator.validate import StacValidate
from stac_validator.utilities import is_valid_url
import json
@@ -40,7 +40,8 @@ API Reference
import requests
from typing import Optional, Union, Dict, Any, List
from dotenv import load_dotenv
- import pkg_resources
+ import importlib.metadata
+ import importlib.resources
load_dotenv()
@@ -162,7 +163,7 @@ API Reference
self.config = self.parse_config(self.config_file)
self.asset_type = self.message["asset_type"] if "asset_type" in self.message else ""
self.version = self.message["version"] if "version" in self.message else ""
- self.validator_version = pkg_resources.require("stac-validator")[0].version
+ self.validator_version = importlib.metadata.distribution("stac-validator").version
self.validate_all = self.recursive_validation(self.item)
self.valid_stac = self.message["valid_stac"]
self.error_type = self.check_error_type()
@@ -205,7 +206,7 @@ API Reference
with open(default_config_file) as f:
default_config = yaml.load(f, Loader=yaml.FullLoader)
else:
- with pkg_resources.resource_stream(__name__, "stac-check.config.yml") as f:
+ with importlib.resources.open_text(__name__, "stac-check.config.yml") as f:
default_config = yaml.load(f, Loader=yaml.FullLoader)
if config_file:
with open(config_file) as f:
@@ -866,7 +867,7 @@ API Reference
self.config = self.parse_config(self.config_file)
self.asset_type = self.message["asset_type"] if "asset_type" in self.message else ""
self.version = self.message["version"] if "version" in self.message else ""
- self.validator_version = pkg_resources.require("stac-validator")[0].version
+ self.validator_version = importlib.metadata.distribution("stac-validator").version
self.validate_all = self.recursive_validation(self.item)
self.valid_stac = self.message["valid_stac"]
self.error_type = self.check_error_type()
@@ -909,7 +910,7 @@ API Reference
with open(default_config_file) as f:
default_config = yaml.load(f, Loader=yaml.FullLoader)
else:
- with pkg_resources.resource_stream(__name__, "stac-check.config.yml") as f:
+ with importlib.resources.open_text(__name__, "stac-check.config.yml") as f:
default_config = yaml.load(f, Loader=yaml.FullLoader)
if config_file:
with open(config_file) as f:
@@ -1416,7 +1417,7 @@ API Reference
with open(default_config_file) as f:
default_config = yaml.load(f, Loader=yaml.FullLoader)
else:
- with pkg_resources.resource_stream(__name__, "stac-check.config.yml") as f:
+ with importlib.resources.open_text(__name__, "stac-check.config.yml") as f:
default_config = yaml.load(f, Loader=yaml.FullLoader)
if config_file:
with open(config_file) as f:
diff --git a/docs/cli.rst b/docs/cli.rst
index 1e335c4..e17c909 100644
--- a/docs/cli.rst
+++ b/docs/cli.rst
@@ -32,7 +32,7 @@ CLI Reference
import click
from .lint import Linter
- import pkg_resources
+ import importlib.matadata
def link_asset_message(link_list:list, type: str, format: str) -> None:
"""Prints a list of links or assets and any errors associated with them.
@@ -205,7 +205,7 @@ CLI Reference
)
@click.command()
@click.argument('file')
- @click.version_option(version=pkg_resources.require("stac-check")[0].version)
+ @click.version_option(version=importlib.metadata.distribution("stac-check").version)
def main(file, recursive, max_depth, assets, links):
linter = Linter(file, assets=assets, links=links, recursive=recursive, max_depth=max_depth)
intro_message(linter)
diff --git a/setup.py b/setup.py
index a830685..c531b39 100644
--- a/setup.py
+++ b/setup.py
@@ -15,6 +15,7 @@
url="https://github.com/stac-utils/stac-check",
packages=find_packages(exclude=("tests",)),
include_package_data=True,
+ setup_requires=["setuptools"],
install_requires=[
"click>=8.0.0",
"requests>=2.19.1",
@@ -22,7 +23,6 @@
"stac-validator>=3.4.0",
"PyYAML",
"python-dotenv",
- "setuptools",
],
extras_require={
"dev": [
diff --git a/stac_check/cli.py b/stac_check/cli.py
index 491ceee..ffb8577 100644
--- a/stac_check/cli.py
+++ b/stac_check/cli.py
@@ -1,5 +1,6 @@
+import importlib.metadata
+
import click
-import pkg_resources
from .lint import Linter
from .logo import logo
@@ -38,7 +39,9 @@ def recursive_message(linter: Linter) -> None:
click.secho(f"Max-depth = {linter.max_depth}")
click.secho("-------------------------")
for count, msg in enumerate(linter.validate_all):
- click.secho(f"Asset {count+1} Validated: {msg['path']}", bg="white", fg="black")
+ click.secho(
+ f"Asset {count + 1} Validated: {msg['path']}", bg="white", fg="black"
+ )
click.secho()
if msg["valid_stac"] == True:
recursive_linter = Linter(msg["path"], recursive=True)
@@ -177,7 +180,7 @@ def cli_message(linter: Linter) -> None:
)
@click.command()
@click.argument("file")
-@click.version_option(version=pkg_resources.require("stac-check")[0].version)
+@click.version_option(version=importlib.metadata.distribution("stac-check").version)
def main(file, recursive, max_depth, assets, links):
linter = Linter(
file, assets=assets, links=links, recursive=recursive, max_depth=max_depth
diff --git a/stac_check/lint.py b/stac_check/lint.py
index 0db65b0..61e9731 100644
--- a/stac_check/lint.py
+++ b/stac_check/lint.py
@@ -1,9 +1,10 @@
+import importlib.metadata
+import importlib.resources
import json
import os
from dataclasses import dataclass
from typing import Any, Dict, List, Optional, Union
-import pkg_resources
import requests
import yaml
from dotenv import load_dotenv
@@ -134,7 +135,9 @@ def __post_init__(self):
self.message["asset_type"] if "asset_type" in self.message else ""
)
self.version = self.message["version"] if "version" in self.message else ""
- self.validator_version = pkg_resources.require("stac-validator")[0].version
+ self.validator_version = importlib.metadata.distribution(
+ "stac-validator"
+ ).version
self.validate_all = self.recursive_validation(self.item)
self.valid_stac = self.message["valid_stac"]
self.error_type = self.check_error_type()
@@ -185,7 +188,9 @@ def parse_config(config_file: Optional[str] = None) -> Dict:
with open(default_config_file) as f:
default_config = yaml.load(f, Loader=yaml.FullLoader)
else:
- with pkg_resources.resource_stream(__name__, "stac-check.config.yml") as f:
+ with importlib.resources.open_text(
+ "stac_check", "stac-check.config.yml"
+ ) as f:
default_config = yaml.load(f, Loader=yaml.FullLoader)
if config_file:
with open(config_file) as f: