Skip to content

Commit

Permalink
Merge pull request #112 from avalentino/feature/no-pkg-resources
Browse files Browse the repository at this point in the history
Do not use the deprecated pkg-resources package
  • Loading branch information
jonhealy1 authored Nov 15, 2024
2 parents 9565314 + cbddc80 commit f30d0fd
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 16 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ API Reference
<summary>
<span>Expand source code</span>
</summary>
<pre><code class="python">import pkg_resources
<pre><code class="python">
from stac_validator.validate import StacValidate
from stac_validator.utilities import is_valid_url
import json
Expand All @@ -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()

Expand Down Expand Up @@ -162,7 +163,7 @@ API Reference
self.config = self.parse_config(self.config_file)
self.asset_type = self.message[&#34;asset_type&#34;] if &#34;asset_type&#34; in self.message else &#34;&#34;
self.version = self.message[&#34;version&#34;] if &#34;version&#34; in self.message else &#34;&#34;
self.validator_version = pkg_resources.require(&#34;stac-validator&#34;)[0].version
self.validator_version = importlib.metadata.distribution(&#34;stac-validator&#34;).version
self.validate_all = self.recursive_validation(self.item)
self.valid_stac = self.message[&#34;valid_stac&#34;]
self.error_type = self.check_error_type()
Expand Down Expand Up @@ -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__, &#34;stac-check.config.yml&#34;) as f:
with importlib.resources.open_text(__name__, &#34;stac-check.config.yml&#34;) as f:
default_config = yaml.load(f, Loader=yaml.FullLoader)
if config_file:
with open(config_file) as f:
Expand Down Expand Up @@ -866,7 +867,7 @@ API Reference
self.config = self.parse_config(self.config_file)
self.asset_type = self.message[&#34;asset_type&#34;] if &#34;asset_type&#34; in self.message else &#34;&#34;
self.version = self.message[&#34;version&#34;] if &#34;version&#34; in self.message else &#34;&#34;
self.validator_version = pkg_resources.require(&#34;stac-validator&#34;)[0].version
self.validator_version = importlib.metadata.distribution(&#34;stac-validator&#34;).version
self.validate_all = self.recursive_validation(self.item)
self.valid_stac = self.message[&#34;valid_stac&#34;]
self.error_type = self.check_error_type()
Expand Down Expand Up @@ -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__, &#34;stac-check.config.yml&#34;) as f:
with importlib.resources.open_text(__name__, &#34;stac-check.config.yml&#34;) as f:
default_config = yaml.load(f, Loader=yaml.FullLoader)
if config_file:
with open(config_file) as f:
Expand Down Expand Up @@ -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__, &#34;stac-check.config.yml&#34;) as f:
with importlib.resources.open_text(__name__, &#34;stac-check.config.yml&#34;) as f:
default_config = yaml.load(f, Loader=yaml.FullLoader)
if config_file:
with open(config_file) as f:
Expand Down
4 changes: 2 additions & 2 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ CLI Reference
</summary>
<pre><code class="python">import click
from .lint import Linter
import pkg_resources
import importlib.matadata

def link_asset_message(link_list:list, type: str, format: str) -&gt; None:
&#34;&#34;&#34;Prints a list of links or assets and any errors associated with them.
Expand Down Expand Up @@ -205,7 +205,7 @@ CLI Reference
)
@click.command()
@click.argument(&#39;file&#39;)
@click.version_option(version=pkg_resources.require(&#34;stac-check&#34;)[0].version)
@click.version_option(version=importlib.metadata.distribution(&#34;stac-check&#34;).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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
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",
"jsonschema>=3.1.2",
"stac-validator>=3.4.0",
"PyYAML",
"python-dotenv",
"setuptools",
],
extras_require={
"dev": [
Expand Down
9 changes: 6 additions & 3 deletions stac_check/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import importlib.metadata

import click
import pkg_resources

from .lint import Linter
from .logo import logo
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions stac_check/lint.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit f30d0fd

Please sign in to comment.